TypeScriptTips

Make bugs impossible.
One TypeScript tip at a time.

I like the tricks :) – Kasia

Zero null

Don't allow nulls if you can represent a "zero" with the base type.

type Balance = number | null
const balance = null // ⛔️ 0 would do it

type Transactions = number[] | null
const transactions = null // ⛔️ [] would do it
type Balance = number // ✅ null is invalid
type Transactions = number[] // ✅ null is invalid