目录

@typescript-eslint/no-parameter-properties

Disallow parameter properties in class constructors.

This rule applies only to .js and .ts files.

Rule Configuration

// code-linter.json5
{
  "rules": {
    "@typescript-eslint/no-parameter-properties": "error"
  }
}

Options

By default, no parameter property is allowed in constructors. If you want to use some properties, you can configure additional options.

allows: accepts a string array. The properties in the array can be used. The string supports the following values:

Example:
// code-linter.json5
{
  "rules": {
    "@typescript-eslint/no-parameter-properties": ["error", {"allows": ["readonly"]}]
  }
}

Example of Correct Code

export class Foo {
  public name: string;

  public constructor(name: string) {
    this.name = name;
  }
}

Example of Incorrect Code

export class Foo {
 // In the default configuration, readonly cannot be used for parameters.
  public constructor(public readonly name: string) {}
}

Rule Set

plugin:@typescript-eslint/all

For details about how to configure Code Linter check rules, see Code Linter.