问题描述
我正在寻找防止将“函数”用作类型的规则
myMethod: Function;
我什么都没找到,所以我愿意接受建议:)
解决方法
遵循规则Function
类型,您可以使用eslint
您可以使用@typescript-eslint/ban-types
规则Rule Link。但这也会禁止其他默认类型,例如String
,Boolean
等。Link of other default banned types
如果您只想禁止Function
并禁用其他禁止,则将其添加到您的.eslintrc
文件中。
"@typescript-eslint/ban-types": ["error",{
"types": {
"String": false,"Boolean": false,"Number": false,"Symbol": false,"{}": false,"Object": false,"object": false,"Function": true,},"extendDefaults": true
}
]