Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • TypeScript Tutorial
  • TS Exercise
  • TS Interview Questions
  • TS Cheat Sheet
  • TS Array
  • TS String
  • TS Object
  • TS Operators
  • TS Projects
  • TS Union Types
  • TS Function
  • TS Class
  • TS Generic
Open In App
Next Article:
What is the difference between interface and type in TypeScript ?
Next article icon

TypeScript Differences Between Type Aliases and Interfaces Type

Last Updated : 23 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In TypeScript, both type aliases and interfaces are used to define custom types, but they have distinct differences and use cases.

  • Type Aliases: Allow the definition of types with a custom name, applicable to primitives, unions, tuples, and more complex types.
  • Interfaces: Primarily used for defining object types and specifying property names and their types. They can be extended or merged.

Type Aliases

Type aliases in TypeScript allow you to create custom names for types, enhancing code readability and reusability.

JavaScript
type Point = {     x: number;     y: number; };  function printPoint(point: Point): void {     console.log(`x: ${point.x}, y: ${point.y}`); }  const myPoint: Point = { x: 10, y: 20 }; printPoint(myPoint); 
  • The type Point = { x: number; y: number; }; line defines a type alias named Point representing an object with x and y properties, both of which are numbers.
  • The printPoint function accepts a parameter of type Point and logs its properties to the console.
  • The myPoint constant is declared with the Point type and initialized with appropriate x and y values.

Output:

x: 10, y: 20

TypeScript Interfaces

Interfaces in TypeScript define the structure of an object, specifying the required property types and method signatures. They ensure type safety and enhance code clarity.

JavaScript
interface Point {     x: number;     y: number; }  function displayPoint(point: Point): void {     console.log(`x: ${point.x}, y: ${point.y}`); }  const myPoint: Point = { x: 15, y: 25 }; displayPoint(myPoint); 
  • interface Point { x: number; y: number; }: Defines an interface named Point that describes an object with x and y properties, both of type number.
  • Function displayPoint(point: Point): void: Accepts an object adhering to the Point interface and logs its x and y values.

Output:

x: 15, y: 25

Type Aliases vs Interfaces in TypeScript

Type Aliases

Interfaces Type

Type Aliases use the type keyword to define a new type.

Interface Type use the interface keyword to define a new type.

Type aliases support extending other type aliases by intersection type. The & symbol is used to create an intersection type. Type aliases also extends interface types.

Interface Type also supports extending other interfaces by using the `extends` keyword. Interface type also extends type aliases.

Type Aliases can be implemented by class with the use of the `implements` keyword. but they cannot be extended or implemented.

Interface Type can also be implemented by class with the use of the implements keyword.

Type Aliases don't support declaration merging where declaring the same type of aliases again a second time with another type gives an error.

Interface type does support declaration merging where declaring the same interface again a second time merges with previous attributes of the last type interface.


Next Article
What is the difference between interface and type in TypeScript ?
author
chmanikanta528
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • Geeks Premier League
  • TypeScript
  • Geeks Premier League 2023

Similar Reads

  • What is the difference between interface and type in TypeScript ?
    In TypeScript, both interface and type are used to define the structure of objects, but they differ in flexibility and usage. While interface is extendable and primarily for object shapes, type is more versatile, allowing unions, intersections, and more complex type definitions. Type in TypeScriptTh
    4 min read
  • Difference between interfaces and classes in TypeScript
    In this article, we will see what is the Difference between "interface" and "Classes" in TypeScript. Interface: Interface is the virtual structure that is used for type-checking. In TypeScript we use interface keyword to create the new interface with identity. It create the structure for the same da
    3 min read
  • What are the differences between any vs Object in TypeScript?
    TypeScript is an open-source programming language. It is a superset of JavaScript language. TypeScript is designed for the development of large applications. any: It is a built-in data type in TypeScript which helps in describing the type of variable which we are unsure of while writing the code. Th
    2 min read
  • Difference Between valueof and keyof in TypeScript
    In TypeScript, valueOf() retrieves the primitive value of an object, useful for accessing inherent data types. Conversely, keyof extracts keys as a union type, crucial for type-safe property referencing and dynamic type handling in TypeScript's type system. ValueOf() methodThe valueOf() method is a
    2 min read
  • Difference between Flow and TypeScript
    1. Flow : Flow is developed and maintained by Facebook. It is a static type checker, designed to quickly find errors in JavaScript applications. Nothing more, nothing less. It's not a compiler, but a checker. It can work without any type of annotations and it is very good at inferring types. To enab
    2 min read
  • Interesting Facts About Object Types and Interfaces in TypeScript
    TypeScript enhances object types and interfaces with strong typing, extendibility, and dynamic features, making code more structured and maintainable. Mastering these concepts improves scalability, flexibility, and type safety in applications. 1. Interfaces Can Describe FunctionsInterfaces in TypeSc
    3 min read
  • What's the Difference Between 'extends' and 'implements' in TypeScript ?
    TypeScript offers powerful way for organizing code and managing relationships between different components through the use of extends and implements keywords. This article explores the distinctions and functionalities of these two keywords. ExtendsThe extends keyword is used for two main purposes in
    3 min read
  • Difference between a type and a kind
    The words Type and Kind are very common words in English speeches and writings. Both of the words are very commonly used on daily basis for communication purpose. Both of the words seem to be similar but it is not so. Both the words Kind and Type have different meaning and should be used wisely to k
    2 min read
  • What are type aliases and how to create it in Typescript ?
    In Typescript, Type aliases give a type a new name. They are similar to interfaces in that they can be used to name primitives and any other kinds that you'd have to define by hand otherwise. Aliasing doesn't truly create a new type; instead, it gives that type a new name. Aliasing a primitive isn't
    3 min read
  • TypeScript - Type Annotations and Type Inference
    TypeScript is a superset of JavaScript that adds static typing, helping developers catch errors early. Two core features are type annotations- where developers explicitly define variable, parameter, and return types, and type inference, where TypeScript automatically deduces types based on values or
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences