What is TypeScript?
TypeScript is a superset of JavaScript that is compiled to JS, and has benefits like type safety. It helps catch errors during development.
Why use TypeScript?
Basic Types
Just like in JavaScript, Typescript has primitive data types and non-primitive data types.
Primitive Types:
Basic Types
Primitive Types:
Basic Types
Object Types:
See Labs for code demo
Basic Types
Object Types:
See Labs for code demo
Type Aliases, Union Types, Intersection Types
See Labs for code demo
Functions Typing and Interfaces
See Labs for code demo
Classes and OOP Concepts
TypeScript enhances JavaScript classes with type annotations and access modifiers.
There are three main visibility modifiers in TypeScript:
Keywords that support OOP concepts:
See Labs for code demo
Generics
Generics allows developers to create reusable components that can work with a variety of data types while maintaining type safety
Generics can be implemented with functions, interfaces, etc.
See Labs for code demo
Modules
A module is just a file that contains reusable code like variables, functions, or classes, and can be imported or exported to other files.
There are two module systems in JavaScript:
See Labs for code demo