Skip to content

Latest commit

 

History

History

exact

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Exact<Type, Shape> returns Type when type Type and Shape are identical. Otherwise returns never

interface Dog {
  name: string;
  bark: () => void;
}

interface Cat {
  name: string;
  meow: () => void;
}

type CatEqualsToDog = Exact<Cat, Dog>;
//   ^? never

type DogEqualsToDog = Exact<Dog, Dog>;
//   ^? Dog

It supports:

  • Arrays
  • Object types
  • Tuples
  • Union types with objects
  • Union types with primitives

It doesn't support:

  • Enums

Support is addressed in #342

TS Playground – https://tsplay.dev/Wo8dlw