๐Ÿ“ Next.js ํ”„๋กœ์ ํŠธ์— TypeScript ์ ์šฉํ•˜๊ธฐ

Boriยท2022๋…„ 9์›” 10์ผ
2

์–ด์จŒ๋“  ๊ณต๋ถ€

๋ชฉ๋ก ๋ณด๊ธฐ
6/41

๐Ÿ—’ Next.js ํ”„๋กœ์ ํŠธ์— TypeScript ์ ์šฉํ•˜๊ธฐ

  • ์ด๋ฏธ ์ƒ์„ฑ๋œ Next.js ํ”„๋กœ์ ํŠธ์— TypeScript๋ฅผ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”, ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋นˆ tsconfig.json ํŒŒ์ผ ์ƒ์„ฑ
$ touch tsconfig.json
  • ์ด ํ›„ next(npm run dev ๋˜๋Š” yarn dev)๋ฅผ ์‹คํ–‰ํ•˜๋ฉด Next.js๊ฐ€ ํ•„์š”ํ•œ ํŒจํ‚ค์ง€ ์„ค์น˜ ๊ณผ์ •์„ ์•ˆ๋‚ดํ•˜๋ฉฐ ์„ค์ •์„ ์™„๋ฃŒ
$ yarn dev

# You'll see instructions like these:
#
# Please install TypeScript, @types/react, and @types/node by running:
#
#         yarn add --dev typescript @types/react @types/node
#
# ...

  • tsconfig.json` ํŒŒ์ผ์ด ์ž๋™์œผ๋กœ ์„ค์ •๋จ
{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "incremental": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve"
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}
  • .js ํŒŒ์ผ์„ .tsx ๋˜๋Š” .ts๋กœ ๋ณ€๊ฒฝํ•˜๊ณ , TypeScript๋ฅผ ์ ์šฉ

์ฐธ๊ณ 

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

comment-user-thumbnail
2022๋…„ 9์›” 12์ผ

์™€์•„ ๋ฉ‹์ ธ์š”~

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ