typestar

Generics

20 steps in 4 sets of TypeScript.

Type parameters, and then the part people skip: reading types rather than only writing them. keyof, typeof, indexed access, and the inference rules that mean most code needs no annotations at all.

Generic helper types close it. Twenty steps, and this is where TypeScript stops feeling like annotations on JavaScript and starts feeling like a language of its own.

Start this tour

Type parameters

  • GenericsFunctions and types that work over any type.
  • Constraints and defaultsA type parameter can be bounded, and can have a default.
  • InferenceWhere TypeScript works the type out, and how to help it.
  • VarianceWhere a subtype is accepted, and the annotations that say so.

Reading types

Generic helpers

Encore

  • inventory.tsA complete inventory script: typed records in, grouped and totaled report out.

The other TypeScript tours