TypeScript Tutorial #15: Error Handling Patterns

In the previous tutorial, we learned about template literal types. Now let’s learn about error handling — one of the most important topics in any real application. By the end of this tutorial, you will know how to safely narrow the unknown error in catch blocks, create custom error classes, implement the Result type pattern, and follow best practices for error handling in TypeScript. Why catch Gives You unknown, Not a Typed Value You cannot write catch (error: SomeType) in TypeScript. There is no such syntax. The language does not allow you to annotate the catch parameter with a specific type. ...

May 8, 2026 · 7 min

TypeScript Tutorial #14: Template Literal Types

In the previous tutorial, we learned about mapped types and conditional types. Now let’s learn about template literal types — a way to create type-safe string patterns. By the end of this tutorial, you will know how to use template literal types, built-in string manipulation types, and practical patterns for events, APIs, and CSS. What Are Template Literal Types? Template literal types use the same backtick syntax as JavaScript template literals, but at the type level: ...

May 7, 2026 · 6 min

TypeScript Tutorial #13: Mapped Types and Conditional Types

In the previous tutorial, we learned about built-in utility types. Now let’s learn how those utility types are built — using mapped types and conditional types. By the end of this tutorial, you will know how to transform object types, extract types with infer, and build your own custom utility types. What Are Mapped Types? A mapped type creates a new type by transforming every property of an existing type. It loops over each key and applies a transformation. ...

May 7, 2026 · 6 min

TypeScript Tutorial #12: Utility Types

In the previous tutorial, we learned about modules and namespaces. Now let’s learn about utility types — built-in types that transform other types. TypeScript includes many utility types out of the box. They save you from writing complex type logic yourself. By the end of this tutorial, you will know when and how to use each one. Why Utility Types? Imagine you have a User type: interface User { id: number; name: string; email: string; age: number; } Now you need a function that updates a user. But you want to allow partial updates — only some fields, not all. Without utility types, you would need to create a new type manually: ...

May 6, 2026 · 6 min

TypeScript Tutorial #11: Modules and Namespaces

In the previous tutorial, we learned about classes and access modifiers. Now let’s learn about modules — how TypeScript organizes code across multiple files. By the end of this tutorial, you will know how to use import and export, type-only imports, declaration files, path aliases, and third-party type packages. What Are Modules? A module is a file that exports values, functions, types, or classes. Other files can import what they need. This keeps your code organized and avoids name conflicts. ...

May 6, 2026 · 8 min

TypeScript Tutorial #10: Classes and Access Modifiers

In the previous tutorial, we learned about generics. Now let’s learn about classes in TypeScript — how they work, what access modifiers do, and when you should use them. By the end of this tutorial, you will know how to use public, private, protected, readonly, abstract classes, parameter properties, and how to implement interfaces with classes. Basic Classes A class defines a blueprint for objects. TypeScript adds type annotations to JavaScript classes: ...

May 5, 2026 · 9 min

TypeScript Tutorial #9: Generics

In the previous tutorial, we learned about type narrowing and type guards. Now let’s learn about generics — one of the most powerful features in TypeScript. By the end of this tutorial, you will know how to write generic functions, interfaces, and constraints. You will also learn common patterns like keyof, default type parameters, and generic utility functions. Why Generics? Imagine you need a function that returns the first element of any array: ...

May 5, 2026 · 8 min

TypeScript Tutorial #8: Type Narrowing and Type Guards

In the previous tutorial, we learned about enums and const assertions. Now let’s learn about type narrowing — one of the most important concepts in TypeScript. By the end of this tutorial, you will know how to use typeof, instanceof, custom type guards, discriminated unions with switch, and exhaustive checking with never. What is Type Narrowing? Type narrowing means making a type more specific within a block of code. When you have a union type like string | number, TypeScript can figure out the exact type based on your checks. ...

May 5, 2026 · 8 min

TypeScript Tutorial #7: Enums and Const Assertions

In the previous tutorial, we learned about union types and literal types. Now let’s learn about enums and const assertions — two ways to define a fixed set of values in TypeScript. By the end of this tutorial, you will know when to use enums, when to use as const, and how the satisfies operator works. What is an Enum? An enum (enumeration) is a way to define a group of named constants. TypeScript has three kinds: numeric enums, string enums, and const enums. ...

May 4, 2026 · 8 min

TypeScript Tutorial #6: Union Types, Literal Types, and Type Aliases

In the previous tutorial, we learned about objects and interfaces. Now let’s learn about union types, literal types, and type aliases — patterns that make TypeScript truly powerful. By the end of this tutorial, you will know how to use union types, literal types, discriminated unions, intersection types, and type aliases. Union Types A union type means “this value can be one of several types.” Use the | (pipe) symbol: let id: string | number; id = "abc-123"; // OK — string id = 42; // OK — number id = true; // Error: Type 'boolean' is not assignable to type 'string | number' Union types are everywhere in real code. A function that accepts multiple types: ...

May 4, 2026 · 7 min