TypeScript (TS)

TypeScript is a superset of JavaScript created by Microsoft that adds features such as static typing, improved tooling and error checking, interfaces, enums, and generics, and is transpiled into JavaScript.

let age: number = 29;
let userName: string = 'Grant';
let isOpen: boolean = true;

console.log(`${userName} is ${age} years old`);

Types

Types describe what kind of data a value is allowed to be. Types answer questions such as "Is this a number or a string? Is this value optional or required? What properties does this object have? What arguments can this function accept? What will this function return?" In JavaScript, these questions are answered at runtime. In TypeScript, they're answered before the code runs.

TypeScript Basics

Transpiling TypeScript into JavaScript

# This transpiles the TypeScript code into JavaScript

tsc typescript_file.ts

# The new JavaScript code can now be executed

node typescript_file.js

Common Basic Types

number
string
boolean
null
undefined
let age: number = 29;
let userName: string = 'Grant';
let isOpen: boolean = true;

console.log(`${userName} is ${age} years old`);