![](/img/trans.png)
[英]ESlint & Angular 13: Unable to turn off typescript-eslint/typedef
[英]Turn off eslint camelCase for typescript interface identifiers
我正在尝试将现有的 JS 存储库迁移到 TypeScript。问题是项目的 API 响应是带有snake_case
标识符的对象,这与默认的 eslint camelCase
规则冲突。
在迁移之前,我们在 .eslintrc.js 中使用此规则处理snake_case
.eslintrc.js
标识符:
'camelcase': ['error', {properties: 'never'}],
在我们的代码中可以有这样的对象:
const { variable_name } = await axios(url)
但是在移动到 TypeScript 之后,这些标识符也会出现在界面中。
所以基本上我希望能够拥有:
interface Model<T extends string> {
type: T;
id: number;
variable_name: string;
language_code: string;
}
但是 Typescript 现在抛出:
Identifier 'variable_name' is not in camel case.
我的.eslintrc.js
文件中应该有什么规则来证明这一点? 请注意,我的标识符不仅限于上面列出的那两个,还有许多其他标识符,为了简单起见,我删除了它们。
请记住,JavaScript(为其开发 ESLint)不知道类型(例如接口)。
所以我认为这是在检查文件时发生的事情:
camelCase
规则适用于对象及其属性。我认为你需要做的是:
camelCase
规则(至少对于您的 TypeScript 文件)。这应该有效:
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "default",
"format": ["camelCase"]
},
{
"selector": "typeProperty",
"format": null
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.