Given a situation that wrapping the JSON.stringify with my own function:
declare function stringify(
value: any,
replacer?: (key: string, value: any) => any,
space?: string | number
): string;
declare function stringify(
value: any,
replacer?: (number | string)[] | null,
space?: string | number
): string;
function myStringify(
data: object,
replacer: ((key: string, value: any) => any) | (number | string)[] | null,
space: string | number,
) {
return stringify(data, replacer, space); // TS error: type is compatible!
}
How to create my own method myStringify reuse the JSON.stringify?
You can check the error detail through the TS playground