They look almost identical, but there are some important differences. Let's explore when to use each.
When defining the shape of an object in TypeScript, we generally have two options: type and interface .
Let's start with a simple example:
type Person = { name : string ; age : number ; } ;
// Using an interface interface Person { name : string ; age : number ; }
Enter fullscreen mode
Exit fullscreen mode
Both approaches describe an object with two properties: name and age .
A quick note: You might see developers using prefixes such as I for interfaces and T for type aliases. These are personal naming conventions, not TypeScript requirements. Generally, avoid unnecessary prefixes.
Another option is class , but unlike type and interface , a class is a JavaScript runtime construct that introduces both a value and a type.
1.…