microsoft / microsoft/TypeScript
Docs: "Type assertion" vs "asserts" keyword
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Hey there!
I’m updating Programming TypeScript to include assertions in control flow analysis, and was looking for guidance about naming.
Type assertions (x as T) and assertions in control flow analysis (asserts x is T) are similarly named. What’s a good way to call these these features, in a way that doesn’t confuse people and aligns with the way the TS team is communicating it?
A couple of ideas:
- Rename
x as Tto “type coercion” or “type casting" (even though it’s not a runtime behavior), and callasserts x is Ta “type assertion” - Keep
x as Tas-is (“type assertion”), and callasserts x is Ta “user-defined type assertion”, similar to a “user-defined type guard”
Thanks!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the linked pull request 32695 and the issue’s discussion of x as T versus asserts x is T. Done means reaching an agreed naming convention that aligns with TypeScript’s communication and can guide the Programming TypeScript update.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100