Interface-3

홍인열·2021년 8월 11일
0
//indexable type
interface person3 {
  name: string;
  age?: number;
  [index: string]: any; // 어떤 이름의 index가 와도 되는 type.
}

function hello3(person: person3): void {
  console.log(`p3 안녕하세요 ${person.name} 입니다.`);
}

const p31: person3 = {
  name: "hinyc",
  age: 31,
};

const p32: person3 = {
  name: "lee",
  sisters: ["uk", "ik"],
};

const p33: person3 = {
  name: "Woo",
};

hello3(p31);
hello3(p32);
hello3(p33);
profile
함께 일하고싶은 개발자

0개의 댓글