extends
A keyword with three jobs in TypeScript: a class inheriting from another, a limit on a generic type parameter, and a tsconfig.json inheriting a base file.
In more detail
class HttpError extends Error makes a subclass. In generics, K extends keyof T means K must be one of T's keys, and in a conditional type T extends U ? X : Y asks whether T is assignable to U. In tsconfig.json, "extends" loads another configuration file and lets you override parts of it.
Related terms
- generic constraint — A rule on a type parameter that limits which types may fill it, such as requiring a class, a particular interface or a certain shape.
- 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.
- class — A blueprint in code that bundles data and the functions that work on it, from which objects are made.
- tsconfig.json — The configuration file that tells the TypeScript compiler which files to check and how strict to be.
Taught in
- tsconfig.json: target, lib, strict And NodeNext — Production TypeScript
- The in Operator And Instanceof Narrowing — Production TypeScript
- Generic Interfaces, Classes And Type Aliases — Production TypeScript
- Generic Constraints: extends, keyof And Indexed Access — Production TypeScript
- Const Type Parameters: Retaining Literal Types In Functions — Production TypeScript
- Function Utilities: ReturnType, Parameters And Constructor — Production TypeScript
- Conditional Types: Ternary Types And Type Inference With infer — Production TypeScript
- Modern Decorators: Stage 3 Standards And Class Metadata — Production TypeScript