Basic typing of variables

const name: string = "Tom Delong";
const age: number = 23;

Typing for Class, Array, and Map

class User {
  constructor({ name, age }: { name: string, age: number }) {
    this.id = Math.random();
    this.name = name;
    this.age = age;
  }
}

const users: User[] = [
  new User({ name: "Mark", age: 23 }),
  new User({ name: "Tom", age: 23 }),
  new User({ name: "Travis", age: 23 }),
]

const usersMap: Map<string, User> = Object.fromEntries(
  users.map(u => [u.id, u])
)

Rename and type destructed variables

const { cameras: devices }: { cameras: CameraModel[] } = bar;
console.log(devices) // list of CameraModels

Generics - These are just a way for you to pass types into a function like you would an argument. For regular arguments you do this function(arg1) and if you also wanted to pass this function a type you do this function<type1>(arg1). Parens for regular arguments "(value)" and carrots for type arguments "<value>".

// pass in the CameraModel and custom fetch to our getDevice function
getDevices<CameraModel>(getCameras);

function getDevices<DeviceType>(getFunction) {
  // in this instance DeviceType === CameraModel and we can use it
  // to correctly type the return from our getFunction
  const devices: DeviceType[] = getFunction();
  return devices;
}

Function argument: destructing, typing, and default values

function AudioGraph(
  { volume, gain } :
  { volume: string; gain: string; } =
  { volume: 100, gain: 50 }
) {
  // these arguments are:
  // 1. destructed
  // 2. typed
  // 3. have default values
  console.log(volume, gain);
}