Skip to content

typescript/no-unnecessary-parameter-property-assignment Correctness ​

✅ This rule is turned on by default.
💡 A suggestion is available for this rule.

What it does ​

Prevents unnecessary assignment of parameter properties.

Why is this bad? ​

Constructor parameters marked with one of the visibility modifiers public, private, protected, or readonly are automatically initialized. Providing an explicit assignment is unnecessary and can be removed.

Examples ​

Examples of incorrect code for this rule:

js
class Foo {
  constructor(public name: unknown) {
    this.name = name;
  }
}

Examples of correct code for this rule:

js
class Foo {
  constructor(public name: unknown) {}
}

How to use ​

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny typescript/no-unnecessary-parameter-property-assignment
json
{
  "rules": {
    "typescript/no-unnecessary-parameter-property-assignment": "error"
  }
}

References ​

Released under the MIT License.