factory function
A function whose job is to create and return new objects, often choosing or configuring the class to use.
In more detail
A generic factory typed with InstanceType returns exactly the type of the class it was given. Factories that start from nothing often need an explicit type argument.
Related terms
- InstanceType<T> — The utility type that gives the type of object produced by calling new on class type T.
- dependency injection — Giving an object the collaborators it needs from outside, usually through its constructor, instead of letting it create or look them up itself.
Taught in
- Why Generics: Functions, Identities And Type Variables — Production TypeScript
- Function Utilities: ReturnType, Parameters And Constructor — Production TypeScript