💎 TypeScript Crash Course

Everything you need to know about TypeScript

Basic Type Checking

file_type_typescript app.ts
// Variables
const num = 23; // implicit type
let str: string; // explicit type

// Functions
export function multiply(a:number, b:number) {
    return a * b
}

Types and Interfaces

let human: Human;

type Human = {
    dna: string,
    age: number,
    sex: HumanSex
}

type HumanSex = 'male' | 'female' | 'cyborg'


const human: Human = {
    dna: "AGTC",
    age: 23,
    sex: 'cyborg',
}

Generics

type Dog = { name: string };
type Cat = { name: string };

const animal = { name: 'fluffy' }

type Robot<T> = {
    chip: string;
    animal: T;
}


const robotCat: Robot<Cat> = { animal, chip: 'Intel' };
const robotDog: Robot<Dog> = { animal, chip: 'AMD' };

How do add Types for Browser APIs

file_type_typescript app.ts
/// <reference lib="dom" />

Questions? Let's chat

Open Discord