Skip to content
CSCosmos
TSViz
Concepts
Problems
Playground
GitHub
Toggle theme
Loading...
TypeScript Problems
50 practice tasks to master TypeScript. Filter by difficulty or search by concept.
All
Easy
Medium
Hard
Strongly-type a user profile
Easy
Primitives & Objects
Define a typed object for a user with required and optional fields.
Safer unknown parsing
Easy
unknown & narrowing
Parse an unknown API payload and narrow it safely.
Union of statuses
Easy
Literal unions
Create a status union and reject invalid strings.
Tuple coordinates
Easy
Tuples
Model a 2D point and destructure it with labels.
Readonly config
Easy
Readonly & const assertions
Freeze a config object to prevent mutation.
Function overloads
Medium
Functions & overloads
Provide overloads for a formatter handling strings and numbers.
Discriminated response
Medium
Unions & guards
Model success/error API responses and handle them exhaustively.
Narrow with in/typeof
Medium
Type guards
Use in and typeof to safely access fields on a union.
Keyof picker
Medium
keyof & indexed access
Write a pick function constrained to existing keys.
Mapped readonly
Medium
Mapped types
Create a generic to deep-readonly an object.
Partial update
Easy
Utility types
Type a function that merges a partial update into an entity.
Record of handlers
Medium
Record & unions
Create a handler map keyed by event names.
Template literal routes
Medium
Template literal types
Constrain route strings to /users/:id patterns.
Infer Promise inner
Medium
Conditional + infer
Write a type to extract the resolved type of a Promise.
Async result type
Medium
Async/Await
Type an async function fetching users with rejection handling.
Exact optionals
Medium
tsconfig strict
Model optional props without allowing undefined assignments.
Branded IDs
Medium
Opaque/branded types
Create branded types to avoid mixing userId and orgId.
Array vs tuple params
Easy
Tuples & rest
Type a function that accepts a variadic tuple and returns the head.
Readonly arrays
Easy
Readonly collections
Prevent mutation of an array returned from a function.
Intersection composition
Medium
Intersections
Combine mixins while avoiding field conflicts.
Module interop
Medium
Modules/ESM/CJS
Type imports for a CommonJS module consumed in ESM.
Type-only imports
Easy
Modules
Refactor imports to use import type and reduce bundle impact.
Index signature safety
Medium
Index signatures
Add noUncheckedIndexedAccess-safe indexing to a map.
Form element assertion
Easy
Type assertions
Safely cast a queried element to HTMLFormElement with guards.
Distribute over union
Hard
Conditional types
Write a conditional type that distributes over union members.
Event map remap
Hard
Key remapping
Map keys to handler names using mapped types with as.
Zod-style infer
Hard
infer usage
Extract a runtime schema’s TS type using infer in conditionals.
Deep partial
Hard
Mapped types
Implement a DeepPartial utility respecting arrays/objects.
Promise queue
Medium
Async control
Type a queue that processes tasks sequentially with async handlers.
Abortable fetch wrapper
Medium
Async + AbortSignal
Type a wrapper that enforces AbortSignal usage.
Discriminated UI state
Easy
Unions
Model loading/success/error UI state and render branches.
Safe JSON parse
Medium
unknown & guards
Parse JSON into unknown then narrow to expected shape.
Readonly tuple labels
Easy
Tuples
Create a labeled readonly tuple for RGB values.
Function this typing
Hard
Functions & this
Type a method that relies on this, preserving context.
Overload vs union
Medium
Overloads vs unions
Refactor overloads into a union parameter design.
Mapper of DTOs
Medium
Mapped types
Transform an API response type into a view model type.
Keyof assertions
Medium
Type guards
Create a guard that asserts a string is a key of an object.
Mutable to immutable
Easy
Readonly utility
Convert a mutable object type to a readonly version.
Filter props
Hard
Mapped + Conditional
Create a type that picks only function properties from an object.
Pick by value type
Hard
Conditional + keyof
Pick keys whose values extend a given type.
Optional chaining safety
Easy
Strict null checks
Refactor code to satisfy strictNullChecks without !.
Tuple to union
Easy
Indexed access
Turn a readonly tuple of strings into a union type.
Variadic tuple append
Medium
Variadic tuples
Append an element to a tuple type preserving labels.
Awaited utility
Easy
Awaited<T>
Use Awaited to unwrap nested Promise types.
NonNullable pipeline
Medium
NonNullable
Ensure a pipeline output excludes null/undefined.
Readonly Map wrapper
Medium
Interfaces vs types
Expose a read-only view over a Map with iterators.
Ambient module typing
Medium
Ambient declarations
Type an untyped npm package via declare module.
Global augmentation
Medium
Declaration merging
Augment Window with a typed config object.
Error branding
Medium
Discriminated unions
Create typed errors with codes and narrow by code.
CLI args parser
Hard
Template literals + conditionals
Type a CLI flag parser with inferred output object.