Object Types

objects can be anonymous, named by using interface or type.

// ⭐️ anonymous
//                     ╭──────── anonymous ────────╮
function greet(person: { name: string; age: number }) {
  return "Hello " + person.name;
}

// ⭐️ interface
interface Person {
  name: string;
  age : number;
}

// ⭐️ type alias
type Person = {
  name: string;
  age : number;
};

// test run
function greet(person: Person) {
  return "Hello " + person.name;
}

Last updated