azt*_*ack 10 typescript type-narrowing
VS代码版本:
我正在 VS Code 中尝试一些“Type Narrowing”代码,但 VS Code 提供的信息类型与 TypeScript Playground 不同:
VS Code 给出:的返回类型Document.getElementById是HTMLElement:
而 TypeScript Playground 提供:
的返回类型Document.getElementById应该是HTMLElement | null:

el在空检查预计为类型之前HTMLElement | null:
el在空检查之后应该是类型HTMLElement缩小的类型:
我已经升级了全球打字稿包V4.0.2并设置typescript.tsdk到/Users/<username>/.nvm/versions/node/v12.16.3/lib/node_modules/typescript/lib用户settings.json
我已将严格的类型检查选项设置为:
/* Strict Type-Checking Options */
"strict": true,
// "noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
// "strictBindCallApply": true,
// "strictPropertyInitialization": true,
// "noImplicitThis": true,
"alwaysStrict": true,
Run Code Online (Sandbox Code Playgroud)
有没有我遗漏的配置tsconfig.json?
| 归档时间: |
|
| 查看次数: |
154 次 |
| 最近记录: |