TS2 Module Augmentation와 Interface Merge를 활용한 bottom - up 식 구현 모듈의 interface에 merge 함으로써 타입을 관리하면 더 강력한 추상화와 중앙집권식이 구조가 아닌 개별 관리 구조를 가져갈 수 있다. (bottom - top) remix.run 프레임워크를 사용한 예제이나, 해당 프레임워크를 몰라도 상관없습니다. app/service/api.ts export interface ApiFns {} export type ApiFnKeys = keyof ApiFns; export type ApiProps = { [key in ApiFnKeys]: Parameters[0]; }; export type Method = { method: M }; type ApiMethod = { [key in ApiFnKeys]: ApiFns[key]['method']; }; /* ..... 2022. 7. 24. 식별할 수 있는 문자열(문자열 리터럴) 확인하는 방법 string extends T를 추가로 검사하면 string은 문자열 리터럴 타입을 상속하지 않으므로 string과 문자열 리터럴 타입을 구분할 수 있게 된다. 이것을 활용하여 다음과 같은 유틸리티를 만들었다. HTML 삽입 미리보기할 수 없는 소스 const categoryListPath = routerPaths.categoryList({ userName: 'gururu' }) // => '/gururu/category' 이러면 routeMatch에 경로에 해당하는 문자열만 추가해주면 알아서 routerPaths에 해당하는 generator 함수가 만들어진다. 2022. 4. 22. 이전 1 다음