1. 패키지 설치
npm install --save typescript @types/node @types/react @types/react-dom @types/jest
2. 경로에 있는 js파일 ts, tsx로 확장자 변경해준다.
3. "npx tsc --init" 명령어로 tsconfig.json 파일 생성한 후, tsconfig.json 파일에 "jsx": "react-jsx"추가
4. src/index.tsx에서 수정
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
5. 타입이 없다고 나오는 패키지들 타입 추가하기
(패키지를 다운받고 타입이 없는경우는 definitelyTyped 페이지에 왠만한건 다 있을거다)
npm i --save-dev @types/styled-components
CRA에서 처음부터 타입스크립트 template 설치하는 법
npx create-react-app 프로젝트이름 --template typescript
'NOTE' 카테고리의 다른 글
Array.findIndex() (0) | 2023.03.02 |
---|---|
react-helmet (0) | 2023.02.25 |
Array.prototype.filter(), Array.prototype.find()의 차이 (0) | 2023.02.16 |
Swiper.js slidesPerGroup 슬라이드 여러장씩 이동시키기 (0) | 2023.02.03 |
a태그 이미지 다운로드 구현 (0) | 2022.03.20 |