TypeScriptTips

Make bugs impossible.
One TypeScript tip at a time.

I like the tricks :) – Kasia

Object vs Record

Object is prolly not the right type you want.

const aNaN: Object = NaN
// ⛔️ No type error

const a1: Object = 1
// ⛔️ No type error

const aObject: Object = { a: 1 }
// ✅ No type error
type Obj = Record<string, unknown>
// or
// type Obj = { [key: string]: unknown }

const aNaN: Obj = NaN
// ✅ Type error

const a1: Obj = 1
// ✅ Type error

const aObject: Obj = { a: 1 }
// ✅ No type error