DEV Community

Cover image for Getting Started with TypeScript: A Comprehensive Guide

Getting Started with TypeScript: A Comprehensive Guide

Jack Pritom Soren on January 29, 2024

Introduction TypeScript is a superset of JavaScript that brings static typing to the language. Developed by Microsoft, it aims to enhanc...
Collapse
 
jwhenry3 profile image
Justin Henry

Another unit of information that is very helpful is Union Typing, which allows you to merge types without dealing with inheritance.

export declare type Truck = { extendedCab: boolean };
export declare type Car = { trunkSize: 'small' | 'medium' | 'large' };
export declare type Vehicle = Truck | Car; 
// can be one or the other

export declare type NameLike = { name: string };
export declare type AgeLike = { age: number };
export declare type PersonLike = NameLike & PersonLike; 
// requires both fields
Enter fullscreen mode Exit fullscreen mode
Collapse
 
jps27cse profile image
Jack Pritom Soren

Thank you so much!

Collapse
 
jangelodev profile image
João Angelo

Hi Jack Pritom Soren !
Thanks for sharing