interface Person2 {
name: string;
// 있을수도 있고 없을수도 있다!
age?: number;
}
function hello2(person: Person2): void {
console.log(`ㅎㅇ! ${person.name} 이라고 해요!`);
}
hello2({ name: 'malza', age: 29 });
hello2({ name: 'yoon' }); // ok!
interface Person3 {
name: string;
age?: number;
// indexable type. 어떤 이름의 property 가 와도 괜찮다.
[index: string]: any;
}
function hello3(person: Person3): void {
console.log(`ㅎㅇ! ${person.name}입니다 ㅎ`);
}
const p3: Person3 = {
name: 'malza',
// age 있거나 말거나
};
const p3_2: Person3 = {
name: 'yoon',
age: 20,
systers: ['park', 'woo'],
};
const p3_3: Person3 = {
name: 'Amy',
mother: p3,
father: p3_2,
};
console.log(p3_3.mother); // 잘 나온다.
console.log(p3_3.father); // 잘 나온다.
};