简体   繁体   English

NextJS Typescript - 设置 tslint 配置以在有未使用的导入/声明时强制出错

[英]NextJS Typescript - Setup tslint configuration to force error when have unused import/declarations

can anyone tell me how to force error when I have an unused import/declaration written in next typescript?当我在下一个 typescript 中写入未使用的导入/声明时,谁能告诉我如何强制错误?

the use case is: example I have import { Accordion, AccordionButton } from '@chakra-ui/react';用例是:例如我import { Accordion, AccordionButton } from '@chakra-ui/react'; the Accordion component is used , but for AccordionButton is unused , I want when I save the file I got an error compile cause of AccordionButton is not used.使用了 Accordion 组件,但是对于 AccordionButton未使用我希望在保存文件时出现错误,因为 AccordionButton 没有使用。

Note: I already add: "noUnusedLocals": true, "noUnusedParameters": true注意:我已经添加: "noUnusedLocals": true, "noUnusedParameters": true

in tsconfig.json but still not resolved my problem在 tsconfig.json 但仍然没有解决我的问题

It can very much depend on the editor you use.它在很大程度上取决于您使用的编辑器。 In VScode I have it set up to grey out unused imports so you can easily notice and remove them.在 VScode 中,我将它设置为灰色未使用的导入,以便您可以轻松地注意到并删除它们。

In your VScode config:在您的 VScode 配置中:

{
  "javascript.validate.enable": true,
  "editor.showUnused": true
}

As far as getting an error, there is an eslint plugin which can show a linting error for unused imports here:至于出现错误,有一个 eslint 插件可以在这里显示未使用的导入的 linting 错误:

https://www.npmjs.com/package/eslint-plugin-unused-imports https://www.npmjs.com/package/eslint-plugin-unused-imports

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

相关问题 Typescript - 在 createReducer 上出现 tslint 错误 - Typescript - getting tslint error on createReducer 强制打字稿不删除未使用的引用 - Force typescript not to remove unused references 尝试使用 React + TypeScript 项目修复 tslint 错误 - Trying to fix tslint error with React + TypeScript project @typescript-eslint/no-unused-vars 类型声明中的误报 - @typescript-eslint/no-unused-vars false positive in type declarations 当我在 ts 代码中出现错误时,如何使用 tsconfig 文件强制 TypeScript 不编译为 JS? - How to force TypeScript to not compile to JS when I have an error in ts code, with tsconfig file? 在TypeScript中使用import / require来获取接口声明 - Use import/require in TypeScript to get interface declarations 在 TypeScript 中使用 NextJS 设置 Jest + React 测试库 — 设置 upp jest.config.js 时出错 - Setup Jest + React testing library using NextJS in TypeScript — error setting upp jest.config.js 后续变量声明必须有相同的类型错误 lodash require TypeScript - Subsequent variable declarations must have the same type error for lodash require TypeScript Angular新手:调试打字稿错误“'imageLoader'的所有声明必须具有相同的类型参数” - Angular Newbie: Debugging Typescript Error “All declarations of 'imageLoader' must have identical type parameters” NextJS服务器文件中的Typescript错误 - Typescript error in server file for NextJS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM