跳转到内容

noParameterProperties

此内容尚不支持你的语言。

Diagnostic Category: lint/style/noParameterProperties

Since: v1.0.0 Sources:

Disallow the use of parameter properties in class constructors.

TypeScript includes a “parameter properties” shorthand for declaring a class constructor parameter and class property in one location. Parameter properties can confuse those new to TypeScript as they are less explicit than other ways of declaring and initializing class members. Moreover, private class properties, starting with #, cannot be turned into “parameter properties”. This questions the future of this feature.

class A {
constructor(readonly name: string) {}
}
code-block.ts:2:17 lint/style/noParameterProperties ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Use a more explicit class property instead of a parameter property.

1 │ class A {
> 2 │ constructor(readonly name: string) {}
^^^^^^^^^^^^^^^^^^^^^
3 │ }
4 │

Parameter properties are less explicit than other ways of declaring and initializing class properties.

class A {
constructor(name: string) {}
}