DEV Community

German Escobar
German Escobar

Posted on

Types vs Interfaces in TypeScript

Even though there's a lot of information about this subject on the Internet, I haven't seen a single one mentioning that having two similar concepts was a mistake from the designers of the language.

Even though you can interchange types and interfaces in TypeScript most of the time, I will argue that unless you are going to implement an interface you should always use a type.

interface Configurable {
  configure(): void
}

class Task implements Configurable {
  configure(): void {
    // do some configuration
  }
}
Enter fullscreen mode Exit fullscreen mode

Remember that an interface is basically a contract, so they should include only method declarations.

In conclusion, I suggetst you should use types most of the time, and only use interfaces if you are planning to write implementations.

Top comments (0)