-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Fix return type for JSON.stringify(any) -> string #38574
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ea00c4b
Add definitions JSON.stringify returning undefined
jupiter c4c7d5c
Update for changed correct type
jupiter 67d7842
Revert change to lib after build scripts fixed
jupiter f26c011
Fix return type for JSON.stringify
jupiter 24ce526
Revert "Update for changed correct type"
jupiter a323061
Tolerate any and remove fix for Function
jupiter 1c0edd2
Update baselines
jupiter c7406f9
Merge remote-tracking branch 'upstream/master' into fix-18879
jupiter c3bb35f
Update baselines
jupiter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
Show resolved
Hide resolved
|
||
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; | ||
} | ||
|
||
/** | ||
|
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
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
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
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
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
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
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
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); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
space
isany
here?