front-end/react

리액트 프로젝트에 타입스크립트 추가

hojung 2022. 1. 28.
728x90
반응형

처음부터 typescript를 사용하려면 create-react-app에서 

npx create-react-app my-app --template typescript

#

yarn create react-app my-app --template typescript

 

이미 만들어 놓은 React 프로젝트에 typescript를 추가하고 싶다면

npm의 경우

npm install --save typescript @types/node @types/react @types/react-dom @types/jest #

yarn의 경우

or yarn add typescript @types/node @types/react @types/react-dom @types/jest

 

그 후 tsc --init 명령어를 통해 typescript 컴파일러 옵션이 들어있는 tsconfig.json 파일을 생성

 

그 다음 compileroption을 다음과 같이 설정한다. 

여기서 jsx를 설정해주는 것은 tsx파일을 이용하기 위해서 꼭 필요한 것이니 유의하자 

728x90
반응형

댓글