TypeScript Tutorials
TypeScript from the first annotation to a codebase that holds together — the type system itself, then what changes when you point it at a real project: unions instead of enums, generics that earn their place, the tsconfig flags that decide what compiles, decorators, and React. Every example is lifted from a working pizza ordering app, so code in these posts is code that runs.
- TypeScript – Interview QuestionsThe questions a TypeScript role actually asks, answered against the twenty lessons before this one. any versus unknown, interface versus type, why enum is contentious, what structural typing means in practice, how narrowing works, what erases at build time and what does not. Short answers, with the reasoning behind them.
- TypeScript – With ReactTyping props and children, useState where inference is enough and where it is not, useRef's two different types, event handlers, and generic components. Plus the context pattern that removes the `| undefined` every consumer would otherwise have to handle, taken from this app's auth provider.
- TypeScript – DecoratorsA decorator is a function that runs when the class is defined. What @Injectable, @Column and @Post are really doing, the metadata reflection that lets a framework read your parameter types at runtime, writing your own, and the split between the legacy experimentalDecorators and the standard ones — with which this app uses.
- TypeScript – tsconfig, the Flags That MatterMost of tsconfig you set once. These are the ones that change what compiles: the strict family one flag at a time, target and lib and how they differ, moduleResolution, noEmit, erasableSyntaxOnly, and path aliases. Read off the two real configs in this app — which disagree with each other, correctly.
- TypeScript – Modules and Type-Only Importsimport type and why a bundler needs you to say it, verbatimModuleSyntax, and the reason the NestJS half of this app writes `.js` in an import that points at a `.ts` file. Module resolution in one page, declaration files, and what to do about a package that ships no types.
- TypeScript – Assertions, as const and satisfies`as` is you overruling the checker, and it is the one construct here that can make a program crash. When it is legitimate, the double-assertion escape hatch and why needing it is a warning, non-null `!`, and then `satisfies` — the operator that checks a value against a type without widening it, which is what you usually wanted.
- TypeScript – keyof, Mapped and Conditional TypesThe machinery the utility types are built from. keyof and typeof and what they mean together, indexed access, mapped types with their modifiers, conditional types and infer. Ending with the expression this app uses in two files — `(typeof UserRole)[keyof typeof UserRole]` — read one piece at a time.
- TypeScript – The Utility Types Worth KnowingPartial, Required, Readonly, Pick, Omit, Record, Exclude, Extract, NonNullable, ReturnType and Awaited — what each one is for, in the order you will actually need them. Including the Record in this app that turns adding a status to a union into a build error until somebody writes the label for it.
- TypeScript – GenericsA generic is a function's type argument, and the point is preserving a relationship the checker would otherwise lose. Constraints with extends, defaults, generic interfaces and classes, and the rule for when NOT to reach for one — with a data loading hook that would return `any` without them.
- TypeScript – Classespublic, private and protected, and why TypeScript's private is a compile-time promise while #private is a runtime one. readonly, parameter properties and the build flag that bans them, abstract classes, implements versus extends, and subclassing Error so the UI can tell a rejected write from a server that fell over.
- TypeScript – FunctionsParameter and return types, optional and default and rest parameters, and the function type itself — the thing you annotate a callback with. Then overloads, when one signature genuinely cannot describe two call shapes, and why a union return type is usually the better answer than a second overload.
- TypeScript – Narrowing and Type GuardsNarrowing is what makes unions usable: typeof, instanceof, the in operator, truthiness and equality all teach the checker something. Then the two you write yourself — a predicate returning `x is Thing`, and the discriminated union — plus the never trick that turns a forgotten case into a build failure instead of a blank badge.
- TypeScript – Enums, and What to Use InsteadTypeScript's enum is the one feature in the language that emits runtime JavaScript, and everything awkward about it follows from that: reverse mappings that put numbers in your object, const enum breaking under isolatedModules, and a build flag that rejects it outright. Then the `as const` object this app uses in both halves instead.
- TypeScript – Unions and IntersectionsA union is a value that is one of these; an intersection is a value that is all of these at once. Why you can only reach the members a union has in common, why an intersection of two conflicting properties gives you never rather than an error, and how a union of string literals replaces a validation function.
- TypeScript – Interfaces vs Type AliasesThey overlap almost completely, which is why the question keeps coming up. The three real differences — declaration merging, what each can name, and the error messages you get back — and the rule this app follows: interface for a shape with a name, type for everything a shape cannot express.
- TypeScript – Object TypesOptional properties and why `string | null` is not the same as `?`, readonly and exactly how shallow it is, index signatures for genuinely open-ended objects, nested shapes, and excess property checks — the rule that rejects an extra key on a literal but waves the same object through when it arrives in a variable.
- TypeScript – Arrays and Tuplesstring[] versus Array<string>, arrays of unions versus unions of arrays, and readonly arrays that stop a helper mutating its argument. Then tuples: fixed length, typed per position, and the one in this app's date formatter that would be Array<string | number> without them — which is to say, useless.
- TypeScript – any, unknown, never and voidThe four types that are not values. any switches the checker off and spreads; unknown is the safe version and forces you to prove what you have; never is what a function that does not return has, and the trick behind exhaustive switches; void is not undefined. With the catch (err: unknown) block that made the case.
- TypeScript – The Basic Typesstring, number, boolean and the annotations you do not need to write. Where inference is better than an explicit type and where it quietly gives up, why let and const infer differently, literal types, and the one place a return type is worth writing by hand even though TypeScript could work it out.
- TypeScript – Setting Up a ProjectTwo projects, two setups, and the difference matters. A Node service where tsc emits the JavaScript, and a Vite app where tsc only checks and the bundler strips the types. What tsc --init actually gives you, why noEmit is not a downgrade, and the four commands you will run every day.
- TypeScript – Get StartedStart here. What TypeScript actually is — a type checker that erases itself, not a language that runs — the three kinds of bug it catches and the one class it cannot, the exact versions this track is written against, the pizza ordering app every example is taken from, and the full lesson index in reading order.