[React] TypeScript(1): 설치 및 js 변환법

J.A.Y·2024년 3월 23일
0

TypeScript

목록 보기
1/4

TypeScript 설치하는 방법

1. npm 설치

  • Window:
npm install typescript -g
  • Mac:
sudo npm install typescript

2. 설치 후 버전 확인

tsc -v

실행하면 아래처럼 버전이 뜨게 됩니다.

3. tsconfig 파일 생성

tsc --init

4. ts파일 생성 후 js로 변환하고자 할 때

tsc파일이름.ts

5. node.js로 실행

변환된 js파일을 실행해줍니다.

node 파일이름.js

node.js npm 설치법

npm init
npm install express --save

ts-node로 js파일 변환 및 실행 자동화

ts-node 전역 설치

npm install -g ts-node

ts-node 버전 확인

ts-node -vv

ts-node 실행

ts-node index.ts

타입스크립트 템플릿으로 프로젝트 만들기

npx create-react-app 프로젝트명 --template typescript

기존 프로젝트에 타입스크트 적용하고 싶을 때는 모듈 설치를 해주고, js와 jsx파일을 ts, tsx파일로 변경 및 tsconfig.json파일을 생성해주면 됩니다.

npm install typescript @types/node @types/react @types/react-dom @types/jest
profile
Done is better than perfect🏃‍♀️

0개의 댓글