Practice / ts

TypeScript practice

Every TypeScript exercise, built from a topic you can open beside it.

76 exercises runs offline
ts Quiz new Which conditional tests whether a union T as a whole is assignable to U? Compose conditional, mapped, indexed-access, template-literal, and recursive types without confusing compile-time guarantees with runtime checks. advanced 1 min · from Advanced types ts Quiz new Why does { [K in keyof M]: { type: K; payload: M[K] } }[keyof M] preserve an event name-p… Compose conditional, mapped, indexed-access, template-literal, and recursive types without confusing compile-time guarantees with runtime checks. advanced 1 min · from Advanced types ts Predict the output new What does this program print? Compose conditional, mapped, indexed-access, template-literal, and recursive types without confusing compile-time guarantees with runtime checks. intermediate 2 min · from Advanced types ts Review AI code new Review a generated event router Compose conditional, mapped, indexed-access, template-literal, and recursive types without confusing compile-time guarantees with runtime checks. advanced 6 min · from Advanced types ts Spot the bug new Spot the bug in DeepReadonly Compose conditional, mapped, indexed-access, template-literal, and recursive types without confusing compile-time guarantees with runtime checks. advanced 4 min · from Advanced types ts Quiz new What does value as Account do at runtime? Understand how TypeScript describes JavaScript values, infers and narrows types, and stops at runtime data boundaries. beginner 1 min · from Basic types ts Predict the output new What does this program print? Understand how TypeScript describes JavaScript values, infers and narrows types, and stops at runtime data boundaries. beginner 2 min · from Basic types ts Review AI code new Review a generated admin ID filter Understand how TypeScript describes JavaScript values, infers and narrows types, and stops at runtime data boundaries. intermediate 10 min · from Basic types ts Spot the bug new Spot the bug in firstLabel Understand how TypeScript describes JavaScript values, infers and narrows types, and stops at runtime data boundaries. beginner 4 min · from Basic types ts Quiz new Why is unknown safer than any for an untrusted JSON result? Understand how TypeScript describes JavaScript values, infers and narrows types, and stops at runtime data boundaries. beginner 1 min · from Basic types ts Quiz new Given a correctly constructed UserId brand over number, which assignment is safe without … Distinguish structurally identical values and connect runtime validation, assertions, and trust boundaries in an auditable contract. intermediate 1 min · from Branded types ts Quiz new Why should addUsd(a, b) call the UsdCents constructor on a + b? Distinguish structurally identical values and connect runtime validation, assertions, and trust boundaries in an auditable contract. advanced 1 min · from Branded types ts Predict the output new What does this program print? Distinguish structurally identical values and connect runtime validation, assertions, and trust boundaries in an auditable contract. intermediate 2 min · from Branded types ts Review AI code new Review a generated transfer boundary Distinguish structurally identical values and connect runtime validation, assertions, and trust boundaries in an auditable contract. advanced 6 min · from Branded types ts Spot the bug new Spot the bug in the UserId predicate Distinguish structurally identical values and connect runtime validation, assertions, and trust boundaries in an auditable contract. advanced 4 min · from Branded types ts Quiz new What does declare function loadConfig(): Config do in a declaration file? Declaration files give existing JavaScript APIs static types; learn module boundaries, resolution, declaration emit, and tests that keep types honest. beginner 1 min · from Declaration files ts Quiz new A package exports both "." and "./reports". What must its declarations cover? Declaration files give existing JavaScript APIs static types; learn module boundaries, resolution, declaration emit, and tests that keep types honest. intermediate 1 min · from Declaration files ts Predict the output new What does this program print after TypeScript erases its type-only declarations? Declaration files give existing JavaScript APIs static types; learn module boundaries, resolution, declaration emit, and tests that keep types honest. beginner 2 min · from Declaration files ts Review AI code new Review a generated payment declaration Declaration files give existing JavaScript APIs static types; learn module boundaries, resolution, declaration emit, and tests that keep types honest. advanced 6 min · from Declaration files ts Spot the bug new Spot the bug in the Session declaration Declaration files give existing JavaScript APIs static types; learn module boundaries, resolution, declaration emit, and tests that keep types honest. intermediate 4 min · from Declaration files ts Quiz new Which type expression produces the source member names of an enum E? Enums bring named constants into both the type system and runtime; learn their output, validation boundaries, and alternatives. intermediate 2 min · from Enums ts Predict the output new What does this program print? Enums bring named constants into both the type system and runtime; learn their output, validation boundaries, and alternatives. beginner 2 min · from Enums ts Review AI code new Review a generated session helper Enums bring named constants into both the type system and runtime; learn their output, validation boundaries, and alternatives. advanced 10 min · from Enums ts Spot the bug new Spot the bug in State parsing Enums bring named constants into both the type system and runtime; learn their output, validation boundaries, and alternatives. intermediate 4 min · from Enums ts Quiz new Given enum Role { Admin = "ADMIN" }, which assignment type-checks without an assertion? Enums bring named constants into both the type system and runtime; learn their output, validation boundaries, and alternatives. beginner 2 min · from Enums ts Quiz new What does T extends { id: string } guarantee inside a generic function? Use type parameters to preserve relationships across inputs, outputs, and containers without claiming more than runtime code proves. intermediate 1 min · from Generics ts Predict the output new What does this program print? Use type parameters to preserve relationships across inputs, outputs, and containers without claiming more than runtime code proves. beginner 2 min · from Generics ts Quiz new What useful fact does <T>(value: T) => T express that (value: any) => any does not? Use type parameters to preserve relationships across inputs, outputs, and containers without claiming more than runtime code proves. beginner 1 min · from Generics ts Review AI code new Review generated entity index Use type parameters to preserve relationships across inputs, outputs, and containers without claiming more than runtime code proves. advanced 6 min · from Generics ts Spot the bug new Spot the bug in the generic JSON decoder Use type parameters to preserve relationships across inputs, outputs, and containers without claiming more than runtime code proves. intermediate 4 min · from Generics ts Quiz new What constraint does the type "auto" | string impose? Model closed states with exact values, and understand widening, as const, satisfies, discriminated unions, and runtime validation. intermediate 2 min · from Literal types ts Quiz new What is the usual inferred type of request.method in const request = { method: "GET" }? Model closed states with exact values, and understand widening, as const, satisfies, discriminated unions, and runtime validation. beginner 2 min · from Literal types ts Predict the output new What does this program print? Model closed states with exact values, and understand widening, as const, satisfies, discriminated unions, and runtime validation. beginner 3 min · from Literal types ts Review AI code new Review generated job event parser Model closed states with exact values, and understand widening, as const, satisfies, discriminated unions, and runtime validation. advanced 12 min · from Literal types ts Quiz new What is the main effect of const cfg = { retry: 3 } satisfies { retry: 0 | 1 | 2 | 3 }? Model closed states with exact values, and understand widening, as const, satisfies, discriminated unions, and runtime validation. intermediate 3 min · from Literal types ts Spot the bug new Spot the bug in Mode parsing Model closed states with exact values, and understand widening, as const, satisfies, discriminated unions, and runtime validation. intermediate 5 min · from Literal types ts Quiz new Under TypeScript 6 strict checking, which statement about this declaration is correct? Check that expressions meet TypeScript contracts without discarding useful inference, and avoid mistaking the check for runtime validation. intermediate 1 min · from satisfies operator ts Quiz new Why is JSON.parse(raw) satisfies Settings not runtime validation? Check that expressions meet TypeScript contracts without discarding useful inference, and avoid mistaking the check for runtime validation. intermediate 1 min · from satisfies operator ts Predict the output new What does this program print? Check that expressions meet TypeScript contracts without discarding useful inference, and avoid mistaking the check for runtime validation. beginner 2 min · from satisfies operator ts Review AI code new Review generated job registry Check that expressions meet TypeScript contracts without discarding useful inference, and avoid mistaking the check for runtime validation. advanced 6 min · from satisfies operator ts Spot the bug new Spot the bug in the command registry Check that expressions meet TypeScript contracts without discarding useful inference, and avoid mistaking the check for runtime validation. intermediate 4 min · from satisfies operator ts Quiz new With strictFunctionTypes, which assignment is safe for function-property callbacks? Strict mode exposes unsafe assumptions about nulls, callbacks, class fields, iterators, and untyped code before JavaScript runs. intermediate 1 min · from Strict mode ts Predict the output new What does this strict TypeScript program print? Strict mode exposes unsafe assumptions about nulls, callbacks, class fields, iterators, and untyped code before JavaScript runs. beginner 2 min · from Strict mode ts Review AI code new Review generated job runner Strict mode exposes unsafe assumptions about nulls, callbacks, class fields, iterators, and untyped code before JavaScript runs. advanced 6 min · from Strict mode ts Spot the bug new Spot the bug in Client settings Strict mode exposes unsafe assumptions about nulls, callbacks, class fields, iterators, and untyped code before JavaScript runs. intermediate 4 min · from Strict mode ts Quiz new Which option is not enabled by strict: true in TypeScript 6? Strict mode exposes unsafe assumptions about nulls, callbacks, class fields, iterators, and untyped code before JavaScript runs. intermediate 1 min · from Strict mode ts Quiz new Which comparison provides a meaningful type-coverage regression signal? Type coverage measures identifiers that escape to any; learn its limits, strict counting, boundary validation, and stable CI gates. intermediate 1 min · from Type coverage ts Predict the output new What does this program print when JSON.parse returns any? Type coverage measures identifiers that escape to any; learn its limits, strict counting, boundary validation, and stable CI gates. beginner 2 min · from Type coverage ts Review AI code new Review generated type coverage runner Type coverage measures identifiers that escape to any; learn its limits, strict counting, boundary validation, and stable CI gates. advanced 6 min · from Type coverage ts Spot the bug new Spot the bug in profile formatting Type coverage measures identifiers that escape to any; learn its limits, strict counting, boundary validation, and stable CI gates. intermediate 4 min · from Type coverage ts Quiz new How does type-coverage treat a value explicitly typed as unknown? Type coverage measures identifiers that escape to any; learn its limits, strict counting, boundary validation, and stable CI gates. intermediate 1 min · from Type coverage ts Quiz new After checking "id" in value on a non-null object, what has been proved? Narrow unions and unknown values with runtime evidence, then write trustworthy custom predicates and assertion functions. intermediate 1 min · from Type guards ts Quiz new Why is declaring isSmallNumber(value): value is number unsafe when it returns false for n… Narrow unions and unknown values with runtime evidence, then write trustworthy custom predicates and assertion functions. advanced 1 min · from Type guards ts Predict the output new What does this program print? Narrow unions and unknown values with runtime evidence, then write trustworthy custom predicates and assertion functions. beginner 2 min · from Type guards ts Review AI code new Review generated webhook guard Narrow unions and unknown values with runtime evidence, then write trustworthy custom predicates and assertion functions. advanced 6 min · from Type guards ts Spot the bug new Spot the bug in the Profile guard Narrow unions and unknown values with runtime evidence, then write trustworthy custom predicates and assertion functions. intermediate 4 min · from Type guards ts Quiz new Why can extracting an inline map callback into const render = (item) => item.name introdu… Understand how TypeScript infers types from initializers, context, and generic arguments, and where explicit contracts keep that inference honest. intermediate 3 min · from Type inference ts Quiz new What is the usual inferred type of config.mode in const config = { mode: "safe" }? Understand how TypeScript infers types from initializers, context, and generic arguments, and where explicit contracts keep that inference honest. beginner 2 min · from Type inference ts Predict the output new What does this program print? Understand how TypeScript infers types from initializers, context, and generic arguments, and where explicit contracts keep that inference honest. beginner 3 min · from Type inference ts Review AI code new Review generated invoice summary Understand how TypeScript infers types from initializers, context, and generic arguments, and where explicit contracts keep that inference honest. advanced 12 min · from Type inference ts Spot the bug new Spot the bug in the event handler Understand how TypeScript infers types from initializers, context, and generic arguments, and where explicit contracts keep that inference honest. intermediate 5 min · from Type inference ts Quiz new A variable is declared as string | number and currently narrowed to string. Why may a lat… How TypeScript narrows unions and unknown through control flow, with exhaustive branches, honest predicates, and stable local bindings. intermediate 3 min · from Type narrowing ts Quiz new Why pass a switch default value to assertNever instead of returning "unknown"? How TypeScript narrows unions and unknown through control flow, with exhaustive branches, honest predicates, and stable local bindings. intermediate 3 min · from Type narrowing ts Predict the output new What does this program print? How TypeScript narrows unions and unknown through control flow, with exhaustive branches, honest predicates, and stable local bindings. beginner 3 min · from Type narrowing ts Review AI code new Review generated job update decoder How TypeScript narrows unions and unknown through control flow, with exhaustive branches, honest predicates, and stable local bindings. advanced 12 min · from Type narrowing ts Spot the bug new Spot the bug in the Invoice predicate How TypeScript narrows unions and unknown through control flow, with exhaustive branches, honest predicates, and stable local bindings. intermediate 5 min · from Type narrowing ts Quiz new What runtime effect does declaring type Combined = A & B have? Model alternatives with unions, combine constraints with intersections, and keep compositions safe through narrowing, discriminants, and never checks. beginner 3 min · from Union and intersection types ts Predict the output new What does this program print? Model alternatives with unions, combine constraints with intersections, and keep compositions safe through narrowing, discriminants, and never checks. beginner 3 min · from Union and intersection types ts Review AI code new Review a generated API result renderer Model alternatives with unions, combine constraints with intersections, and keep compositions safe through narrowing, discriminants, and never checks. advanced 12 min · from Union and intersection types ts Spot the bug new Spot the bug in ImportedUser Model alternatives with unions, combine constraints with intersections, and keep compositions safe through narrowing, discriminants, and never checks. intermediate 5 min · from Union and intersection types ts Quiz new Which statement about an object union A | B is correct under structural typing? Model alternatives with unions, combine constraints with intersections, and keep compositions safe through narrowing, discriminants, and never checks. intermediate 3 min · from Union and intersection types ts Quiz new Why enable exactOptionalPropertyTypes for a patch type built with Partial? Derive contracts with Partial, Pick, Omit, Record, and function utilities without confusing shallow types for runtime behavior. intermediate 4 min · from Utility types ts Quiz new A function returns an existing Account object under the type Omit<Account, "passwordHash"… Derive contracts with Partial, Pick, Omit, Record, and function utilities without confusing shallow types for runtime behavior. intermediate 3 min · from Utility types ts Predict the output new What does this program print? Derive contracts with Partial, Pick, Omit, Record, and function utilities without confusing shallow types for runtime behavior. beginner 3 min · from Utility types ts Review AI code new Review a generated account update boundary Derive contracts with Partial, Pick, Omit, Record, and function utilities without confusing shallow types for runtime behavior. advanced 12 min · from Utility types ts Spot the bug new Spot the bug in PublicAccount Derive contracts with Partial, Pick, Omit, Record, and function utilities without confusing shallow types for runtime behavior. intermediate 5 min · from Utility types