在处理TypeScript项目时,我注释掉了一行,并得到了错误:
编译失败
Run Code Online (Sandbox Code Playgroud)./src/App.tsx (4,8): error TS6133: 'axios' is declared but never used.在构建期间发生此错误,无法解除.
错误是对的,我正在导入axios,但我想暂时注释掉这个调用axios.get.我很欣赏这个错误,因为它保持了我的进口清洁,但在早期开发过程中非常具有破坏性.
有什么方法可以禁用或忽略该警告?
Sar*_*ana 24
你可能已经noUnusedLocals打开了编译器选项tsconfig.json.在开发过程中关闭它.
xia*_*ia2 17
在 tsconfig.json 中
{
"compilerOptions": {
...
"noUnusedLocals": false, // just set this attribute false
}
}
Run Code Online (Sandbox Code Playgroud)
将会完成。
如需更多提示:
在 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
Run Code Online (Sandbox Code Playgroud)
小智 6
我在我的 React 应用程序中遇到了同样的问题。除了更改 "noUsedLocals": false中的属性外tsconfig.json,您还需要调整"noUnusedParameters": false. 前者仅适用于局部变量,如果通过函数传递未使用的参数,则后者也需要更改为 false。
总之,您必须执行以下操作:
{
"compilerOptions": {
"noUnusedLocals": false,
"noUnusedParameters": false,
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9554 次 |
| 最近记录: |