Difference Between type and interface in TypeScript

By Hemanta Sundaray on 2023-04-14

If you want to define a named type in TypeScript, you can either use the type keyword:

type User = {
  firstName: string
  lastName: string
  age: number
}

Or the interface keyword:

interface User {
  firstName: string
  lastName: string
  age: number
}

In terms of functionality, both will enforce the type of the object at compile time.

So, what’s the difference between interface an type?

In terms of syntax, defining a type using type and interface differs slightly. When using type, the name of the type is followed by an equal sign (=), whereas with interface, there is no equal sign. The name of the interface is directly followed by curly braces ({ }).

However, the biggest difference between interface and type is in their usage. While interface can only be used to type objects, type can be used to type not only objects, but also primitives and other types.

Join the Newsletter