docs: rm error code example and add more practical one and change casts to type assertions - #3621
Open
legend80s wants to merge 1 commit into
Open
docs: rm error code example and add more practical one and change casts to type assertions#3621legend80s wants to merge 1 commit into
legend80s wants to merge 1 commit into
Conversation
…e cast to type assertion.
Author
@microsoft-github-policy-service agree |
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What's the problem of current docs?
1. Type error and Inappropriate example
1
elementshould bemyElement2 type error and misplaced Example
This example doesn't fit the first use case of
@type— it's better suited for demonstrating casts. It should be removed from the first part of@typeintroduction.No more errors and the inline usage of
@typeassertion is well explained.2. Rename "Casts" to "Type Assertions"
It's functionally identical to TypeScript's
as— simply written as inline@typein JSDoc!C-style casts imply a runtime type conversion, whereas TypeScript's
assyntax and JSDoc's inline@typeare simply type assertions that do not affect runtime behavior. Thus, "Type Assertions" is a more accurate and less misleading term.3. Add example from https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions
4. Add JSDoc equivalent for
as unknown as TThe original docs don't show how to write nested inline assertions in JSDoc — a pattern many users don't know about.