All skill tracks
languages field guide
TypeScript
Structural typing, narrowing, generics, conditional and mapped types, module resolution, and strictness for TypeScript interviews.
4 difficulty sections16 modules4 lessons4815 min
16
Modules
4/128
Lessons written
4815 min
Total read time
4
Difficulty sections
Cheat sheet: TypeScript at a glance

128 of 4 lessons
- 1What problem does TypeScript actually solve that JavaScript alone does not, and what does it deliberately not solve?Basicconceptual30 minIn writing
- 2Walk me through what happens when tsc runs on a file: which stages does the compiler go through before it emits JavaScript?Basicconceptual40 minIn writing
- 3TypeScript types are erased at compile time. What does that rule out, and which TypeScript features are the exceptions?Basicconceptual35 minIn writing
- 4Your build uses esbuild or SWC to strip types and runs tsc only for type checking. Why split it that way, and what breaks if someone skips the tsc step?Intermediatepractical35 minIn writing
- 5What is the difference between a type error and a build failure, and how do noEmitOnError and isolatedModules change that relationship?Intermediatepractical35 minIn writing
- 6When would you argue against adding TypeScript to a project, and what would change your mind?Intermediateconceptual30 minIn writing
- 7A teammate says 'TypeScript caught a bug for us in production last night.' Explain why that sentence cannot be literally true, and what probably happened instead.Scenarioscenario45 minIn writing
- 8Quiz: check your grasp of what TypeScript compiles to, what it erases, and exactly where its guarantees stop.Basicconceptual20 minIn writing
- 9When should you write an explicit type annotation and when should you let TypeScript infer the type?Basicconceptual30 minIn writing
- 10How do you type a nested object, and what type does TypeScript give an object literal assigned to a variable with no annotation?Basicconceptual30 minIn writing
- 11What is the difference between `name?: string` and `name: string | undefined`, and when does that difference actually bite?Intermediatepractical35 minIn writing
- 12Compare `readonly` properties, `as const`, and `Object.freeze`. Which of them does the compiler enforce and which does the runtime enforce?Basicpractical35 minIn writing
- 13How do you type an object whose keys aren't known ahead of time, and what does noUncheckedIndexedAccess change about reading from it?Intermediatepractical40 minIn writing
- 14What does strictNullChecks actually change, and how do you handle a value that is legitimately absent without reaching for `!`?Intermediatetroubleshooting35 minIn writing
- 15A config object was typed with every field optional so callers could pass partial config. Six months later half the codebase is littered with `?.` and `??`. What went wrong, and how would you retype it?Scenarioscenario45 minIn writing
- 16Quiz: optional properties, readonly, index signatures, and where inference widens a literal.Basicconceptual20 minIn writing
- 17What is the practical difference between `any` and `unknown`, and why is `unknown` almost always the better choice at a trust boundary?Basicconceptual30 minIn writing
- 18Where does `never` show up in real code, and what is the compiler telling you when a variable narrows to it?Intermediateconceptual35 minIn writing
- 19Which everyday operations hand you an `any` even in a strict codebase, and how would you hunt them down?Intermediatetroubleshooting35 minIn writing
- 20What does `as` actually do at runtime, and what is the difference between an assertion, a cast, and validation?Intermediatepractical35 minIn writing
- 21When, if ever, is the non-null assertion operator `!` defensible, and what would you require alongside it in code review?Intermediatepractical30 minIn writing
- 22Production throws a runtime TypeError ('Cannot read properties of undefined') on a field that TypeScript's types say can never be undefined. How do you find where the type safety broke down?Scenarioscenario5 min
- 23You inherit a codebase with noImplicitAny off and roughly 400 implicit anys. In what order would you turn strictness on, and how do you keep the team shipping meanwhile?Scenarioscenario50 minIn writing
- 24Quiz: what any allows, what unknown forbids, and when a type narrows all the way to never.Basicconceptual20 minIn writing
- 25What is the difference between `string[]`, `Array<string>`, and `ReadonlyArray<string>`, and when does the readonly version pay for itself?Basicconceptual30 minIn writing
- 26When would you reach for a tuple type instead of an object or a plain array, and what do labelled tuple elements add?Intermediatepractical35 minIn writing
- 27How do variadic tuple types let you type a function like `pipe`, or a partial-application helper, without overloads?Advancedpractical45 minIn writing
- 28Which kinds of enum emit runtime JavaScript and which don't, and why do many teams ban `enum` outright?Intermediateconceptual35 minIn writing
- 29How does `as const` give you enum-like behaviour with no runtime cost, and what do you give up by using it?Intermediatepractical30 minIn writing
- 30Why does TypeScript happily let you read `arr[10]` from a three-element array, and what would you turn on to stop it?Intermediatetroubleshooting30 minIn writing
- 31A shared `Status` enum is used across a frontend, a backend, and a database migration. Argue for or against keeping it an enum, and say exactly what you would replace it with.Scenarioscenario45 minIn writing
- 32Quiz: array vs tuple vs readonly array, enum emit behaviour, and const assertions.Basicconceptual20 minIn writing
- 33TypeScript uses structural typing instead of nominal typing. What does that mean in practice, and where does it surprise developers coming from Java or C#?Basicconceptual5 min
- 34Interfaces and type aliases overlap heavily. What can each one do that the other cannot, and which do you reach for by default?Basicconceptual30 minIn writing
- 35What is declaration merging, when is it genuinely useful, and why is it also a footgun in application code?Intermediateconceptual35 minIn writing
- 36What is the difference between `interface B extends A` and `type B = A & { ... }` when the two disagree about a property's type?Intermediatepractical35 minIn writing
- 37Why does passing an object literal directly trigger an excess property error while assigning it to a variable first does not?Intermediatetroubleshooting30 minIn writing
- 38Structural typing means a `UserId` string and an `OrderId` string are interchangeable. How do you make the compiler tell them apart?Advanceddesign45 minIn writing
- 39A function expecting a `Logger` silently accepted an unrelated object that happened to have a `log` method, and it shipped. How would you design the type so that cannot happen again?Scenarioscenario45 minIn writing
- 40Quiz: interface versus alias, declaration merging, excess property checks, and branded types.Basicconceptual20 minIn writing
- 41What can you do with a value typed as a union before you narrow it, and why is that restriction the correct behaviour?Basicconceptual30 minIn writing
- 42How do literal types turn a `string` parameter into a closed set of allowed values, and how does that compare with an enum?Basicconceptual30 minIn writing
- 43What does intersecting two object types actually produce, and what happens when both declare the same property with incompatible types?Intermediateconceptual35 minIn writing
- 44What does it mean for a type operation to distribute over a union, and when does that behaviour surprise people?Advancedconceptual45 minIn writing
- 45How would you model a value that is either loading, loaded with data, or failed, and why not one interface with three optional fields?Intermediatedesign40 minIn writing
- 46Why can't you read a property that exists on only some members of a union, even when you are certain which member you hold?Intermediatetroubleshooting35 minIn writing
- 47A form component accepts either a `value`/`onChange` pair or a `defaultValue`, never both. How do you make the compiler enforce that at the call site?Scenarioscenario45 minIn writing
- 48Quiz: union member access rules, literal types, intersections, and distribution.Basicconceptual20 minIn writing
- 49How does TypeScript narrow a type through an `if`, and which kinds of check does control-flow analysis understand?Basicconceptual35 minIn writing
- 50Compare `typeof`, `instanceof`, and the `in` operator as narrowing tools. Where does each one let you down?Intermediatepractical35 minIn writing
- 51How do you write a `value is Thing` type predicate, and what exactly is the compiler trusting you about when you do?Intermediatepractical40 minIn writing
- 52What is an assertion function (`asserts x is T`), and why does it require an explicit return type annotation to work?Advancedpractical40 minIn writing
- 53How would you model a set of related but distinct API response shapes so the compiler forces you to handle every case, including a new one added later?Advanceddesign5 min
- 54Your narrowing works, then a callback or an `await` in the middle of the block loses it. Why does the compiler widen the type back?Intermediatetroubleshooting40 minIn writing
- 55A code review flags `if (typeof x === 'object')` as a bug magnet. Explain what is wrong with it and what you would write instead.Scenarioscenario45 minIn writing
- 56Quiz: control-flow narrowing, type predicates, assertion functions, and exhaustiveness checks.Basicconceptual20 minIn writing
- 57How do you type a function value, and what does TypeScript do about optional, default, and rest parameters?Basicconceptual30 minIn writing
- 58When is a set of overload signatures the right tool, and why does the implementation signature not participate in call resolution?Intermediatepractical40 minIn writing
- 59Overloads, or a union parameter plus narrowing: how do you decide between them, and which is friendlier to callers?Intermediatedesign35 minIn writing
- 60How do you type `this` inside a function, and what does a `this` parameter give you that an arrow function cannot?Advancedpractical40 minIn writing
- 61Why does TypeScript accept a callback whose parameter type is narrower than the one declared, and what does strictFunctionTypes change?Advancedconceptual45 minIn writing
- 62Should you annotate function return types or let them be inferred? Make the case both ways, for a published library and for an application.Intermediatepractical30 minIn writing
- 63An overloaded helper compiles cleanly but throws at runtime for one specific argument combination. How can overloads produce that, and how would you prevent it?Scenarioscenario45 minIn writing
- 64Quiz: function types, overload resolution order, this parameters, and parameter variance.Basicconceptual20 minIn writing
- 65What problem do generics solve that a union or `unknown` does not, and when is adding a type parameter pointless?Basicconceptual35 minIn writing
- 66How does TypeScript infer generic type parameters from function arguments, and when do you need to supply them explicitly?Intermediatepractical5 min
- 67How do `extends` constraints on a type parameter work, and how would you write a function that accepts any object carrying a given key?Intermediatepractical40 minIn writing
- 68What do default type parameters buy you, and how do they interact with inference at the call site?Intermediatepractical30 minIn writing
- 69How do `keyof` and indexed access types let you write a type-safe `get(obj, key)` helper?Intermediatepractical40 minIn writing
- 70How would you design a generic repository or cache interface without forcing every call site to pass three type arguments?Intermediatedesign45 minIn writing
- 71A teammate's generic utility has five type parameters and every call site passes all of them explicitly. Diagnose what went wrong and describe how you would simplify it.Scenarioscenario50 minIn writing
- 72Quiz: inference sites, constraints, defaults, keyof, and when a generic is overkill.Basicconceptual20 minIn writing
- 73Walk me through Partial, Required, Readonly, Pick, Omit, and Record. What is each one for, and where does each disappoint you?Basicconceptual40 minIn writing
- 74How does a mapped type work, and how would you write `Partial<T>` yourself from scratch?Intermediatepractical40 minIn writing
- 75How do the `+` and `-` modifiers on `readonly` and `?` work inside a mapped type, and how would you write a `Mutable<T>`?Advancedpractical40 minIn writing
- 76How would you write a recursive `DeepPartial<T>`, and what should it do about arrays, functions, and Dates?Advanceddesign50 minIn writing
- 77Why does `Omit` silently accept a key that does not exist on the type, and how would you make a strict version?Intermediatetroubleshooting35 minIn writing
- 78You have a database row type and an API response type that are ninety percent identical. How do you relate them without copy-pasting fields?Intermediatedesign40 minIn writing
- 79A refactor renamed a field on a core model and the compiler flagged forty files, except three that broke in production instead. What kind of type duplication allows that?Scenarioscenario45 minIn writing
- 80Quiz: built-in utility types, mapped type syntax, property modifiers, and Omit's weak spot.Basicconceptual20 minIn writing
- 81How does `T extends U ? X : Y` evaluate, and what makes a conditional type 'deferred' rather than resolved?Intermediateconceptual40 minIn writing
- 82What does `infer` do, and how would you implement your own `ReturnType<T>` with it?Advancedpractical45 minIn writing
- 83Why does a conditional type over a union get applied per member, and how do you switch that behaviour off deliberately?Advancedconceptual45 minIn writing
- 84How do template literal types work, and how would you type an event emitter whose handler names are `on${Capitalize<EventName>}`?Advancedpractical45 minIn writing
- 85How does `as` inside a mapped type let you rename or filter keys, and what would you build with it?Advancedpractical45 minIn writing
- 86Your types compile but the editor takes eight seconds to respond. What causes type-level performance problems, and how do you find and fix them?Advancedtroubleshooting45 minIn writing
- 87A clever conditional type in a shared package produces an unreadable error message whenever a caller gets it wrong. How do you improve that developer experience without giving up the safety?Scenarioscenario50 minIn writing
- 88Quiz: conditional evaluation, infer positions, distribution, and template literal types.Basicconceptual20 minIn writing
- 89What question is TypeScript actually answering when it reports 'Type A is not assignable to type B'?Basicconceptual35 minIn writing
- 90Why does `let x = 'red'` get the type `string` while `const x = 'red'` gets `'red'`, and how do you control that widening?Intermediateconceptual35 minIn writing
- 91Explain covariance and contravariance using arrays and function parameters, and give an example where TypeScript is deliberately unsound.Advancedconceptual50 minIn writing
- 92TypeScript lets you pass a `Dog[]` where an `Animal[]` is expected. Show how that can crash at runtime, and say why the team shipped it anyway.Advancedtroubleshooting45 minIn writing
- 93How do readonly arrays and `Readonly<T>` change assignability, and why does making a parameter readonly widen what callers may pass?Intermediatepractical40 minIn writing
- 94Why is a type with extra properties usually assignable while a type missing one never is, and when is that asymmetry wrong for your domain?Intermediatepractical35 minIn writing
- 95A mutation through a supertype-typed reference corrupted a typed array in production. Walk me through how the compiler allowed it and how you would prevent a repeat.Scenarioscenario50 minIn writing
- 96Quiz: assignability, literal widening, variance directions, and the known unsound spots.Basicconceptual20 minIn writing
- 97What is a `.d.ts` file, who writes it, and what are your options when an npm package ships none?Basicconceptual35 minIn writing
- 98How does TypeScript find the types for an import, and what do `moduleResolution` and `paths` change about that search?Intermediatetroubleshooting45 minIn writing
- 99Explain `esModuleInterop` and `allowSyntheticDefaultImports`. What breaks when a CommonJS package is imported from an ESM file?Intermediatetroubleshooting45 minIn writing
- 100How do you add types for a global, a non-code import such as a `.svg`, or an entirely untyped third-party module?Intermediatepractical40 minIn writing
- 101You are publishing a library. What does `declaration: true` emit, and what commonly makes a declaration file fail to generate?Advancedpractical45 minIn writing
- 102How do you extend a third-party library's types, such as adding a field to Express's `Request`, without forking the package?Advancedpractical45 minIn writing
- 103A package's shipped types claim a function returns `string`, but at runtime it sometimes returns null. What do you do, in order?Scenarioscenario45 minIn writing
- 104Quiz: declaration files, module resolution, interop flags, and module augmentation.Basicconceptual20 minIn writing
- 105Which tsconfig options actually change what your code means, and which only affect the emitted output?Basicconceptual35 minIn writing
- 106`strict: true` switches on a family of flags. Name them, and say which one causes the most churn on an existing codebase.Intermediateconceptual40 minIn writing
- 107What is the difference between `target`, `lib`, and a polyfill, and how does getting this wrong ship a runtime error?Intermediatepractical40 minIn writing
- 108What do project references and `composite` builds solve in a monorepo, and what do they cost you day to day?Advancedpractical45 minIn writing
- 109What does `noUncheckedIndexedAccess` change, and why do teams switch it on and then immediately switch it back off?Intermediatetroubleshooting35 minIn writing
- 110How would you wire type checking, linting, and incremental builds into CI so it is fast and impossible to bypass?Intermediatedesign40 minIn writing
- 111Type checking takes four minutes on every commit and developers have started sprinkling `// @ts-ignore` to get past it. What do you change first?Scenarioscenario50 minIn writing
- 112Quiz: the strict family, target versus lib, project references, and incremental builds.Basicconceptual20 minIn writing
- 113How do TypeScript's `public`, `private`, and `protected` differ from JavaScript's `#private` fields at runtime?Basicconceptual35 minIn writing
- 114What are parameter properties, as in `constructor(private readonly repo: Repo)`, and why do some teams avoid them?Intermediatepractical30 minIn writing
- 115When do you use an abstract class rather than an interface, given that structural typing makes `implements` largely a comment?Intermediatedesign40 minIn writing
- 116How do you type a static factory or a constructor signature so a function can accept 'a class that produces T'?Advancedpractical45 minIn writing
- 117What do the TC39 standard decorators do, and how do they differ from the older `experimentalDecorators` implementation?Intermediateconceptual45 minIn writing
- 118Frameworks like NestJS and TypeORM read types at runtime through decorators. How does that work given type erasure, and what are its limits?Advanceddesign50 minIn writing
- 119A `private` field was read from outside its class by plain JavaScript at runtime and nothing complained. Explain how, and what you would change if that actually matters.Scenarioscenario45 minIn writing
- 120Quiz: access modifiers, parameter properties, abstract classes, and decorator behaviour.Basicconceptual20 minIn writing
- 121How do you type an async function, and why does `catch (e)` hand you `unknown` under modern strict settings?Intermediatepractical35 minIn writing
- 122What is the right way to type data arriving from an HTTP API, and why is `as ResponseType` the wrong answer?Intermediatedesign45 minIn writing
- 123How do you keep a runtime schema and a static type in sync without hand-writing both and letting them drift?Advanceddesign45 minIn writing
- 124How do you test that a type behaves as intended, and what does a type-level test catch that a unit test cannot?Advancedpractical45 minIn writing
- 125Describe a realistic plan for migrating a large JavaScript codebase to TypeScript without a big-bang rewrite.Advanceddesign60 minIn writing
- 126Capstone: model a subscription billing domain in TypeScript, covering plans, subscriptions, invoices, and every transition between their states, so that an invalid state is unrepresentable and every state change is exhaustively handled. Present your types and defend the trade-offs you made.Scenariodesign240 minIn writing
- 127Your service is fully strict-typed and still had three shape-mismatch incidents this quarter, all at integration points. Where do you invest next, and why there?Scenarioscenario50 minIn writing
- 128Quiz: async typing, boundary validation, type-level tests, and migration strategy.Basicconceptual20 minIn writing