Show List

TypeScript Data Types

TypeScript is a superset of JavaScript and allows to add types to data.

There are below common data types in TypeScript:
  • boolean
  • number
  • string
  • any - It allows any type of value reassignment.
  • void - Used with functions not returning anything.

Type Assignment


Type assignment can be done in two ways:

Explicit
Example: let fName: string = "Bob";

Implicit
Example: let fName = "Bob";
In the implicit assignment TypeScript will guess the type based on the assignment. 

TypeScript will throw warning if there is attempt to re-assign to a different data type
let fName: string = "Bob"; // fName is declared as string

fName = 33; // attempt to assign a number will throw warning


    Leave a Comment


  • captcha text