타입스크립트 Generics in Class - 타입스크립트 TypeScript 강좌 13편
안녕하세요? 오늘은 지난 시간에 배운 Class Visibility에 더해서 클래스에서 제네릭을 쓰는 방법에 대해 알아보겠습니다. 일단 지난 시간에 만들었던 Database 클래스를 를 이용한 제네릭 형태로 변경해 보겠습니다. interface Database { get(id: string): string; set(id: string, value: string): void; } class InMemoryDatabase implements Database { protected db: Record = {}; get(id: string): string { return this.db[id]; } set(id: string, value: string): void { this.db[id] = value; } } 위..