Created
January 11, 2021 04:22
-
-
Save ifyour/d5c904a6b0b5c548d9cc4d76783d071e to your computer and use it in GitHub Desktop.
JSON 操作不丢失类型
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare class Stringified<T> extends String { | |
private ___stringified: T | |
} | |
interface JSON { | |
stringify<T>( | |
value: T, | |
replacer?: (key: string, value: any) => any, | |
space?: string | number | |
): string & Stringified<T> | |
parse<T>(text: Stringified<T>, reviver?: (key: any, value: any) => any): T | |
parse(text: string, reviver?: (key: any, value: any) => any): any | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
demo: https://tsplay.dev/json-string-type