✏️ 첫 번째 방법

Untitled

node index.js

❌ 파일을 찾을 수 없음.

Untitled

node index.ts

❌ 기대하지 않은 값이다.

→ Node는 자바스크립트만 컴파일 할 수 있다. 타입스크립트는 읽지 못함.

📌 tsc

tsc index.ts

Untitled

→ 컴파일하는 명령어지만, 또 오류가 났다.

🚩 해결하기

npm install typescript -g

Untitled

tsc -v

Untitled

tsc index.ts

index.js 파일이 생성

index.js 파일이 생성

📌 또 다른 오류

Cannot redeclare block-scoped variable 'name'

{
  "compilerOptions": {
    "lib": ["ES6"]
  }
}

→ 오류 해결

✏️ 두 번째 방법

빌드해서 컴파일 하기

🧹단축키 Ctrl + Shift + b

Untitled

📌 오류 발생 - VS Code와 윈도우 사용자에게 생기는 오류

Untitled

📌 해결하기

윈도우에서 cmd 오픈

바탕화면에서 → cd typscript-study(폴더 안으로 들어오기)

tsc -p c:\Users\user\Desktop\typscript-study\tsconfig.json

cmd 창에 입력해준다.

dist 폴더 안에 컴파일 된 index.js를 볼 수 있다.

dist 폴더 안에 컴파일 된 index.js를 볼 수 있다.