简体   繁体   English

忽略 TS6133:“(导入)已声明但从未使用过”?

[英]Ignore TS6133: "(import) is declared but never used"?

While working on a TypeScript project, I commented out a line, and got the error:在做一个 TypeScript 的项目时,我注释掉一行,得到了错误:

Failed to compile编译失败

./src/App.tsx (4,8): error TS6133: 'axios' is declared but never used.

This error occurred during the build time and cannot be dismissed.此错误发生在构建期间,无法消除。

The error is right, I am importing axios, but I wanted to temporarily comment out the call to axios.get .报错没错,我导入的是axios,但是想暂时注释掉对axios.get的调用。 I appreciate that error as it keeps my imports clean, but during early development is is pretty disruptive.我很欣赏这个错误,因为它使我的导入保持清洁,但在早期开发过程中非常具有破坏性。

Any way to disable or ignore that warning?有什么方法可以禁用或忽略该警告?

You probably have the noUnusedLocals compiler option turned on in your tsconfig.json . 你可能有noUnusedLocals编译器选项在您开启tsconfig.json Just turn it off during development. 在开发过程中关闭它。

In tsconfig.json在 tsconfig.json

{
  "compilerOptions": {
    ...
    "noUnusedLocals": false,   // just set this attribute false
  }
}

It will be done.将会完成。

For more tips:更多提示:

In xxx.ts file在 xxx.ts 文件中

//@ts-nocheck 
when on the top of the file,it will not check the below.

//@ts-ignore
when use it,it will not check the next line

I had the same problem in my React App.我在我的 React 应用程序中遇到了同样的问题。 Apart from changing the "noUsedLocals": false property in the tsconfig.json , you also need to adjust the "noUnusedParameters": false .除了更改 tsconfig.json 中的 " tsconfig.json "noUsedLocals": false属性外,您还需要调整"noUnusedParameters": false The former is only applicable to local variables, if you are passing unused parameters through functions, the latter will need to be changed to false as well.前者只适用于局部变量,如果你通过函数传递未使用的参数,后者也需要更改为 false。

In summary, you'll have to do the following:总之,您必须执行以下操作:

{
  "compilerOptions": {
     "noUnusedLocals": false,
     "noUnusedParameters": false,
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 TS6133(已声明但从未读取)显示为警告而不是错误 - Show TS6133 (declared but never read) as warning instead of error src/index.ts:1:1 - 错误 TS6133: 'functions' 已声明但其值从未被读取 - src/index.ts:1:1 - error TS6133: 'functions' is declared but its value is never read 钩子(批量更新周期) - 语义错误 TS6133: '' 已声明,但其值从未被读取 - Hooks (Batched update cycle) - semantic error TS6133: '' is declared but its value is never read TypeScript错误:声明了foo,但永远不会读取它的值。 TS6133 - TypeScript error: foo is declared but its value is never read. TS6133 DataSnapshot' 已声明,但其值从未被读取。ts(6133) - DataSnapshot' is declared but its value is never read.ts(6133) 如何使用 TypeGraphQL 和 TypeScript 抑制 TS6133 错误? - How to suppress TS6133 error with TypeGraphQL and TypeScript? 使用匿名方法时如何避免TS6133错误? - how can I avoid TS6133 errors when using anonymous methods? 将1参数函数绑定到具有2参数函数的回调,避免错误TS6133 - bind a 1parameter function to a callback with 2 parameters function avoiding error TS6133 Typescript 错误 - “类型已声明但从未使用” in.ts。 在界面中使用时 - Typescript error - “type is declared but never used” in .ts. When it was used in interface 属性'平台'已声明但从未使用过 - Property 'platform' is declared but never used
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM