Skip to Content
0 likes
Discriminated Unions for success and error Responses Level: Intermediate

Replace a data-or-error object with a union tagged by success, then add a generic Outcome and an unwrap helper. After this, the compiler knows which property exists in each case.

0 likes
Type JSON from fetch Without as MyType Everywhere Level: Intermediate

Replace scattered casts with one assertion function and one typed fetch helper. After this, a 404 or a changed payload fails with a clear message instead of carrying a wrong type.

0 likes
unknown First, Then Narrow: Parse an API Payload Level: Intermediate

Receive a nested payload as unknown and narrow it with two small helpers until every property is checked. After this, you can write a parser that rejects wrong data and returns a real type.

0 likes
Augment Express Request Without Fighting the Compiler Level: Advanced

Add a user property to the Express request type with a module augmentation in one declaration file. After this, middleware and handlers agree on the type and you avoid the mistake that floods node_modules with errors.

0 likes
Template Literal Types for /users/:id Routes Level: Advanced

Turn a route pattern into a type that finds the parameter names and checks the paths you pass. After this, a typo in a route or a missing parameter is a compile error.