如何禁止类属性中的非null断言运算符



没有非null断言有esint角色。我的问题是如何禁止在类属性中使用非null断言?

class A{
someProp!:string
}

是否有某种类型脚本配置或esint角色?

查看AST资源管理器,该产品被称为PropertyDefinition,添加!会将definite: true添加到对象中。因此,您可以将选择器PropertyDefinition[definite=true]no-restricted-syntax结合使用。

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

最新更新