首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何禁用@typescript-eslint/no-null断言规则

如何禁用@typescript-eslint/no-null断言规则
EN

Stack Overflow用户
提问于 2020-02-20 13:04:56
回答 2查看 28.4K关注 0票数 32

我想让data!.id

错误:

警告禁止非空断言@typescript-eslint/no-null断言

当前配置:

代码语言:javascript
复制
module.exports = {
  parser: '@typescript-eslint/parser',
  extends: [
    'eslint:recommended',
    'plugin:jsx-a11y/recommended',
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:react/recommended',
    'prettier/@typescript-eslint',
    'plugin:prettier/recommended'
  ],
  plugins: ['react-hooks'],
  parserOptions: {
    ecmaVersion: 2020,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true
    }
  },
  rules: {
    '@typescript-eslint/ban-ts-ignore': 0,
    '@typescript-eslint/no-explicit-any': 0,
    '@typescript-eslint/consistent-type-assertions': ['warn', { assertionStyle: 'as' }],
    eqeqeq: 1,
    'react/prop-types': 0,
    '@typescript-eslint/camelcase': 0,
    'react-hooks/rules-of-hooks': 'error',
    'react-hooks/exhaustive-deps': 'warn'
  },
  globals: {
    React: 'writable'
  }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-02-20 13:54:15

请将'@typescript-eslint/no-non-null-assertion': 'off'添加到配置文件中,如下所示。

代码语言:javascript
复制
module.exports = {
  ...
  rules: {
    ...
    '@typescript-eslint/no-non-null-assertion': 'off'
  },
  ...
}
票数 48
EN

Stack Overflow用户

发布于 2021-06-07 10:54:23

如果您试图禁用整个文件的规则,将此注释添加到要忽略的文件顶部将有效:

代码语言:javascript
复制
/* eslint-disable  @typescript-eslint/no-non-null-assertion */

如果您试图仅在下一行上禁用规则(而不是对整个文件),则将此注释直接添加到要忽略的行后面将有效:

代码语言:javascript
复制
// eslint-disable-next-line  @typescript-eslint/no-non-null-assertion
票数 22
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60320613

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档