我正在寻找一条规则来阻止使用“函数”作为类型
myMethod: Function;
我没有找到任何东西,所以我愿意接受建议:)
您可以使用@typescript-eslint/ban-types
rule 规则链接 https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md。但这也会禁止其他默认类型,例如String
, Boolean
, etc. 其他默认禁止类型链接 https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/src/rules/ban-types.ts#L56
如果您只想禁止Function
并禁用其他禁令,然后将其添加到您的.eslintrc
file.
"@typescript-eslint/ban-types": ["error",
{
"types": {
"String": false,
"Boolean": false,
"Number": false,
"Symbol": false,
"{}": false,
"Object": false,
"object": false,
"Function": true,
},
"extendDefaults": true
}
]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)