[英]Typescript: Disabling es-lint rule for only an interface?
I have the rule in my project to disallow variables not in camelcase.我在我的项目中有规则禁止不在驼峰式中的变量。 I am hitting an external API where the response comes back with an object that has variables in camelcase.
我正在访问一个外部 API,其中响应返回一个对象,该对象具有驼峰形式的变量。 When I define a type:
当我定义一个类型时:
interface AgeData {
name: string,
corner: number
}
interface APIResp {
file_name: string,
data_info: AgeData[],
interest_m: number
}
I need to use camelcase for the expected format back from the API since I can't control the external API.由于我无法控制外部 API,因此我需要使用驼峰式从 API 返回的预期格式。
Throughout the rest of my code, I use:在我的其余代码中,我使用:
// eslint-disable-next-line camelcase
to disable it but this doesn't seem to work for interfaces.禁用它,但这似乎不适用于接口。
I don't want to change the rule or override it.我不想更改规则或覆盖它。 It's a fairly large project and I just want it this one interface.
这是一个相当大的项目,我只想要一个界面。
I don't think camelcase
can be as type-aware as you're hoping for, but what it can do is:我不认为
camelcase
可以像您希望的那样具有类型意识,但它可以做的是:
So, one way is to use the following config for the ESLint rule:因此,一种方法是对 ESLint 规则使用以下配置:
[
'error',
{
allow: ['file_name', 'data_info', 'interest_m']
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.