Skip to content

JSON.parse(), JSON.stringify() more specific declarations for #6955 - #28270

Merged
Ryan Cavanaugh (RyanCavanaugh) merged 3 commits into
microsoft:masterfrom
AnyhowStep:json-parse-reviver-stringify-replacer-better-declaration
Feb 2, 2019
Merged

Ryan Cavanaugh (RyanCavanaugh) merged 3 commits into
microsoft:masterfrom
AnyhowStep:json-parse-reviver-stringify-replacer-better-declaration

Conversation

@AnyhowStep

Copy link
Copy Markdown
Contributor

Fixes #6955

I made a few comments in that issue about being unclear about how the whole PR process works,

And it seems I broke 5 tests,

image
image
image

I assume it's because they are expecting the previous signature for JSON.parse() and JSON.stringify() but I've changed them.

I'm not sure how to read the output files in tests/baselines/local and decide if they're okay to baseline-accept (which I assume updates the expected results) but I made a best-effort attempt to look through them and they seemed okay to me.

@msftclas

Microsoft Contribution License Agreements (msftclas) commented Oct 31, 2018 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@AnyhowStep AnyhowStep changed the title Json parse reviver stringify replacer better declaration JSON.parse(), JSON.stringify() more specific declarations for #6955 Nov 1, 2018
@dalen

Copy link
Copy Markdown

Shouldn't JSON.parse really return an unknown rather than any?

@AnyhowStep

AnyhowStep commented Nov 8, 2018 •

Copy link
Copy Markdown
Contributor Author

Ah, yes. That makes sense. Personally, I'm in favour of it now that you've pointed it out but I think it might break code for a lot of people.

[EDIT]

To elaborate, I think changing it to unknown would be good. And breaking existing code in this case isn't actually bad because it would force them to re-examine their code and make type guards and whatnot. Or, if they're lazy, cast with as any.

But I'm not sure how the TS team feels about such a change.

Comment thread lib/lib.es5.d.ts Outdated
* @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?: (key: string, value: any) => any, space?: string | number): string;
stringify(value: any, replacer?: (this : any, key: string, value: any) => any, space?: string | number): string;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the stray space?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK to merge after Monday

@RyanCavanaugh

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) test this please

@typescript-bot

TypeScript Bot (typescript-bot) commented Feb 1, 2019 •

Copy link
Copy Markdown
Contributor

Heya Ryan Cavanaugh (@RyanCavanaugh), I've started to run the extended test suite on this PR at dd3ed02. You can monitor the build here. It should now contribute to this PR's status checks.

@RyanCavanaugh

Copy link
Copy Markdown
Member

Nothing relevant in RWC, GTG

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants