Skip to content

noParameterProperties (since v1.0.0)

Diagnostic Category: lint/style/noParameterProperties

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) {}
}
style/noParameterProperties.js: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) {}
}