Skip to content

Commit 4866b34

Browse files
committed
add code and note til ts external lib modularization
1 parent 4d5c5f2 commit 4866b34

File tree

7 files changed

+68
-11
lines changed

7 files changed

+68
-11
lines changed

project/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
- [x] `tsc` 명령어로 타입스크립트 컴파일 하기
1414
2. 명시적인 `any` 선언하기
1515
- `tsconfig.json` 파일에 `noImplicitAny` 값을 `true`로 추가
16+
- 가능한한 구체적인 타입으로 타입 정의
17+
3. 프로젝트 환경 구성
18+
- babel, eslint, prettier 등의 환경 설정
19+
4. 외부 라이브러리 모듈화
20+
1621

1722
## 참고 자료
1823

project/package-lock.json

Lines changed: 45 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

project/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
"keywords": [],
1111
"author": "",
1212
"license": "ISC",
13-
"dependencies": {},
13+
"dependencies": {
14+
"axios": "^0.21.0",
15+
"chart.js": "^2.9.4"
16+
},
1417
"devDependencies": {
1518
"@babel/core": "^7.12.7",
1619
"@babel/preset-env": "^7.12.7",

project/src/app.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
const sum = (a, b) => a + b;
1+
// // 라이브러리 로딩
2+
// import 변수명 from '라이브러리 이름';
3+
// // 변수, 함수 임포트 문법
4+
// import {} from '파일 상대 경로';
5+
import axios from 'axios';
6+
import * as Chart from 'chart.js';
27

38
// utils
49
function $(selector: string) {
@@ -8,12 +13,10 @@ function getUnixTimestamp(date: Date) {
813
return new Date(date).getTime();
914
}
1015

11-
const a = 10;
12-
1316
// DOM
14-
let a: Element | HTMLElement | HTMLParagraphElement;
17+
// let a: Element | HTMLElement | HTMLParagraphElement;
1518
const confirmedTotal = $('.confirmed-total') as HTMLSpanElement;
16-
const deathsTotal: HTMLParagraphElement = $('.deaths');
19+
const deathsTotal = $('.deaths') as HTMLParagraphElement;
1720
const recoveredTotal = $('.recovered') as HTMLParagraphElement;
1821
const lastUpdatedTime = $('.last-updated-time') as HTMLParagraphElement;
1922
const rankList = $('.rank-list');

project/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"outDir": "./built",
66
"moduleResolution": "Node",
77
"lib": ["ES2015", "DOM", "DOM.Iterable"],
8-
"noImplicitAny": true
8+
"noImplicitAny": true,
9+
"typeRoots": ["./node_modules/@types", "./types"]
910
},
1011
"include": ["./src/**/*"]
1112
}

project/types/chart.js/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module 'chart.js' {
2+
// ...
3+
}

setup/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ node_modules
7474
"eslint.validate": [
7575
"javascript",
7676
"typescript"
77-
],
77+
]
7878
}
7979
```
8080

0 commit comments

Comments
 (0)