Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13.7k
Fix return type for JSON.stringify(any) -> string#38574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
ea00c4bc4c7d5c67d7842f26c01124ce526a3230611c0edd2c7406f9c3bb35fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1040,17 +1040,40 @@ interface JSON { | ||
| /** | ||
| * 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 replacer An array of strings and numbers that acts as a 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?: (this: any, key: string, value: any) => any, space?: string | number): string; | ||
| stringify( | ||
| value: number | string | boolean | null | object, | ||
| replacer?: (number | string)[] | null, | ||
| space?: string | number | ||
| ): string; | ||
| stringify( | ||
| value: undefined | Symbol, | ||
| replacer?: (number | string)[] | null, | ||
| space?: any | ||
| ): undefined; | ||
| stringify( | ||
jupiter marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| value: any, | ||
| replacer?: (number | string)[] | null, | ||
| space?: string | number | ||
| ): 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 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; | ||
| stringify( | ||
| value: any, | ||
| replacer: (this: any, key: string, value: any) => number | string | boolean | null | object, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uses this overload and returns | ||
| space?: string | number | ||
| ): string; | ||
| stringify( | ||
| value: any, | ||
| replacer?: (this: any, key: string, value: any) => any, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think | ||
| space?: string | number | ||
| ): any; | ||
| } | ||
| /** | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,52 @@ | ||
| //// [json.stringify.ts] | ||
| var anyReplacer = (k) => undefined; | ||
| var failsafeReplacer = (k) => null; | ||
| var value = null; | ||
| JSON.stringify(value, undefined, 2); | ||
| JSON.stringify(value, null, 2); | ||
| JSON.stringify(value, ["a", 1], 2); | ||
| JSON.stringify(value, (k) => undefined, 2); | ||
| JSON.stringify(value, undefined, 2); | ||
| JSON.stringify(value, anyReplacer, 2); | ||
| JSON.stringify(value, failsafeReplacer, 2); | ||
| JSON.stringify(value, undefined, 2); | ||
| JSON.stringify(undefined); | ||
| JSON.stringify(undefined, anyReplacer); | ||
| JSON.stringify(undefined, failsafeReplacer); | ||
| JSON.stringify(() => "", anyReplacer); | ||
| JSON.stringify(() => "", failsafeReplacer); | ||
| JSON.stringify({}); | ||
| JSON.stringify({}, anyReplacer); | ||
| JSON.stringify({}, failsafeReplacer); | ||
| JSON.stringify(new Object()); | ||
| JSON.stringify(new Object(), anyReplacer); | ||
| JSON.stringify(new Object(), failsafeReplacer); | ||
| var anyValue: any; | ||
| JSON.stringify(anyValue); | ||
| JSON.stringify(anyValue, anyReplacer); | ||
| JSON.stringify(anyValue, failsafeReplacer); | ||
| //// [json.stringify.js] | ||
| var anyReplacer = function (k) { return undefined; }; | ||
| var failsafeReplacer = function (k) { return null; }; | ||
| var value = null; | ||
| JSON.stringify(value, undefined, 2); | ||
| JSON.stringify(value, null, 2); | ||
| JSON.stringify(value, ["a", 1], 2); | ||
| JSON.stringify(value, function (k) { return undefined; }, 2); | ||
| JSON.stringify(value, anyReplacer, 2); | ||
| JSON.stringify(value, failsafeReplacer, 2); | ||
| JSON.stringify(value, undefined, 2); | ||
| JSON.stringify(undefined); | ||
| JSON.stringify(undefined, anyReplacer); | ||
| JSON.stringify(undefined, failsafeReplacer); | ||
| JSON.stringify(function () { return ""; }, anyReplacer); | ||
| JSON.stringify(function () { return ""; }, failsafeReplacer); | ||
| JSON.stringify({}); | ||
| JSON.stringify({}, anyReplacer); | ||
| JSON.stringify({}, failsafeReplacer); | ||
| JSON.stringify(new Object()); | ||
| JSON.stringify(new Object(), anyReplacer); | ||
| JSON.stringify(new Object(), failsafeReplacer); | ||
| var anyValue; | ||
| JSON.stringify(anyValue); | ||
| JSON.stringify(anyValue, anyReplacer); | ||
| JSON.stringify(anyValue, failsafeReplacer); |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
spaceisanyhere?