These are notes on TypeScript I have curated from my time spent answering Stack Overflow questions, including behavior, canonical issues, workarounds, and anti-patterns. I often find myself referencing the same documentation and GitHub issues from time to time, so I thought it would be nice if I had them all in one place.
All notes are written using the latest version of TypeScript.
This section contains useful TypeScript snippets, mostly utilities. Every snippet will include an explanation of why you would use it and how it works.
Here are a few common misconceptions, practices, and ideas that you should know. Most of these are inspired directly by Stack Overflow questions (and answers).
- Conditional type abuse
boolean
is a unionkeyof
with unions- Generics with default values
as
is not a cast- Mapped types:
This is a list of GitHub issues and pull requests I often reference, serving as a sort of landmark to build an answer upon. I check for newer issues or pull requests to add every so often.
- #13298 Type manipulations: union to tuple
- #25784 Bring back typedef property expansion
- #33912 Relate control flow to conditional types in return types
- #41164 Circular reference error when defining Record type
- #44312 Keyword to permit inferring a union for a type parameter
- #47486 Empty object type is not working
This is just a list of webpages I link to extremely often. Mostly just documentation, but sometimes there's a Stack Overflow Q&A or GitHub repository.