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 or unknown types [1]

    • ❌ const item: any = {...}

    • ❌ const item: unknown = {...}

  • minimal "type casting" / "type assertions" [1][2][3]

    • ❌ const item = {...} as TypeX

Last updated