我正在TypeScript
项目中使用react-native
,它工作正常。
我唯一的问题是,IDE向我显示了错误和所有内容。但是即使有一些打字稿错误,我仍然可以运行我的项目。
例如,如果我遇到打字稿错误
type something = 'abc'
const fn(arg: something){ }
fn('somethingelse')
IDE将显示somethingelse
未分配给abc
。
但是当我重新加载应用程序/捆绑包时。它仍然可以编译。
我添加了一些打字稿配置文件
tsconfig.json
{
"compilerOptions": {
"baseUrl": "app",
"target": "es2018",
"lib": ["dom", "dom.iterable", "esnext"],
"jsx": "preserve",
"allowJs": true,
"allowSyntheticDefaultImports": true,
"allowUnreachableCode": false,
"declaration": false,
"downlevelIteration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": false,
"isolatedModules": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noLib": false,
"noUnusedParameters": true,
"noUnusedLocals": true,
"pretty": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"removeComments": true,
"sourceMap": true,
"strict": true,
"suppressImplicitAnyIndexErrors": true,
"module": "esnext",
"moduleResolution": "node",
"noEmit": true
},
"typeAcquisition": {
"include": ["jest"]
},
"include": ["app/**/*", "test-utils"]
}
当我也yarn tsc
时遇到此错误
TypeError: Cannot read property 'kind' of undefined
尽管tsc --w可以工作,但是我希望在运行时出现这些错误,以便在发生任何错误时都能对其进行修复。现在,我只在IDE上看到这些错误。但它仍然可以编译。