上周,我使用ts-migrate
将我们的代码库迁移到TypeScript。该工具在TS文件中添加了大量的// @ts-expect-error
注释,以使其通过TS编译器和类型检查。然而,当我运行yarn run tsc
来检查我的代码库时,我得到了5k+错误,声明error TS2578: Unused '@ts-expect-error' directive.
,我是否遗漏了一段配置,声明这些类型的错误是正常的?寻找任何建议,让这通过TS编译器。
这是我的TS配置以供参考。
{
"compilerOptions": {
"target": "ES2016",
"module": "commonjs",
"lib": ["esnext", "dom"],
"allowJs": true,
"checkJs": false,
"jsx": "react",
"declaration": false,
"declarationMap": false,
"sourceMap": false,
"skipDefaultLibCheck": true,
"skipLibCheck": true,
"noEmit": true,
"isolatedModules": true,
"strict": false,
"noImplicitAny": false,
"strictNullChecks": false,
"strictFunctionTypes": false,
"strictBindCallApply": false,
"strictPropertyInitialization": false,
"noImplicitThis": false,
"alwaysStrict": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": false,
"noFallthroughCasesInSwitch": false,
"baseUrl": "./",
"typeRoots": [
"./types/",
"./node_modules/@types"
],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true
}
}
完整的错误消息示例:
src/WorkspacePicker/__tests__/index.test.tsx:27:1 - error TS2578: Unused '@ts-expect-error' directive.
27 // @ts-expect-error ts-migrate(2582) FIXME: Cannot find name 'describe'. Do you need to instal... Remove this comment to see the full error message
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/WorkspacePicker/__tests__/index.test.tsx:29:3 - error TS2578: Unused '@ts-expect-error' directive.
29 // @ts-expect-error ts-migrate(2582) FIXME: Cannot find name 'test'. Do you need to install ty... Remove this comment to see the full error message
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/WorkspacePicker/__tests__/index.test.tsx:38:5 - error TS2578: Unused '@ts-expect-error' directive.
38 // @ts-expect-error ts-migrate(2304) FIXME: Cannot find name 'expect'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
发布于 2021-04-27 16:07:37
我也有同样的问题,但我的错误也出现在那些非测试文件中。我认为这是因为ts-migrate
和你的集成开发环境的打字版本不匹配。我在package.json
中添加了一个typescript包,以使两个版本相同,从而修复了它
发布于 2021-01-11 23:48:02
答案很简单。您在没有错误的地方使用了// @ts-expect-error
。我建议在VS代码中通过正则表达式\s*\/\/\s*@ts-expect-error
(to nothing)替换它,以删除所有注释。
https://stackoverflow.com/questions/65669672
复制相似问题