Logo

BLOG

Read thoughts on software development, design, and engineering.

⌘K
Loading posts…

Popular Articles

Type Assertions and Type CastingTypeScript13 min read

Type Assertions and Type Casting

Type assertions tell TypeScript to trust your judgment about a value's type. While they're powerful tools for working with DOM elements, API responses, and type narrowing, they can also bypass type safety if misused. This guide covers the as syntax, angle-bracket syntax, when to use assertions safely, and the crucial difference between TypeScript assertions and runtime type casting. Learn to wield this tool responsibly while maintaining type safety in your applications.

#TypeScript#Type Assertions#Type Casting+3
Read article
The any, unknown, and never TypesTypeScript15 min read

The any, unknown, and never Types

TypeScript has three special types that handle edge cases: any (the escape hatch), unknown (the type-safe alternative), and never (for impossible values). Understanding when and how to use these types is crucial for writing safe yet flexible TypeScript code. This guide covers the differences between these types, shows you how to work with unknown safely, and demonstrates how never enables exhaustive type checking and prevents runtime errors. Learn to use these types effectively while maintaining type safety.

#TypeScript#Type System#any type+4
Read article
Enums: When and How to Use ThemTypeScript11 min read

Enums: When and How to Use Them

Enums provide a way to define named constants in TypeScript, making your code more readable and maintainable. Whether you're working with status codes, user roles, or application states, enums help organize related values under a single type. This guide covers numeric enums, string enums, const enums, and most importantly—when to use enums versus alternatives like union types and objects. Learn the patterns that will make your TypeScript code cleaner and more expressive.

#TypeScript#Enums#Type System+4
Read article
Blog — All posts | Joshua R. Lehman Portfolio Site | Joshua R. Lehman Portfolio