TypeScript Crash Course
This is meant to be a basic introduction to common types used in TypeScript. This is not necessarily releated to React but will be used as React files are typed.
const myName: string = 'Aryan';const myAge: number = 25; // I swear 🤥:// array of typeconst myFavoriteLanguages: string[] = ['JavaScript', 'Python', 'Java'];// string literals (must be one of these EXACT values)const seasons: 'summer' | 'fall' | 'winter' | 'spring' = 'winter';// object with specific propertiesconst car: {make: string;model: string;yearReleased: number;hasAirbags?: boolean; // the question mark means this property is optional} = {make: 'Honda',model: 'Civic',yearReleased: 1994,}; // fun fact, this was my first car!// you can also define the type separatelytype Car = {make: string;model: string;yearReleased: number;hasAirbags?: boolean;};const someFancierCar: Car = {make: 'Jaguar',model: 'XJ',yearReleased: 2019,hasAirbags: true,};// array of objectsconst garage: Car[] = [car, someFancierCar];// function without call signatureconst callback: Function = () => 'ohai!';// function with call signatureconst callbackWithStrictSignature: (name: string) => string = () => `hai again, ${name}!`;