我如何禁止 class 属性中的非空断言运算符?

How can i forbidden Non-null assertion operator in class properties?

no-non-null-assertion 有 eslint 角色。 我的问题是如何禁止在 class 属性中使用非空断言?

class A{
  someProp!:string
}

有一些 typescript 配置或 eslint 角色吗?

正在查看 the AST explorer, this production is called a PropertyDefinition, and adding the ! adds definite: true to the object. So, you can use the selector PropertyDefinition[definite=true] in combination with no-restricted-syntax

rules: {
    'no-restricted-syntax': ['error',
        {
            selector: 'PropertyDefinition[definite=true]',
            message: 'Non-null property assertions are forbidden',
        },
    ],
},