React
[Typescript] @type이 없는 외부 라이브러리 사용 방법
곰돌찌
2020. 7. 8. 13:26
업무때 고생해서 일단 적어보기
1. tsconfig.json
아래 typeRoots와 declaration, declarationDir 등 입력할 것
{
"compilerOptions": {
...
"typeRoots": ["./types", "./node_modules/@types"], // 보통 types 폴더를 만들어 타입 정의
"declaration": true, // lib 만들 때 .d.ts 파일을 자동으로
"declarationDir": "./types" // 이 폴더에 만들어주는 옵션
},
"typeRoots": ["./types", "./node_modules/@types"],
"include": ["src"]
}
2. root에서 types 라는 폴더를 생성
3. type이 없던 외부 라이브러리의 이름으로 폴더를 하나 생성
4. 폴더 아래 index.t.ts 생성
5. 자신이 타입을 다 정의하고싶다!! 하면 index.d.ts 에다가 하면되지만... 그럴 시간이 없으면..
declare module 'react-date-range';
간단하게 이렇게만 써주면 해결됨!!!!