Add Typescript to Existing Next.js project with Yarn 🧞‍♂️

Originally posted: 2021-04-06

Super simple code to add TS to your existing Next.js app using Yarn instead of NPM.

Step 1

In the root folder of your project (where your package.json file is), put this into Terminal:

touch tsconfig.json

Step 2

Now install Typescript into your Next.js app using Yarn:

yarn add typescript @types/react @types/node

Extras

Don't forget to restart your development server if it's open in another Terminal.

Also, I would highly recommend adding to the file inclusions in your tsconfig.json file:

  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    "**/*.css", 👈
    "**.*.js" 👈
  ],