function hello1(person: { name: string, age: number }): void{
console.log(`안녕하세요! ${person.name} 입니다.`);
}
const p1: { name: string, age: number } = {
name: 'Mark',
age: 39
};
hello1(p1);
{ name: string, age: number }
를 인터페이스로 생성하여 간결하게 작성
interface Person1 {
name: string,
age: number
}
function hello1(person: Person1): void {
console.log(`안녕하세요! ${person.name} 입니다.`);
}
const p1: Person1 = {
name: 'Mark',
age: 39
};
hello1(p1);
인터페이스는 컴파일 타임에만 필요함 실제로 컴파일될 때는 사라짐
컴파일 후 js 파일 내용
"use strict";
function hello1(person) {
console.log("\uC548\uB155\uD558\uC138\uC694! " + person.name + " \uC785\uB2C8\uB2E4.");
}
var p1 = {
name: 'Mark',
age: 39
};
hello1(p1);