Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- localStorage
- Node.js기본
- 성장기
- SSE
- 개발자
- 실시간알림
- EventSource
- mariadb
- Partition
- partitioning
- ServerSentEvent
- Lag
- 파티셔닝
- 열공하자
- node.js란
- node.js
- PostgreSQL
- frontend
Archives
- Today
- Total
써치킴의 우당탕탕 개발 블로그
[TypeScript][ch4][TypeScript Compiler] compileOptions - typeRoots, types 본문
TypeScript 합시다
[TypeScript][ch4][TypeScript Compiler] compileOptions - typeRoots, types
써치킴 2022. 2. 12. 03:35프로젝트에서 라이브러리를 사용할 때, 라이브러리는 JavaScript이기 때문에 타이핑이 안되어 있음 (Ex. React)
-> 타이핑이 안되어있는 JavaScript 라이브러리의 타입을 지정해주는 도구가 필요함
@types
- TypeScript 2.0부터 사용 가능해진 내장 type definition 시스템
- 아무 설정을 안하면 node_modules/@types라는 모든 경로를 찾아서 사용
Ex. React 설치
터미널에서 React 설치
npm install react
라이브러리는 설치됐으나 TypeScript에서 쓰기에는 타입 선언이 되어있지 않다는 Error 발생
npm i --save-dev @types/react 설치
에러는 사라지고 node_module/@types/react 폴더가 생김
+ React는 node_module/@types/react/index.d.ts로 설정됨 (default)
compileOptions : types
- 배열 안의 모듈 또는 node_modules/@types/ 안의 모듈 이름에서 찾아옴 (패키지 이름을 적음)
- [] 빈 배열을 넣는다는건 이 시스템을 이용하지 않겠다는 것
compileOptions : typeRoots
- 배열 안에 들있는 경로들 아래서만 타입을 가져옴
- 타입을 지정할 폴더를 지정
typeRoots와 types를 같이 사용하지 않는다!
'TypeScript 합시다' 카테고리의 다른 글
[TypeScript][ch4][TypeScript Compiler] compileOptions - outDir, outFile, rootDir (0) | 2022.02.12 |
---|---|
[TypeScript][ch4][TypeScript Compiler] compileOptions - target과 lib (0) | 2022.02.12 |
[TypeScript][ch4][TypeScript Compiler] files, include, exclude (0) | 2022.02.12 |
[TypeScript][ch4][TypeScript Compiler] extends (0) | 2022.02.12 |
[TypeScript][ch4][TypeScript Compiler] compileOnSave (0) | 2022.02.12 |
Comments