Interfaces

A Sale interface.

interface Sale names the shape of a kiosk row.

Goal

Log city from a Sale.

interface Sale {
  city: string;
  units: number;
}
const row: Sale = { city: "Nairobi", units: 12 };
console.log(row.city, row.units);
interface Sale {
  city: string;
  units: number;
  shillings: number;
}
function total(row: Sale): number {
  return row.shillings;
}
console.log(total({ city: "Mombasa", units: 8, shillings: 320 }));
interface Sale {
  city: string;
  units: number;
}
const rows: Sale[] = [
  { city: "Kisumu", units: 5 },
  { city: "Nakuru", units: 4 },
];
console.log(rows.map((r) => r.city));
interface Kiosk {
  name: string;
  city: string;
}
const k: Kiosk = { name: "Ada", city: "Eldoret" };
console.log(k.name);