TypeScript를 설치하기 전에 먼저 Node.js 와 Visual Studio Code를 다운로드하자.
https://nodejs.org/en/download
Node.js — Download
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
nodejs.org
https://code.visualstudio.com/download
Download Visual Studio Code - Mac, Linux, Windows
Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows. Download Visual Studio Code to experience a redefined code editor, optimized for building and debugging modern web and cloud applications.
code.visualstudio.com
자 이제 Visual Studio Code를 클릭해서 열어보자.
좌측 탐색기에서 폴더를 만들어주고,
Ctrl + Shift + `를 눌러 터미널을 연 다음
npm i -g typescript를 입력해서 typescript 패키지를 다운받는다.
hello.ts 파일을 생성한다.
console.log('Hello world!')
tsc hello.ts를 터미널에 입력하면 hello.js가 생성이 될 뿐, 코드를 실행하지는 않는다.
node hello.js를 입력하면 이제서야 파일 내용을 출력하게 된다.
tsc는 타입스크립트 코드를 ES5형식의 자바스크립트로 변환만 할 뿐 실행하지는 않는다.
변환 및 실행까지 하기 위해서는 ts-node 패키지가 필요하다.
npm i -g ts-node를 입력하여 패키지를 다운받고,
ts-node hello.ts를 입력하면 타입스크립트 코드를 ES5로 변환하고 실행을 한다.
'Programming > TypeScript' 카테고리의 다른 글
모듈 내보내기 및 가져오기 (import, export) (0) | 2024.02.18 |
---|