extends

Expresses inheritance, generic constraints, and conditional type tests.

Since TS 1.0 Spec ↗

Syntax

interface A extends B / <T extends C> / T extends U ? X : Y

Examples

interface Base { id: number }
interface Item extends Base { name: string }

class Repo<T extends Base> {
  save(entity: T) {}
}
type IsString<T> = T extends string ? true : false;
type A = IsString<'x'>; // true

Notes

`extends` has three roles: interface or class inheritance, constraining a generic type parameter, and the assignability test in conditional types. In conditional types over a naked type parameter it distributes across union members.

See also