Both the methods Type and the Interface are used to describe the structure of the objects in TypeScript. But holds some specific features that will be helpful according to the situation, choosing between them and totally depends on the developer.
Type in TypeScript: The Type System in TypeScript portrays the different data types that are supported by the language. It is divided into three major sections that are Any Type, Built-In Type, and User-Defined Type. The Type System in TypeScript is responsible for checking the data type of any value taken before it can be provided as an input to the program.
"Duplicate identifier 'Geeks'" error.
Interface in TypeScript: An Interface in TypeScript is a syntactical obligation that all entities must follow. It can only contain the declaration of the members and is responsible for defining the properties, methods, and events. In a way, it is responsible for defining a standard structure that the derived classes will have to follow.
name: " kgowda", age: 20, email: " firstname.lastname@example.org"
Difference between Type and Interface in TypeScript:
|It is a collection of data types.||It is a form of syntax.|
|It supports the creation of a new name for a type.||It provides a way to define the entities.|
|It has less comparatively less capabilities.||It has comparatively more capabilities.|
|It does not support the use of an object.||It supports the use of an object.|
|Multiple merged declarations cannot be used.||Multiple merged declarations can be used.|
|Two types having the same name raise an exception.||Two interfaces having the same name get merged.|
|It does not have implementation purposes.||It has an implementation purpose.|
- How to declare nullable type in TypeScript ?
- Difference between private keyword and private fields in TypeScript
- What is the difference between 'String' and 'string' in TypeScript ?
- Difference between ES6 and TypeScript
- Function that takes an interface type as value and pointer in Golang
- What are the differences between any vs Object in TypeScript?
- Identifiers and Keywords in TypeScript
- Difference between data type and data structure
- Difference between :first-child and :first-of-type selector in CSS
- Data types in TypeScript
- Hello World in TypeScript
- Variables in TypeScript
- TypeScript class
- Classes in TypeScript
- TypeScript Arrays
- TypeScript Tuples
- TypeScript Ambients Declaration
- TypeScript Union
- TypeScript String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : yoyalamber