Skip to content

Head first TypeScript

TypeScript is a superset of JavaScript that compiles to plain JavaScript. It is a typed superset of JavaScript that compiles to plain JavaScript. TypeScript adds optional types, classes, and modules to JavaScript. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. TypeScript adds optional types, classes, and modules to JavaScript. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. TypeScript adds optional types, classes, and modules to JavaScript.

Microsoft designed TS with specific architectural parameters in mind, which allow TS to integrate fully and easily with existing JS code, while providing robust features external to JS.

  1. Providing a Type Check
  2. More Powerful Object-Oriented Programming
  3. Basic TS Compiler
  4. TypeScript Standalone Compiler, TSC
  5. Language Service
  6. Tool Integration

Getting Started

npm i -g typescript
tsc --version

## create a new tsconfig.json configuration file
tsc --init

## compile a single file
tsc hello.ts

## TS Compiler
tsc hello.ts
    tsc --outFile file.js file.ts
    tsc @args.txt
    tsc --build tsconfig.json

Basic TS Types

  1. Boolean
  2. Number
  3. String
  4. Array
  5. Tuple
  6. Enum
  7. Any
  8. Void
  9. Null and Undefined
  10. Never
  11. Object

Union Types

let mathematician = Math.random() > 0.5
    ? undefined
    : "Mark Goldberg";

let thinker: string | null = null;

if (Math.random() > 0.5) {
    thinker = "Susanne Langer"; // Ok
}

Kinds of Errors

  1. Syntax Errors
  2. Type Errors

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback: dig +short txt issue.imzye.com
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Buy Me a Coffee