首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >错误错误:未使用‘@ts-TS2578-TS2578’指令

错误错误:未使用‘@ts-TS2578-TS2578’指令
EN

Stack Overflow用户
提问于 2021-01-11 23:25:20
回答 2查看 4.2K关注 0票数 1

上周,我使用ts-migrate将我们的代码库迁移到TypeScript。该工具在TS文件中添加了大量的// @ts-expect-error注释,以使其通过TS编译器和类型检查。然而,当我运行yarn run tsc来检查我的代码库时,我得到了5k+错误,声明error TS2578: Unused '@ts-expect-error' directive.,我是否遗漏了一段配置,声明这些类型的错误是正常的?寻找任何建议,让这通过TS编译器。

这是我的TS配置以供参考。

代码语言:javascript
运行
复制
{
    "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
    }
}

完整的错误消息示例:

代码语言:javascript
运行
复制
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'.
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EN

回答 2

Stack Overflow用户

发布于 2021-04-27 16:07:37

我也有同样的问题,但我的错误也出现在那些非测试文件中。我认为这是因为ts-migrate和你的集成开发环境的打字版本不匹配。我在package.json中添加了一个typescript包,以使两个版本相同,从而修复了它

票数 0
EN

Stack Overflow用户

发布于 2021-01-11 23:48:02

答案很简单。您在没有错误的地方使用了// @ts-expect-error。我建议在VS代码中通过正则表达式\s*\/\/\s*@ts-expect-error (to nothing)替换它,以删除所有注释。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65669672

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档