TypeScriptTips

Make bugs impossible.
One TypeScript tip at a time.

I like the tricks :) – Kasia

Pass arguments by name

Using an object instead of passing positional arguments can help prevent subtle bugs.

const pay = (amount: number, discount: number) => {}

pay(discount, amount) // ⛔️
const pay =
  ({ amount, discount }: { amount: number, discount: number }) => {}

pay(discount, amount) // ✅ Does not compile