1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Next.jsでTypescript導入するとき特に何もしなくていいよって話

Posted at

概要

Next.jsマジで親切、Typescript導入に何か特にすること無いよって話です

Next.jsでTypescript導入するとき

create-next-appでNext.jsのプロジェクトを作ってみます

> npx create-next-app

その時生成されたプロジェクトにはTypescriptは入っていません。

package.json
{
  "name": "hoge",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "next": "10.1.2",
    "react": "17.0.2",
    "react-dom": "17.0.2"
  }
}

Typescriptをインストールします。

> yarn add --dev typescript @types/react @types/node

これでyarn run devを走らせてみます。
すると下記のようなログが表示されます。

$ next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Using webpack 4. Reason: future.webpack5 option not enabled https://nextjs.org/docs/messages/webpack5
We detected TypeScript in your project and created a tsconfig.json file for you.

We detected TypeScript in your project and created a tsconfig.json file for you.

Typescriptがあるの見つけたから、tsconfig.json作っておいたよ、ってことですね。
マジで親切。

これでデフォルトのindex.jsindex.tsxに変更してもちゃんと動きます。
スクリーンショット 2021-03-31 20.10.57.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?