TS : 타입 정의(tsconfig.json 내용 정리)
- "include": js로 컴파일하고싶은 디렉토리
- "compilerOptions": {
"outDir": 컴파일된 js가 저장 될 디렉토리,
"target": js로 컴파일 할 ECMA버전,
"lib": 어떤버전의 js가 사용되는지 그 환경, 브라우저위에서 실행하려면 DOM,
"strict": 엄격모드,
"allowJs": ts가 js파일 안에 들어와서 함수를 불러올 수 있게한다.
}
{
"include": ["src"],
"compilerOptions": {
"outDir": "build",
"target": "ES6",
"lib": ["ES6", "DOM"],
"strict": true,
"allowJs": true
}
}
js파일을 그대로 ts 보호를 받는 법 (JSDoc)
- ts가 확인 할 js파일 첫번째 줄에
// @ts-check
작성
- JSDoc 안에 내용 작성
export function init(config) {
return true;
}
export function exit(code) {
return code + 1;
}