问题描述
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合作。 据报道在打字稿Github页面上Import path not checked when not importing any symbols #20534,并标记为“按预期工作”。
github上的示例与您发布的示例有所不同,但是行为的根本原因似乎是相同的。