Skip to content

Commit 83a8962

Browse files
committed
Make JSON.parse return a JSONValue instead of any
This makes type checking of things hangling JSON responses much more accurate and useful.
1 parent b534fb4 commit 83a8962

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/lib.es5.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,14 +1039,19 @@ interface URIErrorConstructor {
10391039

10401040
declare const URIError: URIErrorConstructor;
10411041

1042+
type JSONPrimitive = string | number | boolean | null;
1043+
type JSONValue = JSONPrimitive | JSONObject | JSONArray;
1044+
type JSONObject = { [member: string]: JSONValue };
1045+
interface JSONArray extends Array<JSONValue> {}
1046+
10421047
interface JSON {
10431048
/**
10441049
* Converts a JavaScript Object Notation (JSON) string into an object.
10451050
* @param text A valid JSON string.
10461051
* @param reviver A function that transforms the results. This function is called for each member of the object.
10471052
* If a member contains nested objects, the nested objects are transformed before the parent object is.
10481053
*/
1049-
parse(text: string, reviver?: (key: any, value: any) => any): any;
1054+
parse(text: string, reviver?: (key: any, value: any) => any): JSONValue;
10501055
/**
10511056
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
10521057
* @param value A JavaScript value, usually an object or array, to be converted.

0 commit comments

Comments
 (0)