TypeScript
Use "good" TypeScript practices:
assign a type when declaring variables (if type is not already correctly inferred)
❌
const doc = {...} // no type; can have any fields/values
✅
const doc: TDoc = {...} // type = TDoc ({ id: number, ... })
narrow-scoped types when possible [1]
❌
type side = string
allows "left", "right", "askdjf", "jdklfjal", ...
✅
type side = "left" | "right"
allows "left" or "right" only
minimal-to-no
any
orunknown
types [1]❌
const item: any = {...}
❌
const item: unknown = {...}
Last updated