[英]VSCode isn't showing inline typescript errors
我刚刚安装了 Deno 1.9.2 并在我的 PC 上打开了一个空白文件夹。 我正在关注有关 TypeScript 基础知识的教程。 这就是我的问题所在。
const someFunc = (n: number) => {
if (n % 2 === 0) {
return "even"
}
}
const value = someFunc(4)
value.substring(1)
在某一时刻,VSCode 给老师一个关于值的内联警告,说Object is possibly 'undefined'.
我环顾四周,并被告知将我的 VSCode typescript.validate.enable更改为 true。 我已经这样做了,并且多次重新启动了 VSCode。 当我使用deno run index.ts
运行我的代码时,我得到了我的错误。 有任何想法吗?
此错误与 VSCode 或 Deno 无关。 在您提供的代码中 function someFunc
的返回类型为string | undefined
string | undefined
。 我的猜测是您的tsconfig.json
具有strictFunctionTypes: true
。
您可以通过以下方式修复此错误:
正确处理所有案件 -
const someFunc = (n: number) => {
if (n % 2 === 0) {
return 'even';
}
return ''
};
或者在tsconfig.json
strictFunctionTypes
{
"compilerOptions": {
"strictFunctionTypes": false,
"plugins": [
{
"name": "typescript-deno-plugin",
"enable": true, // default is `true`
"importmap": "import_map.json"
}
]
}
}
虽然我不确定 Deno 是否可以在没有strictFunctionTypes
的情况下工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.