我有一个d.ts
文件,它导入了一个不存在的变量/接口:
import { inexistentVariable } from './myFile.ts'
import { InexistentInterface } from './myTypes.d.ts'
在这两种情况下,我的IDE(VSCode和WebStorm(都不会对此发出警告。我实际上可以在没有警告的情况下使用它:
interface A {
b: InexistentInterface
}
当我悬停在b
时,我得到了b: any
。
这是我的tsconfig:
{
"target": "ES5",
"module": "commonjs",
"lib": [
"esnext.asynciterable",
"ES5",
"ES6",
"dom"
],
"compilerOptions": {
"skipLibCheck": true,
"types": ["reflect-metadata", "jest", "jest-chain", "node"],
"outDir": "dist",
"strict": true,
"strictPropertyInitialization": false,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"downlevelIteration": true,
"baseUrl": ".",
},
"include": [
"./"
],
"exclude": [
"node_modules"
]
}
当导入的特征在代码库中不存在时,有什么方法可以得到错误吗?
我相信这是Typescript的预期行为,以确保与JavaScript的合作。在Typescript Github页面上有报道:在不导入任何符号#220534时未检查导入路径,并标记为";按预期工作";。
github上的例子与您发布的有点不同,但行为的根本原因似乎是一样的。