Skip to content

Commit ecaf6d9

Browse files
authored
Revert "Add undefined to JSON.stringify return type (#51897)" (#52307)
1 parent 38b8f59 commit ecaf6d9

21 files changed

+59
-106
lines changed

src/lib/es5.d.ts

-7
Original file line numberDiff line numberDiff line change
@@ -1117,13 +1117,6 @@ interface JSON {
11171117
* If a member contains nested objects, the nested objects are transformed before the parent object is.
11181118
*/
11191119
parse(text: string, reviver?: (this: any, key: string, value: any) => any): any;
1120-
/**
1121-
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
1122-
* @param value A JavaScript value, usually an object or array, to be converted.
1123-
* @param replacer An array of strings and numbers that acts as an approved list for selecting the object properties that will be stringified.
1124-
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
1125-
*/
1126-
stringify(value: Function | Symbol | undefined, replacer?: (number | string)[] | null, space?: string | number): undefined;
11271120
/**
11281121
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
11291122
* @param value A JavaScript value, usually an object or array, to be converted.

tests/baselines/reference/controlFlowPropertyDeclarations.symbols

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ export class HTMLtoJSX {
232232
>whitespace : Symbol(whitespace, Decl(controlFlowPropertyDeclarations.ts, 121, 50))
233233

234234
return '{' + JSON.stringify(whitespace) + '}';
235-
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
235+
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
236236
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
237-
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
237+
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
238238
>whitespace : Symbol(whitespace, Decl(controlFlowPropertyDeclarations.ts, 121, 50))
239239

240240
});

tests/baselines/reference/controlFlowPropertyDeclarations.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ export class HTMLtoJSX {
316316
>'{' + JSON.stringify(whitespace) : string
317317
>'{' : "{"
318318
>JSON.stringify(whitespace) : string
319-
>JSON.stringify : { (value: Function | Symbol, replacer?: (string | number)[], space?: string | number): undefined; (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (string | number)[], space?: string | number): string; }
319+
>JSON.stringify : { (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (string | number)[], space?: string | number): string; }
320320
>JSON : JSON
321-
>stringify : { (value: Function | Symbol, replacer?: (string | number)[], space?: string | number): undefined; (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (string | number)[], space?: string | number): string; }
321+
>stringify : { (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (string | number)[], space?: string | number): string; }
322322
>whitespace : string
323323
>'}' : "}"
324324

tests/baselines/reference/destructuringInitializerContextualTypeFromContext.symbols

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ const Child: SFC<Props> = ({
5151

5252
}) => `name: ${name} props: ${JSON.stringify(props)}`;
5353
>name : Symbol(name, Decl(destructuringInitializerContextualTypeFromContext.ts, 15, 13))
54-
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
54+
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
5555
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
56-
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
56+
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
5757
>props : Symbol(props, Decl(destructuringInitializerContextualTypeFromContext.ts, 16, 21))
5858

5959
// Repro from #29189

tests/baselines/reference/destructuringInitializerContextualTypeFromContext.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ const Child: SFC<Props> = ({
5050
>`name: ${name} props: ${JSON.stringify(props)}` : string
5151
>name : "Apollo" | "Artemis" | "Dionysus" | "Persephone"
5252
>JSON.stringify(props) : string
53-
>JSON.stringify : { (value: Function | Symbol | undefined, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): undefined; (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
53+
>JSON.stringify : { (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
5454
>JSON : JSON
55-
>stringify : { (value: Function | Symbol | undefined, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): undefined; (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
55+
>stringify : { (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
5656
>props : {}
5757

5858
// Repro from #29189

tests/baselines/reference/destructuringParameterDeclaration4.errors.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
4141
a1(...array2); // Error parameter type is (number|string)[]
4242
~~~~~~
4343
!!! error TS2552: Cannot find name 'array2'. Did you mean 'Array'?
44-
!!! related TS2728 /.ts/lib.es5.d.ts:1502:13: 'Array' is declared here.
44+
!!! related TS2728 /.ts/lib.es5.d.ts:1495:13: 'Array' is declared here.
4545
a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]]
4646
~~~~~~~~
4747
!!! error TS2322: Type 'string' is not assignable to type '[[any]]'.

tests/baselines/reference/destructuringTuple.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ tests/cases/compiler/destructuringTuple.ts(11,60): error TS2769: No overload mat
3333
!!! error TS2769: Overload 2 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error.
3434
!!! error TS2769: Type 'never[]' is not assignable to type '[]'.
3535
!!! error TS2769: Target allows only 0 element(s) but source may have more.
36-
!!! related TS6502 /.ts/lib.es5.d.ts:1467:24: The expected type comes from the return type of this signature.
37-
!!! related TS6502 /.ts/lib.es5.d.ts:1473:27: The expected type comes from the return type of this signature.
36+
!!! related TS6502 /.ts/lib.es5.d.ts:1460:24: The expected type comes from the return type of this signature.
37+
!!! related TS6502 /.ts/lib.es5.d.ts:1466:27: The expected type comes from the return type of this signature.
3838
~~
3939
!!! error TS2769: No overload matches this call.
4040
!!! error TS2769: Overload 1 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.

tests/baselines/reference/duplicateNumericIndexers.errors.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tests/cases/conformance/types/members/duplicateNumericIndexers.ts(25,5): error T
1111
tests/cases/conformance/types/members/duplicateNumericIndexers.ts(29,5): error TS2374: Duplicate index signature for type 'number'.
1212
tests/cases/conformance/types/members/duplicateNumericIndexers.ts(30,5): error TS2374: Duplicate index signature for type 'number'.
1313
lib.es5.d.ts(517,5): error TS2374: Duplicate index signature for type 'number'.
14-
lib.es5.d.ts(1488,5): error TS2374: Duplicate index signature for type 'number'.
14+
lib.es5.d.ts(1481,5): error TS2374: Duplicate index signature for type 'number'.
1515

1616

1717
==== tests/cases/conformance/types/members/duplicateNumericIndexers.ts (12 errors) ====

tests/baselines/reference/json.stringify.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@ JSON.stringify(value, undefined, 2);
44
JSON.stringify(value, null, 2);
55
JSON.stringify(value, ["a", 1], 2);
66
JSON.stringify(value, (k) => undefined, 2);
7-
JSON.stringify(() => {}, undefined, 2);
8-
JSON.stringify(Symbol('s'), undefined, 2);
9-
JSON.stringify(undefined, undefined, 2);
7+
JSON.stringify(value, undefined, 2);
108

119
//// [json.stringify.js]
1210
var value = null;
1311
JSON.stringify(value, undefined, 2);
1412
JSON.stringify(value, null, 2);
1513
JSON.stringify(value, ["a", 1], 2);
1614
JSON.stringify(value, function (k) { return undefined; }, 2);
17-
JSON.stringify(function () { }, undefined, 2);
18-
JSON.stringify(Symbol('s'), undefined, 2);
19-
JSON.stringify(undefined, undefined, 2);
15+
JSON.stringify(value, undefined, 2);

tests/baselines/reference/json.stringify.symbols

+17-30
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,36 @@ var value = null;
33
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
44

55
JSON.stringify(value, undefined, 2);
6-
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
7-
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
8-
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
6+
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
7+
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
8+
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
99
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
1010
>undefined : Symbol(undefined)
1111

1212
JSON.stringify(value, null, 2);
13-
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
14-
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
15-
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
13+
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
14+
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
15+
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
1616
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
1717

1818
JSON.stringify(value, ["a", 1], 2);
19-
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
20-
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
21-
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
19+
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
20+
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
21+
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
2222
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
2323

2424
JSON.stringify(value, (k) => undefined, 2);
25-
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
26-
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
27-
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
25+
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
26+
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
27+
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
2828
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
2929
>k : Symbol(k, Decl(json.stringify.ts, 4, 23))
3030
>undefined : Symbol(undefined)
3131

32-
JSON.stringify(() => {}, undefined, 2);
33-
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
34-
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
35-
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
36-
>undefined : Symbol(undefined)
37-
38-
JSON.stringify(Symbol('s'), undefined, 2);
39-
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
40-
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
41-
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
42-
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
43-
>undefined : Symbol(undefined)
44-
45-
JSON.stringify(undefined, undefined, 2);
46-
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
47-
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
48-
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
49-
>undefined : Symbol(undefined)
32+
JSON.stringify(value, undefined, 2);
33+
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
34+
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
35+
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
36+
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
5037
>undefined : Symbol(undefined)
5138

0 commit comments

Comments
 (0)