- Error
- Reported by the type checker
TS2387
Function overload must be static.
Overloads of a class method mix static and instance signatures. Make every overload of the member static, or none of them.
What it means
Overloads and their implementation must all live on the same side of the class. When the first signature for a name is static, a later signature or implementation without static is reported.
Example
export class Ids {
static next(prefix: string): string;
next(prefix: string): string {
return prefix + "1";
}
}
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(3,3): error TS2387: Function overload must be static.
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
- Make every overload and the implementation
static. - If you need both an instance and a static method, give them different names.