What is TypeScript

TypeScript explained for beginner

What is TypeScript
Photo by Bernard Hermant / Unsplash
  1. Superset of JavaScript
  2. Strongly-typed
  3. Compiled to standard JavaScript
  4. Runs everywhere JavaScript runs

Basic types and variable declaration

Type annotations and type declaration

TypeScript is strongly typed; changing the value once it's set will cause a compiler error.

let x: string = "I will be forever a string type"
x = 32 ❌
console.log(`Hello string: ${x}`)

Boolean

Number

String

Array

Enum

Void: is used as return type for function that don't actually return the value

Null and Undefined: can be assigned to any type

Never

Any

Union Types

let someValue: number | string;
someValue = 42 ✅
someValue = "Monrning" ✅