我需要对接口或类型内的属性使用 Snake_case。我设定camelcase规则
'camelcase': ["error", {properties: "never"}],
Run Code Online (Sandbox Code Playgroud)
正如文档中提到的。它不适用于接口和类型,但适用于 JS 对象。
export const test = {
a_b: 1, // OK. No error
};
export interface ITest {
a_b: number, // Identifier 'a_b' is not in camel case.eslint(camelcase)
}
export type TTest = {
a_b: number, // Identifier 'a_b' is not in camel case.eslint(camelcase)
}
Run Code Online (Sandbox Code Playgroud)
当我将规则设置为 时,错误消失'off',因此此规则适用于 .ts 文件。
那么如何在TS中使用snake_case呢?谢谢。