Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
Algebraic Data Types: Product and Sum Types, Discriminated Unions and Making Illegal States Unrepresentable
Algebraic data types combine types with "and" (product types) or "or" (sum types) so that the number of combinations in the model equals the number of states in the business rule, making impossible states impossible to build. We turn Bookstore's flagged order status into a sum type with abstract records, write transitions with types, and show why C# 14 wants a _ arm, TypeScript discriminated unions, JSON polymorphism and C# 15 union types with real compiler output.
Error Handling in TypeScript: unknown in catch, Narrowing Errors and the Result Pattern
We look at why the catch variable is unknown, narrowing with instanceof Error, custom error classes, Promise pitfalls, and modeling errors with Result and discriminated unions.
Narrowing in TypeScript: Shrinking Unions with Control Flow Analysis
We see how TypeScript narrows unions through control flow analysis: typeof, truthiness, equality, in and instanceof checks, discriminated unions and exhaustive checks with never.