metaprogramming
Writing code that works on other code or on types, such as decorators that modify classes or types computed from other types.
In more detail
Mapped types, conditional types and utility types are metaprogramming at the type level. Use it where it removes real duplication, since heavy type-level code is hard to read.
Related terms
- mapped type — A type that builds a new object type by looping over a set of keys, such as { [K in keyof T]: T[K] }.
- conditional type — A type that picks one of two types depending on whether a type is assignable to another, written like a ternary expression with extends.
- decorator — A line starting with @ placed above a function or class that wraps it to add behaviour or information.
Taught in
- Const Type Parameters: Retaining Literal Types In Functions — Production TypeScript
- Mapped Types, Key Remapping With as And Template Literals — Production TypeScript
- Modern Decorators: Stage 3 Standards And Class Metadata — Production TypeScript