TS2394

error TS2394: This overload signature is not compatible with its implementation signature.

Bad Code ❌

The implementation does not match all signatures:

1
2
3
4
5
export function stringifyJSON(json: object): string;
export function stringifyJSON(json: string): string {
const sorted = parseJSON(json);
return JSON.stringify(sorted, null, 2);
}

Fixed Code ✔️

The implementation must match all signatures:

1
2
3
4
5
export function stringifyJSON(json: object): string;
export function stringifyJSON(json: string | object): string {
const sorted = typeof json === 'string' ? parseJSON(json) : json;
return JSON.stringify(sorted, null, 2);
}