HomeAbout

Subset

Subset Type

Subset is NOT an official feature of Typescript, but is an encouraged pattern.

type Subset<T extends U, U> = U; interface Foo { name: string; age: number; } type Bar = Subset< Foo, { name: string; } >;

This makes sure that U is a subset of T and returns U as a new type.

  • You can not add new properties to Bar which are not part of Foo
  • You can not alter types in a non-compatible way.
    • This also works recursively on nested objects
AboutContact