You’ve finished Reusable Types: Generics, Utility Types and Typed Modules. You started with three volunteer scripts for the Riverside Kids’ Football League, each with its own copy of the league’s types, and the copies disagreed. You finished with one typed client that holds every type once and derives the rest.
What You Can Do Now
- Type classes and modules
- Keep to syntax that can be erased
- Write generic functions and types that keep the relation between inputs and outputs
- Derive types from one source with
keyof,typeofand utility types
How You Got There
- The results table became a class checked against an interface:
class ResultsTable implements TableSource. - The coach’s phone moved into a
#coachPhonefield, which JavaScript keeps private at run time, where TypeScript’sprivateis erased. - An enum gave way to an
as constobject and a literal union, which Node can strip. - A function type,
CompareRows, caught a comparator that returned abooleanwhere sorting needs anumber. - The league’s types got one module, imported with
import type. - A generic request kept the caller’s type, and one result type,
ApiResult<T>, wrapped every reply. - The age groups became one
as constlist that theAgeGrouptype comes from, with(typeof AGE_GROUPS)[number]. - Utility types derived the create and update types:
NewTeamisOmit<Team, "id">, andTeamUpdatebuilds onPartial.