Skip to content

docs(lib): add @throws JSDoc for JSON methods #61596

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

Merged
merged 3 commits into from
May 2, 2025

Conversation

Joseph-Martre
Copy link
Contributor

@Joseph-Martre Joseph-Martre commented Apr 20, 2025

Adds @throws JSDoc documentation to JSON.parse and JSON.stringify to clarify their potential error behavior.
This helps developers better understand the runtime exceptions these methods may produce, and improves IDE support/documentation.

Related to #43528

Alignment with TypeScript Design Goals:

  • (2) Provide a structuring mechanism for larger pieces of code.
  • (10) Be a cross-platform development tool.

Test Criteria

This PR only introduces documentation changes in .d.ts files.
It does not affect runtime behavior or type system behavior, and therefore does not require test cases.

Would like feedback on whether this direction makes sense for error documentation in the TypeScript repo.

@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Apr 20, 2025
@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Apr 20, 2025
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@Joseph-Martre
Copy link
Contributor Author

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

Related to #43528

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

One small wording suggestion for your consideration.

I think having more information is better in jsdoc, although I should point out that we are headed towards less checking of @throws in TS7, not more. This would be for human readers only.

@github-project-automation github-project-automation bot moved this from Not started to Waiting on author in PR Backlog Apr 29, 2025
Co-authored-by: Nathan Shively-Sanders <[email protected]>
@Joseph-Martre
Copy link
Contributor Author

I think having more information is better in jsdoc, although I should point out that we are headed towards less checking of @throws in TS7, not more. This would be for human readers only.

Yes, this isn't intended as a step toward compile-time checking of thrown values. The goal is to provide clearer information in the IDE about which methods can throw, and what they can throw. This should help developers write more robust software with better error handling.

@Joseph-Martre
Copy link
Contributor Author

Updated the JSDoc of the second stringify method to match the suggested change in the first. (The doc tag is duplicated because the method is overloaded.)

@github-project-automation github-project-automation bot moved this from Waiting on author to Needs merge in PR Backlog May 2, 2025
@sandersn sandersn merged commit d88d3a4 into microsoft:main May 2, 2025
32 checks passed
@github-project-automation github-project-automation bot moved this from Needs merge to Done in PR Backlog May 2, 2025
@ethanresnick
Copy link
Contributor

I should point out that we are headed towards less checking of @throws in TS7, not more.

@sandersn I'm just curious what this means, since I wasn't aware that today's TS did any checking of @throws. What am I missing, and what's being removed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants