我在HunterLarco/Twitter-V2中添加了类型脚本定义,它具有以下结构:
package.json
src/
twitter.js
twitter.d.ts
Credentials.js
Credentials.d.ts
我想测试.js
文件是否与.d.ts
声明文件匹配。
现在我正在使用这个tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"alwaysStrict": true,
"baseUrl": ".",
"forceConsistentCasingInFileNames": true,
"lib": ["es2018"],
"module": "commonjs",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"paths": { "twitter-v2": ["src"] },
"typeRoots": [
"./node_modules/@types",
"./src"
],
"outDir": "dist",
"strict": true,
"target": "es2018"
},
"include": [
"src/**/*",
"tests/**/*"
]
}
但是,当我故意向twitter.d.ts
添加不正确的类型信息并运行tsc--project tsconfig.json
时,它不会报告任何错误并写入dist/
。
我需要启用编译器选项来检查js文件(默认情况下typescript不做,即使使用js也是允许的)
https://www.typescriptlang.org/tsconfig#checkjs
{
"extends": "@tsconfig/node10/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"alwaysStrict": true,
"checkJs": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src/**/*", "tests/**/*"]
}