💎 TypeScript Crash Course
Everything you need to know about TypeScript
Which flag is used to force type checking in Deno?
Basic Type Checking
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
app.ts
/// <reference lib="dom" />