// @ts-check
const obj = {
str: `a string`,
};
console.log(obj.nonexistant); // no error (it should be erroring)
let num = 0; // type number
num = obj.str; // has error (good)
为什么第一个问题在 VS Code 中没有显示红色下划线错误/问题?
最佳答案
打字没问题。我很确定这是一个配置问题。尝试添加 jsconfig.json与 "strict": true,
或"noImplicitAny": true,
在其 compilerOptions
字段中,或 tsconfig.json同样,还有 "allowJs": true,
和 "checkJs": true,
.
关于javascript - JavaScript 文件中的 VS Code @ts-check 不检查所有内容 - 不存在的属性不会出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76148660/