I'm working on a polyfill that extends the behavior of the JSON.parse()
function by adding an optional third argument to the reviver callback function.
The polyfill should be imported like this for the end users:
import 'my-polyfill';
The JSON.parse()
is defined in the node_modules/typescript/lib/lib.es5.d.ts
like this:
// lib.es5.d.ts
interface JSON {
// …
parse(
text: string,
reviver?: (this: any, key: string, value: any) => any
): any;
// …
}
How do I override this definition, so when the polyfill is installed/imported my definition is used instead? E.g.:
interface ContextType {
// …
}
interface JSON {
parse<Type = any>(
text: string,
reviver?: (
key: string,
value: any,
context?: ContextType
) => any
): Type;
}