Unknown Errors in TypeScript
Learn why catch clause variables are typed as unknown instead of any, how to safely narrow them, and how to handle the different kinds of values that can be thrown at runtime.
Type-safe JavaScript with TypeScript
Learn why catch clause variables are typed as unknown instead of any, how to safely narrow them, and how to handle the different kinds of values that can be thrown at runtime.
Learn how to create custom error classes that extend the built-in Error, add meaningful properties like status codes and field names, and use them with type-safe catch blocks.
Learn the Result pattern as an alternative to throwing errors. Model success and failure as plain values so the compiler forces you to handle both cases.
TypeScript types disappear at runtime. Learn how to validate data as it enters your application using type guards, assertion functions, and validation libraries to bridge the gap between compile-time types and runtime reality.
JSON.parse returns any, which bypasses TypeScript's type checking. Learn how to parse JSON safely by combining runtime validation with typed parsing so you never trust raw data from a string.
API responses arrive as unknown data at runtime. Learn how to validate API responses in TypeScript with type guards, Zod schemas, and a practical fetch wrapper that guarantees type safety.
Zod is a TypeScript-first schema validation library. Learn how to define schemas, infer types, parse data safely, and handle validation errors so you never trust unvalidated data.
Compare two ways to handle errors in TypeScript: throwing exceptions and returning Result types. Learn when each approach works best and how to combine them in real applications.
Parameters<T> extracts the parameter types of a function as a tuple. Use it to reuse parameter types without duplicating them.
A mapped type iterates over a union of keys and produces a new object type. Use it to transform every property of a type in one declaration.
Key remapping with the as clause lets you rename keys in a mapped type. Use it to prefix, suffix, or transform property names based on their original values.
Template literal types construct new string literal types at the type level, just like template literals build strings at runtime. Use them for string pattern matching and type-safe APIs.