// code snippet
interface TypeConfig { }
[tslint] 接口名称必须以大写的 I 开头(接口名称)
Microsoft 建议接口名称不要以 I 为前缀 - https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines#names
请注意,这些是编写 typescript 编译器本身的指南。 它并不意味着成为任何其他打字稿项目的风格指南。
如果你想在你的项目中采用这个风格指南,你只需将 tslint.json 中的规则配置更改为"interface-name" : [true, "never"]
来自路人的 50 美分:
"interface-name" : [true, "never-prefix"]
而不是"interface-name" : [true, "never"]
🙌
我尝试通过将 interface-name 添加到 Create React App 生成的默认tslint.json
来关闭“I”前缀。 但是,它似乎不起作用。 也许我把它放在错误的位置?
{
"extends": [
"tslint:recommended",
"tslint-react",
"tslint-config-prettier"
],
"linterOptions": {
"exclude": [
"config/**/*.js",
"node_modules/**/*.ts"
]
},
"interface-name" : [true, "never-prefix"]
}
没关系,我想通了:
{
"extends": [
"tslint:recommended",
"tslint-react",
"tslint-config-prettier"
],
"linterOptions": {
"exclude": [
"config/**/*.js",
"node_modules/**/*.ts"
]
},
"rules": {
"interface-name" : [true, "never-prefix"]
}
}
出于某种原因, "interface-name": [true, "never"]
对我不起作用。 但是"interface-name": false
工作正常
@vasilev-alex "interface-name": [true, "never-prefix"]
强调 never-前缀
我仍然收到"interface name must start with a capitalized I"
这是我的 tslint.json:
{
"rules": {
"interface-name": [
true,
"never-prefix"
]
},
"extends": [
"tslint:recommended",
"tslint-react",
"tslint-config-prettier"
],
"linterOptions": {
"exclude": [
"config/**/*.js",
"node_modules/**/*.ts",
"coverage/lcov-report/*.js"
]
}
}
我究竟做错了什么?
@offg777没什么明显的。 链接到回购?
配置对我来说看起来是正确的 - 你确定没有其他东西可以覆盖它吗? 该规则绝对适合我
@offg777
“接口名称必须以大写的 I 开头”
你从哪里得到这个错误? 从您的 IDE 还是在运行 CLI 时?
而且我不知道 tslint 的确切级联规则,但是您是否尝试过将“规则”块放在“扩展”之下?
厉害
eslint 已经支持了吗?
环境
"rules": {
"interface-name": [
true,
"never-prefix"
]
},
结果是Configuration for rule "interface-name" is invalid
也许这条规则存在是有原因的? 每个接口都应该有一个与实现类明显不同的有意义的名称吗?
这是强迫世界其他地方遵循您的偏好_在您自己的项目之外_的令人讨厌的想法。 在编程工具中侵犯您自己的命名约定是产品开发人员神经网络的一个错误;)
好消息是 TSLint 已被弃用,那么这个问题不再相关! #4534
最有用的评论
没关系,我想通了: