TypeScriptTips

Make bugs impossible.
One TypeScript tip at a time.

I like the tricks :) – Kasia

Expand intellisense

@BeralivSuggest a tip

You can debug a static type by forcing the resolution of type aliases with a utility type.

type Persisted = { id: number }
type User = { name: string }
type PersistedUser = Persisted & User
// ⛔️ ^? Persisted & User
type Persisted = { id: number }
type User = { name: string }
type PersistedUser = Persisted & User

type Expand<Type> = { [Key in keyof Type]: Type[Key] }
type Expanded = Expand<PersistedUser>
// ✅ ^? { id: number, name: string }