- Error
- Reported by the type checker
TS2369
A parameter property is only allowed in a constructor implementation.
A parameter property (`public x` in a parameter list) is used outside a constructor body. Move it to the constructor, or remove the modifier.
What it means
Modifiers such as public, private and readonly on parameters declare class properties, and only work on a constructor implementation. On methods, functions, constructor overloads or declarations without a body they are reported.
Example
export class User {
greet(private name: string) {
return name;
}
}
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(2,9): error TS2369: A parameter property is only allowed in a constructor implementation.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- Remove the modifier, or move the parameter to the constructor.