Object

Topics

Object Types (Names)

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;
};
 
function greet(person: Person) {
  return "Hello " + person.name;
}

Last updated