Last active
September 4, 2023 17:32
-
-
Save garretmh/f5008746bcf32cb257047e7171219065 to your computer and use it in GitHub Desktop.
Proposed JSON type definition update
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
/** A parsed JSON value. */ | |
export type json = | |
| string | |
| number | |
| boolean | |
| null | |
| json[] | |
| { [key: string]: json }; | |
/** A JSON stringify-able value. */ | |
export type jsonable = | |
| string | |
| number | |
| boolean | |
| null | |
| undefined | |
| jsonable[] | |
| { [key: string]: jsonable } | |
| { toJSON(): jsonable }; | |
interface JSON { | |
/** | |
* Converts a JavaScript Object Notation (JSON) string into an object. | |
* @param text A valid JSON string. | |
*/ | |
parse(text: string): json; | |
/** | |
* Converts a JavaScript Object Notation (JSON) string into an object. | |
* @param text A valid JSON string. | |
* @param reviver A function that transforms the results. This function is called for each member of the object. | |
* If a member contains nested objects, the nested objects are transformed before the parent object is. | |
*/ | |
parse(text: string, reviver?: (this: json, key: string, value: json) => any): any; | |
/** | |
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string. | |
* @param value A JavaScript value, usually an object or array, to be converted. | |
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. | |
*/ | |
stringify(value: jsonable, replacer?: never, space?: string | number): string; | |
/** | |
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string. | |
* @param value A JavaScript value, usually an object or array, to be converted. | |
* @param replacer A function that transforms the results. | |
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. | |
*/ | |
stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string; | |
/** | |
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string. | |
* @param value A JavaScript value, usually an object or array, to be converted. | |
* @param replacer An array of strings and numbers that acts as an approved list for selecting the object properties that will be stringified. | |
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. | |
*/ | |
stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string; | |
} | |
/** | |
* An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. | |
*/ | |
declare var JSON: JSON; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment