noParameterProperties
このコンテンツはまだ日本語訳がありません。
Diagnostic Category: lint/style/noParameterProperties
Since: v1.0.0
Sources:
- Inspired from:
@typescript-eslint/parameter-properties
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.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-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.