I like the tricks :) – Kasia
TypeScript employs a structural type system, so type aliases are just aliases.
type Dollars = number type Euros = number const twoDollars: Dollars = 2 const pay = (euros: Euros) => {} pay(twoDollars) // ⛔️
type Dollars = { _kind: 'dollars', amount: number } type Euros = { _kind: 'euros', amount: number } const twoDollars: Dollars = { _kind: 'dollars', amount: 2 } const pay = (euros: Euros) => {} pay(twoDollars) // ✅ Does not compile
Crafted with 💛 by Riccardo