Introduction
- 📺 TypeScript in 100 Seconds • 2 minute video by Fireship
- 📺 What is TypeScript? Why not just use JavaScript? • 6 minute video by Basarat Ali showing why TS is a safer version of JS
- 🧑🎓 Introduction to TypeScript • Free one-hour course by Scrimba that teaches you TypeScript through 21 interactive screencasts
- 📺 Let’s Learn TypeScript! • 91 minute video by Orta Therox and Jason Lengstorf showing how to gradually add TypeScript to a JavaScript project
- TypeScript on Exercism • Get fluent in TypeScript by solving 95 exercises • Exercism 👩🎓
Built-in types
- 📺 TypeScript UNKNOWN and ANY types • 5 minute video by Basarat Ali clearly explaining the difference between
any
andunknown
- 📺 unknown, never, and void in TypeScript • 15 minute video by William Candillon showing a colleague practical use cases for
unknown
andnever
andvoid
- 📺 null vs. undefined in JavaScript and TypeScript • 6 minute video by Basarat Ali showing examples of
null
andundefined
values and how to check for them - 📺 TypeScript NEVER type • 3 minute video by Basarat Ali showing how to use the
never
type to ensure all possible input types to a function have been handled - 📺 TypeScript TYPES vs INTERFACES • 7 minute video by Basarat Ali explaining the overlapping and unique features of types and interfaces and recommending to pick one as your default (he defaults to types) based on which one’s unique features are more likely to be useful to you
- 📖 The Omit Helper Type in TypeScript • Article by Marius Schulz
- TypeScript copy existing interface but change type on one property • How to use
Omit
to redefine one or more properties in a base type you’re extending • Stack Overflow 💬
Compiler options
- 📺 TypeScript alwaysStrict: Do you need it? • 3 minute video by Basarat Ali explaining the benefits of setting
alwaysStrict
totrue
- 📺 Why you should use allowUnreachableCode in TypeScript • 3 minute video by Basarat Ali explaining the benefits of setting
allowUnreachableCode
tofalse
Conditional types
- 📺 Conditional Types, TypeScript’s most POWERFUL feature • 4 minute video by Basarat Ali using the example of a
typeName
helper to demonstrate how conditional types work and why you can think of them as functions that compute an output (a specific type) based on an input (a generic type) - 📺 TypeScripts amazing INFER Keyword • 3 minute video by Basarat Ali showing how to use the
infer
keyword inside a conditional type to get the type name of the generic argument that was passed in
Generic types
- Why Generics? • 3 minute video by Basarat Ali showing how generics help in cases where a structure accepts alternating types of inputs and outputs 📺
- TypeScript Challenge! • Quick example of generics to define a method a function argument needs to include (like a trait in Rust) • Visual Studio Code 📺
Literal types
- 📺 Most common TypeScript literal types error • 4 minute video by Basarat Ali explaining how to reassure TS that a string or number is a valid member of a literal type
Special types
- 📺 Lookup Types - one of the first super powers of TypeScript • 3 minute video by Basarat Ali showing how lookup types can clean up your code and prevent typos by using a larger root type as the source of truth for smaller types
- 📺 What are TypeScript MAPPED Types and how to use them Effectively • 4 minute video by Basarat Ali using the example of creating a readonly version of an existing type to demonstrate how a mapped type is created by mapping over the properties of an existing type and modifying their definitions (similar to creating a new JS array by mapping over an existing array and returning a copy that transforms each item in some way)
- 📺 Mapped type MODIFIERS in TypeScript • 4 minute video by Basarat Ali showing how to use
+
,-
andPartial
to modify properties in a mapped type
Function return types
- Overloads
- Be Careful With Return Types In TypeScript • Theo 📺
Operators
- 📺 NULLISH operators ?. and ?? for JavaScript and TypeScript • 5 minute video by Basarat Ali showing how to use
?.
and??
- 📖 Nullish Coalescing: The ?? Operator in TypeScript • Article by Marius Schulz
Type guards
- 📺 TypeScript 2.7:
in
-based type guards • 2 minute video by Basarat Ali showing how to use the JSin
operator as a type guard that both TS and JS will understand
Narrowing
- Narrowing types at run-time with
typeof
andinstanceof
(really a JS thing, but useful in TS too) - Narrowing TS types with
arg is Type
type predicate functions- e.g.
function isString(arg: unknown): arg is string { return typeof arg === 'string'; }
- e.g.
function isFish(pet: Fish | Bird): pet is Fish { return (pet as Fish).swim !== undefined; }
(copied from docs)
- e.g.
- Narrowing TS types with
switch
statements - Narrowing TS types with function overloads (when the return type of a function changes as the type of its arguments change)
Editor features
- Adding a
@ts-check
comment at the top of a JS file will trigger TS checking in that file- In VS Code only?
Runtime Type Checking
- Parsing URL Search Parameters with Zod • Rafał Goławski 📖
- Zod Goes Where TypeScript Can’t • Theo 📺
Challenges
- Typescript Prevents Bad Things… and Good Things • Kyle Shevlin 📖
Make TS understand Array.filter by using type predicates
- Narrowing: Using type predicates • TypeScript docs 📚
- A colleague DM’d me with a TS puzzle that was solved by this on Nov 4, 2022 (check Slack)
- It’s super common for devs to expect TS will understand that Array.filter just narrowed the type
- But it doesn’t unless the function you put in that filter() is has a return type that’s a “type predicate” like “value is MyType”
- If the return type is just “boolean” as usual, TS doesn’t understand how that just narrowed your type options
Inbox
- Override individual properties by omitting them first, then joining the new property definitions as a union type
- TypeScript Utility Types You Need to Know
satisfies
operator:- Typescript’s new ‘satisfies’ operator | by Cefn Hoile | Medium
- TypeScript: Documentation - TypeScript 4.9 • TypeScript 4.9 Release Notes
- new Typescript “satisfies” operator - Stack Overflow
- TypeScript 4.9 ‘satisfies’ operator to ensure expression matches some type • The new ‘satisfies’ operator in TypeScript 4.9 allows for more flexible type sets without loosing information
- Better Configuration in TypeScript with the
satisfies
Operator • Typescript 4.9 introduced the new satisfies keyword, which is extremely handy for most configuration-related tasks in TypeScript.
- Handling errors like a pro in TypeScript • Kolby Sisk explains how to use discriminated unions to handle errors in TypeScript 📖
- Schema validation in TypeScript with Zod - LogRocket Blog
- GitHub - fabian-hiller/valibot: The modular and type safe schema library for validating structural data 🤖 • Zod alternative with smaller bundle 🧰
- VSCode Extension | Total TypeScript - VS Code extension that rephrases cryptic TS errors into plain English
- Clarifying the
satisfies
Operator | Total TypeScript - Matt Pocock - types - Is there a
valueof
similar tokeyof
in TypeScript? - Stack Overflow - Stack Overflow