Union & Literal Types — TypeScript

Union types memungkinkan variabel memiliki salah satu dari beberapa tipe: function cetak(id: string | number) { console.log(`ID: ${id}`); } cetak(123); // OK ce