Skip to main content

no-unnecessary-parameter-property-assignment

Disallow unnecessary assignment of constructor property parameter.

TypeScript 的参数属性 允许在一个地方创建和初始化成员。因此,在大多数情况下,没有必要将同名的参数属性分配给构造函数中的成员。

¥TypeScript's parameter properties allow creating and initializing a member in one place. Therefore, in most cases, it is not necessary to assign parameter properties of the same name to members within a constructor.

eslint.config.mjs
export default tseslint.config({
rules: {
"@typescript-eslint/no-unnecessary-parameter-property-assignment": "error"
}
});

在线运行试试这个规则 ↗

示例

¥Examples

class Foo {
constructor(public bar: string) {
this.bar = bar;
}
}
Open in Playground

选项

该规则不可配置。

何时不使用它

¥When Not To Use It

如果你不使用参数属性,则可以忽略此规则。

¥If you don't use parameter properties, you can ignore this rule.

'## 资源'