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