- Error
- Reported by the type checker
TS2385
Overload signatures must all be public, private or protected.
All overloads of a method must have the same accessibility. Give every overload and the implementation the same public, private or protected modifier.
What it means
Overload signatures of a class method and its implementation form one member, so they must agree on accessibility. Mixing public, private and protected across the signatures of the same method is reported on the signature that differs from the first.
Example
export class Parser {
public parse(text: string): string;
private parse(text: string, strict: boolean): string;
public parse(text: string, strict?: boolean): string {
return strict ? text.trim() : text;
}
}
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(3,11): error TS2385: Overload signatures must all be public, private or protected.
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
- Use the same modifier on every overload and on the implementation.
- If one form should stay private, give it its own method name instead of an overload.