TypeScript
Last updated
Last updated
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
❌ type side = string
allows "left", "right", "askdjf", "jdklfjal", ...
✅ type side = "left" | "right"
allows "left" or "right" only
minimal-to-no any
or unknown
types
❌ const item: any = {...}
❌ const item: unknown = {...}
minimal "type casting" / "type assertions"
❌ const item = {...} as TypeX