TypeScriptTips

Make bugs impossible.
One TypeScript tip at a time.

I like the tricks :) – Kasia

Type-level functions

Generics are just functions (at the type level).

const shout = (str: string) => `${str}!`
const shouted = shout("yeah")
// shouted = "yeah!"

type Shout<Str extends string> = `${Str}!`
type Shouted = Shout<"yeah">
//   ^? type Shouted = "yeah!"