noParameterProperties
Summary
Section titled Summary- Rule available since:
v1.0.0
- Diagnostic Category:
lint/style/noParameterProperties
- This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Inspired from
@typescript-eslint/parameter-properties
- Inspired from
Description
Section titled DescriptionDisallow 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.
Examples
Section titled ExamplesInvalid
Section titled Invalidclass 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.
Valid
Section titled Validclass A { constructor(name: string) {}}
How to configure
Section titled How to configure{ "linter": { "rules": { "style": { "noParameterProperties": "error" } } }}