DEV Community

Rogério Rodrigues de Alcântara
Rogério Rodrigues de Alcântara

Posted on

Types Aliases and Interface are tricky..

type BirdType = {
  wings: 2;
};

interface BirdInterface {
  wings: 2;
}
Enter fullscreen mode Exit fullscreen mode
  • Both declare the shape of an object
  • Both support extending other interfaces and types
  • It's possible to intermix their use
  • Interfaces are open whereas type aliases are closed
  • Typescript gives better error messages for interfaces
  • Prefer interfaces for publicly exposed types

Sources:

Top comments (0)