Skip to content

Instantly share code, notes, and snippets.

@burnoutprojects
Last active August 21, 2023 10:49
Show Gist options
  • Save burnoutprojects/211c9e65ce487918610c44ee9c8e6706 to your computer and use it in GitHub Desktop.
Save burnoutprojects/211c9e65ce487918610c44ee9c8e6706 to your computer and use it in GitHub Desktop.
Typescript Types vs Interfaces
Type Interface
In typescript type is defined for a variable’s data type which means type declaration in typescript is used for declaring names of different types such as user-defined, built-in, or any other data types. Interfaces are defined as the syntax for the class which provides a way to define entities.
It uses the type keyword for defining new types. It uses the interface keyword for declaring an interface.
Types can be used for others like built-in types, tuples, etc. The interface cannot be used with other types of declaration.
Types cannot be extended and hence it does not support classes. Interfaces can be extended and it supports classes.
In Typescript, union types can contain one or more types. In typescript this feature of union types is not supported as we cannot create a union interface by combining two types.

Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment