Skip to content

Instantly share code, notes, and snippets.

@kevincharm
Last active July 20, 2018 02:59
Show Gist options
  • Save kevincharm/f7b22113588ec161cfe35e152c33fc69 to your computer and use it in GitHub Desktop.
Save kevincharm/f7b22113588ec161cfe35e152c33fc69 to your computer and use it in GitHub Desktop.
Tagged types for JSON.stringify and JSON.parse. Extended from: https://github.com/Microsoft/TypeScript/issues/19244
class Stringified<T> {
private ___stringified: T
}
interface JSON {
stringify(
value: any,
replacer?: (key: string, value: any) => any,
space?: string | number
): string
stringify<T>(
value: T,
replacer?: (key: string, value: any) => any,
space?: string | number
): string & Stringified<T>
parse(text: string, reviver?: (key: any, value: any) => any): any
parse<T>(text: Stringified<T>, reviver?: (key: any, value: any) => any): T
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment