[英]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.