Lorenzo GM

Insights on web development, software engineering, and modern tech practices

English|Spanish
Lorenzo GM

TypeScript Interface vs Type Alias

Understanding the differences between interfaces and type aliases in TypeScript

Project FoundationFront-EndTypeScript
TypeScript Interface vs Type Alias

TypeScript Interface vs Type Alias

The Official Handbook provides some information about the difference between them.

Why I prefer to use type alias over interface because:

  1. Declaration merging: if the same interface (same name) is declared twice with different properties, they will be merged into one interface with all the properties. With type alias, it will trigger a TypeScript error.
  2. Usually we talk about types when we refer to TypeScript. It's commonly used the suffix Type when defining them. Files are often called *.types.ts and folder ./types/my.types.ts.
  3. It's not called InterfaceScript, isn't it? :)

Definitely. They are almost the same, there is no real benefit in most cases of using one over the other. What makes sense is to choose one and stick to it.