Disallow parameter properties in class constructors.
This rule applies only to .js and .ts files.
// code-linter.json5
{
"rules": {
"@typescript-eslint/no-parameter-properties": "error"
}
} 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:
// code-linter.json5
{
"rules": {
"@typescript-eslint/no-parameter-properties": ["error", {"allows": ["readonly"]}]
}
} export class Foo {
public name: string;
public constructor(name: string) {
this.name = name;
}
} export class Foo {
// In the default configuration, readonly cannot be used for parameters.
public constructor(public readonly name: string) {}
} plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.