typescript - 定义类型为 null 或 undefined 的变量时类型不匹配
问题描述
在 VS2015(Typescript 版本 2.9.2 和 Typescript.MSBuild 3.0)中创建一个新的打字稿项目时,我无法定义一个带有 null 或 undefined 的变量,这是一个真正的痛苦,因为我不能使用可为空的类型。
function test() {
let x: null;
let y: undefined;
}
代码编译得很好,但是 Typescript Virtual Projects 文件夹中会出现类型预期的 IntelliSense 警告。
我的 tsconfig.json 配置如下:
{
"compilerOptions": {
"strictNullChecks": false,
"sourceMap": true, // Generates a corresponding sourcemap file
"target": "es5",
"outDir": "../Scripts/custom"
},
"compileOnSave": true, // use instead of watch, as supported on visual studio
"exclude": [
"node_modules",
"wwwroot",
"bin",
"obj"
]
}
解决方案
推荐阅读
- apache-camel - Camel-Cdi 没有使用 Registery 注入 CamelContext
- ios - UINavigationController 交互式弹出手势仅在第一次工作
- javascript - 动态读取下拉列表中的选定值
- angular - 构建角度应用程序后,在角度中加载失败的 inline.318b50c57b4eba3d437b.bundle.js
- python - 是否有任何选项可以从 python 中的数组元素创建多个 dict
- java - 部署程序集配置不适用于 mvn 包
- python-3.x - Pandas 数据框按列名上的函数合并
- python - 如果找到分隔符,则拆分字符串
- playframework - 播放 2.4 Global.java onStart 多次调用
- excel - 使用 Excel 并行填充多个 IE WebForms