TS - Object with multiple types

by Rodwyn Moreno

TypeScript

type Hero = {
  name:string,
  age:number
}

let flash: string | number | Hero = "Flash";

console.log(flash);

flash = {
  name: "Barry Allen",
  age: 24
}

console.log(flash);