추상 클래스 abstract(추상) : 클래스가 가져야 하는 실제적인 구현을 제외하고 클래스가 내부에서 가져야 되는 다양한 속성이나 메서드의 타입만 추상적으로 정의 추상 클래스는 class 앞에 abstract 키워드를 붙여줘야 한다 추상 클래스 vs 인터페이스 확장 : 추상 클래스는 extends 키워드 / 인터페이스는 implements 키워드 추상 클래스에서 확장할 클래스가 있으면 super()를 호출해야 한다 추상 클래스는 선언부와 구현부를 같이 포함할 수 있지만 인터페이스는 구현부를 포함할 수 없다 추상 클래스는 Is - A 관계로 extends 키워드를 통해 단일로 사용가능하다 class Dog extends AnimalA{} 인터페이스는 Has - A 관계로 implements 키워드 뒤에 ..
클래스의 접근 제어자 public 어디서나 해당하는 속성을 자유롭게 접근해서 사용할수 있다 생략 가능, Default 값 class Animal { public name: string; public sound: string; constructor(name: string, sound: string) { this.name = name; this.sound = sound; } } class Dog extends Animal { public color: string; constructor(name: string, sound: string, color: string) { super(name, sound); this.color = color; } speak() { return this.sound; } getColo..
함수의 오버로딩 function addString(x: string, y: string) { console.log(x, y); return x + y; } function addNumber(x: number, y: number) { console.log(x + y); return x + y; } addString("Hello", "World"); addNumber(12, 34); addString("Hello", 34); addNumber(12, "World"); 위의 코드를 함수의 오버로딩을 사용해서 표현할 수 있다 function add(x: string, y: string): string; // 선언부 function add(x: number, y: number): number; // 선언부 fun..
함수의 명시적 this 타입 interface User { name: string; } function greet(msg: string) { return `Hello ${this.name}, ${msg}`; } const baek = { name: "Baek", greet, }; baek.greet("Good morning~"); // Hello Baek, Good morning~ const neo = { name: "Neo", }; greet.call(neo, "Good afternoon~"); // Hello Neo, Good afternoon~ this에서 타입이 선언되어 있지 않기 때문에 암시적으로 any타입으로 지정된다 this가 최소한 "User interface의 구조는 가지고 있어야 한다"..