typescript - 如何修复 'Definition for rule ' @typescript-eslint/no-use-before-declare' is not found.eslint(@typescript-eslint/no-use-before-declare)'

标签 typescript eslint

我是 eslint 的新手,我不知道如何解决这个问题。我的导入的开头总是用红线标出。它提示找不到指定规则的定义。我想保留这条规则,因为它似乎在其他方面很有用。 enter image description here .

对于我的 .eslintrc.js 文件,我设置了以下规则:

`

module.exports = {
    env: {
        browser: true,
        node: true
    },
    extends: [
        'eslint:recommended',
        'plugin:@typescript-eslint/eslint-recommended',
        'plugin:@typescript-eslint/recommended',
        'plugin:@typescript-eslint/recommended-requiring-type-checking',
        'prettier'
    ],
    parser: '@typescript-eslint/parser',
    parserOptions: {
        project: 'tsconfig.json',
        sourceType: 'module'
    },
    plugins: ['@typescript-eslint', '@typescript-eslint/tslint'],
    rules: {
        '@typescript-eslint/class-name-casing': 'error',
        '@typescript-eslint/consistent-type-definitions': 'error',
        '@typescript-eslint/explicit-member-accessibility': [
            'off',
            {
                accessibility: 'explicit'
            }
        ],
        '@typescript-eslint/indent': ['error', 'tab'],
        '@typescript-eslint/member-delimiter-style': [
            'error',
            {
                multiline: {
                    delimiter: 'semi',
                    requireLast: true
                },
                singleline: {
                    delimiter: 'semi',
                    requireLast: false
                }
            }
        ],
        '@typescript-eslint/member-ordering': 'error',
        '@typescript-eslint/no-empty-function': 'off',
        '@typescript-eslint/no-empty-interface': 'error',
        '@typescript-eslint/no-inferrable-types': 'error',
        '@typescript-eslint/no-misused-new': 'error',
        '@typescript-eslint/no-non-null-assertion': 'error',
        '@typescript-eslint/no-use-before-declare': ['error', { functions: true, classes: true, variables: true }],
        '@typescript-eslint/prefer-function-type': 'error',
        '@typescript-eslint/quotes': ['error', 'single'],
        '@typescript-eslint/semi': ['error', 'always'],
        '@typescript-eslint/type-annotation-spacing': 'error',
        '@typescript-eslint/unified-signatures': 'error',
        'arrow-body-style': 'error',
        camelcase: 'off',
        'capitalized-comments': 'error',
        'constructor-super': 'error',
        curly: 'error',
        'dot-notation': 'off',
        'eol-last': 'error',
        eqeqeq: ['error', 'smart'],
        'guard-for-in': 'error',
        'id-blacklist': 'off',
        'id-match': 'off',
        'import/no-deprecated': 'warn',
        'max-classes-per-file': ['error', 1],
        'max-len': [
            'error',
            {
                code: 140
            }
        ],
        'no-bitwise': 'error',
        'no-caller': 'error',
        'no-console': [
            'error',
            {
                allow: [
                    'log',
                    'warn',
                    'dir',
                    'timeLog',
                    'assert',
                    'clear',
                    'count',
                    'countReset',
                    'group',
                    'groupEnd',
                    'table',
                    'dirxml',
                    'error',
                    'groupCollapsed',
                    'Console',
                    'profile',
                    'profileEnd',
                    'timeStamp',
                    'context'
                ]
            }
        ],
        'no-debugger': 'error',
        'no-empty': 'off',
        'no-eval': 'error',
        'no-fallthrough': 'error',
        'no-new-wrappers': 'error',
        'no-shadow': [
            'error',
            {
                hoist: 'all'
            }
        ],
        'no-throw-literal': 'error',
        'no-trailing-spaces': 'error',
        'no-undef-init': 'error',
        'no-underscore-dangle': 'off',
        'no-unused-expressions': 'error',
        'no-unused-labels': 'error',
        'no-var': 'error',
        'prefer-const': 'error',
        radix: 'error',
        'spaced-comment': 'error',
        '@typescript-eslint/tslint/config': [
            'error',
            {
                rules: {
                    'component-class-suffix': [true, 'Component', 'View', 'Routing'],
                    'contextual-lifecycle': true,
                    'directive-class-suffix': true,
                    'import-blacklist': [true, 'rxjs/Rx'],
                    'import-spacing': true,
                    'no-host-metadata-property': true,
                    'no-input-rename': true,
                    'no-inputs-metadata-property': true,
                    'no-output-on-prefix': true,
                    'no-output-rename': true,
                    'no-outputs-metadata-property': true,
                    'no-redundant-jsdoc': true,
                    'one-line': [true, 'check-open-brace', 'check-catch', 'check-else', 'check-whitespace'],
                    'template-banana-in-box': true,
                    'template-no-negated-async': true,
                    'use-component-view-encapsulation': true,
                    'use-lifecycle-interface': true,
                    'use-pipe-decorator': true,
                    'use-pipe-transform-interface': true,
                    'no-unused-vars': ['error', { vars: 'all', args: 'after-used', ignoreRestSiblings: false }],
                    whitespace: [true, 'check-branch', 'check-decl', 'check-operator', 'check-separator', 'check-type']
                }
            }
        ]
    }
};

`

除了删除规则之外,您知道如何解决这个问题吗?

谢谢

最佳答案

好根据这个page ,这条规则是不鼓励的,因为现代 TypeScript 不使用它并且计算速度很慢。所以你应该删除规则。

但是如果你仍然想继续使用它,你可以尝试像 { "no-use-before-define": ["error", { "variables": false }] } 这样的东西。

您可以阅读有关此内容的更多信息 here

关于typescript - 如何修复 'Definition for rule ' @typescript-eslint/no-use-before-declare' is not found.eslint(@typescript-eslint/no-use-before-declare)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59083632/

相关文章:

typescript - 如何在 eslint-plugin-import 中为 typescript 配置 `no-cycle` 规则?

javascript - ESLint 的 "no-undef"规则将我对 Underscore 的使用称为 undefined variable

typescript - 错误 TS2339 : Property 'x' does not exist on type 'Y'

typescript - ionic 服务后无法解析 [object OBJECT] 的所有参数

javascript - 类型 'map' .ts(2339) 上不存在属性 'AxiosResponse<any>'

visual-studio-code - VSCode中的ESLint无法在保存时修复

javascript - eslint await 期望一个赋值或函数调用,而是看到一个表达式

visual-studio-code - 在通过 Yarn 管理的 VSCode 中使用自定义 eslint 配置文件

javascript - 迭代绑定(bind)到键的数组(动态)

javascript - Typescript 调试仅适用于本地文件系统