TypeScript Advanced Introduction
TypeScript Advanced treats the type system as a programming language that computes new types from existing types. The course pairs that language with the professional machinery around it, from decorators to strict compiler settings.
Preview: infer reads a return type
A conditional type with infer reads the return type of a function without naming that type by hand. Later lessons teach each part of this preview in full.
function loadScore(): { total: number; passed: boolean } {
return { total: 88, passed: true };
}
type ScoreResult = typeof loadScore extends () => infer R ? R : never;
const result: ScoreResult = { total: 90, passed: true };
console.log(result.total);
console.log(result.passed);Preview: a conditional picks a label
A conditional type chooses between two result types by checking its input. The label types below are computed entirely at compile time.
type Label<T> = T extends string ? 'text' : 'other';
type A = Label<string>;
type B = Label<number>;
const a: A = 'text';
const b: B = 'other';
console.log(a);
console.log(b);Example
function loadUser(): { userName: string; visits: number } {
return { userName: 'Ana', visits: 3 };
}
type UserResult = typeof loadUser extends () => infer R ? R : never;
type ResultLabel<T> = T extends { visits: number } ? 'tracked' : 'plain';
type UserLabel = ResultLabel<UserResult>;
const loaded: UserResult = { userName: 'Ben', visits: 5 };
const tag: UserLabel = 'tracked';
console.log(loaded.userName);
console.log(tag);Key points
- Finish typescript-beginner and typescript-intermediate first, because every lesson in this course builds on both.
- Conditional types, infer and distributive conditionals open the course by computing types with checks and extractions.
- Recursive types and branded types follow, then mapped types and template literal types at greater depth.
- Variance annotations and decorators come next, covering how generic types relate and how classes gain behavior.
- Declaration engineering and compiler configuration cover declaration files, module resolution and project references.
- Async depth and strictness hardening cover promise combinators, async iteration and the strictest checker flags.
- Type-level programming closes the course, and a final project combines the builds into one type-safe library.
In this example, the preview pattern reads the return type of loadUser, and a second conditional labels that result because the result carries a visits field.
Try it Yourself
Edit the code, then press Run.
Running is simulated · TypeScript Playground
Exercise
What does this course assume before the first lesson?