reactjs - Typescript 在枚举中报告未使用的变量
问题描述
在我的 React 项目中,我得到了以下代码:
export enum Tab {BASIC = 'BASIC', ADVANCED = 'ADVANCED', SETTINGS = 'SETTINGS'}
每个枚举案例都给我一个警告,它们已分配但从未使用过。
我已经看到了一些解决方案,但它们似乎不起作用。首先是我的 tsconfig 和 eslintrc。你可以看到我有parser: '@typescript-eslint/parser'
。同样在我的 package.json:"eslint-plugin-typescript": "^1.0.0-rc.3"
和 devDependencies 中:"@typescript-eslint/eslint-plugin": "^2.7.0", "@typescript-eslint/parser": "^2.7.0",
tsconfig
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"noImplicitAny": false,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
]
}
eslintrc.js
module.exports = {
env: {
browser: true,
es6: true,
},
extends: [
'react-app',
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2018,
sourceType: 'module',
},
plugins: [
'react',
'@typescript-eslint',
],
rules: {},
};
我也尝试在 eslintrc 中添加'@typescript-eslint'
,extends
但它说failed to load @typescript-eslint to extend from
我怎样才能解决这个问题?
解决方案
推荐阅读
- python - 将字典键值对存储到树结构中
- php - 计数行通知
- javascript - 为什么本地存储在页面刷新后不应该打开也不能工作?
- asp.net - 如何从 aspxgridview 复选框数据项模板将多个选中/未选中框值插入数据库?
- c# - 如何使用“upn”/“unique_name”(用户的电子邮件 ID)作为声明的一部分为我的 API 集成测试用例创建授权令牌
- android - CollapsingToolbarLayout 折叠时显示工具栏图标
- java - 使用反射根据接收到的参数访问属性 - Java
- c# - 从非根目录加载程序集
- java - 如何将文件从服务器(Spring 框架)上传到其他服务器(例如:112.12.15.2)
- c# - 序列的逆补