타입스크립트 제네릭을 활용하여 placeholder 타입을 생성, 다형성 코드를 작성할 수 있다.
//인터페이스 생성
interface SStorage<T> {
[key:string] : T
}
//클래스 생성
class LocalStorage<T> {
private storage: SStorage<T> = {}
set(key:string, value:T){}
remove(key:string){
delete this.storage[key]
}
get(key:string):T{
return this.storage[key]
}
clear(){
this.storage = {}
}
}
//다양한 타입의 인스턴스 생성
const stringStorage = new LocalStorage<string>();
const booleanStorage = new LocalStorage<boolean>();
알록달록 스토리지