인터페이스:클래스, 오브젝트의 모양을 특정해준다.
type Team = 'red' | 'blue' | 'yellow'
type Heaalth = 1 | 5 | 10
interface Human {
name:string
}
interface Person extends Human { //상속
nickname: string,
team: Team,
health: Heaalth
}
const test: Person = {
name:'seong',
nickname: "netban",
team: "yellow",
health: 10
}
interface Human {
name:string
}
interface Human {
age:number,
}
interface Human { //Human이 하나로 합쳐짐
first_name : string
}
interface Person extends Human {
nickname: string,
}
const test: Person = {
name:'seong',
age: 25,
first_name:'SeungYoung',
nickname: "netban",
}
interface Name {
firstName: string,
lastName: string,
sayHi(name: string): string;
fullName(): string
}
class Myname implements Name {
constructor(
public readonly firstName: string,
public readonly lastName: string
) { }
sayHi(name: string): string {
return `hi ${name}, I'm ${this.fullName()}`
}
fullName(): string {
return `${this.firstName} ${this.lastName}`;
}
}