728x90
TypeScript를 Javascript로 변환하기
function sum(a: number, b: number): number {
return a + b
}
sum(10, 20) //ts -> js 파일로 변환하는 작업을 compile이라고 한다.
npm i typescript -g
tsc index.ts #변환할 ts 파일
- TypeScript -> Javascript으로 변환하는 과정을 compile이라고 한다.
- 변환 후에는 js파일이 생성된다.
타입 스크립트 컴파일 설정하기
https://www.typescriptlang.org/tsconfig
TSConfig Reference - Docs on every TSConfig option
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.
www.typescriptlang.org
tsconfig.json
{
//타입스크립트를 js 파일로 어떻게 컴파일 할 지 정의하는 파일
"compilerOptions": {
"module": "commonjs",
"allowJs": true,
"checkJs": true,
"noImplicitAny": true, //모든 타입에 Any라도 넣어야한다
},
}
- tsconfig.json 파일을 만들게 되면 ts -> js 파일로 컴파일할 때 설정을 json형식으로 적을 수 있다.
플레이 그라운드
https://www.typescriptlang.org/play
TS Playground - An online editor for exploring TypeScript and JavaScript
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
www.typescriptlang.org
TS파일을 작성했을 때 어떤 JS 파일로 변환이 되는지 확인할 수 있는 웹 에디터
Babel · The compiler for next generation JavaScript
The compiler for next generation JavaScript
babeljs.io
더 많은 브라우져가 호환 가능하도록 코드를 변환해주는 라이브러리

- 공식문서에서 제공하는 웹 페이지로 Ts파일이 js로 어떻게 컴파일될지를 보여준다.
- TS Config에 설정한 대로 컴파일이 되 js파일에 보인다.
728x90
'타입스크립트 > 타입스크립트 소개와 배경' 카테고리의 다른 글
| 타입 스크립트 소개 (0) | 2022.10.03 |
|---|