[React] Migrate JavaScript to TypeScript

movieยท2022๋…„ 5์›” 29์ผ
1

1. ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋ฅผ ๊ธฐ์กด ํ”„๋กœ์ ํŠธ์— ์„ค์น˜ํ•œ๋‹ค.

npm install typescript

2. ๊ธฐ์กด์— ์„ค์น˜๋˜์–ด ์žˆ๋˜ ํŒจํ‚ค์ง€๋“ค์„ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ๋ฒ„์ „์œผ๋กœ ์„ค์น˜ํ•œ๋‹ค.

npm install @types/---

ex) npm install @types/react-router-dom

3. tsconfig.json์„ ์ถ”๊ฐ€ํ•œ๋‹ค.

npx tsc --init
  • ๊ธฐ์กด์— jsconfig.json์ด ์žˆ๋‹ค๋ฉด ์ง€์›Œ์ฃผ์ž.

4. jsx ํŒŒ์ผ๋“ค์„ tsx๋กœ ๋ฐ”๊พผ๋‹ค.

  • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ๊ณผ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์ด ๊ณต์กดํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋ ค๋ฉด tsconfig.json์—์„œ "allowJs": true,๋ฅผ ํ•ด์ฃผ์ž.
// tsconfig.json

{
  "compilerOptions": {
     "allowJs": true,
  }
}

์—ฌ๋Ÿฌ ์„ค์ •๋“ค

ts-config

// tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "src", // ์ ˆ๋Œ€๊ฒฝ๋กœ ์„ค์ •
    "jsx": "react-jsx", // jsx์™€์˜ ํ˜ธํ™˜
  }
}

global.d.ts

  • declare


์ฐธ๊ณ 

profile
์˜ํ™”๋ณด๊ด€์†Œ๋Š” ์˜ํ™”๊ด€ ๐Ÿ˜Ž

0๊ฐœ์˜ ๋Œ“๊ธ€