How to add Typescript to GatsbyJS

Oscar de la Hera Gomez
A flower that symbolizes Typescript next to a flower that symbolizes GatsbyJS

The following tutorial offers a step by step guide on how to add Typescript to GatsbyJS.

Download the open source starter project available on GitHub using the button below.

Step One: Create a Gatsby Starter Project

A screenshot of terminal letting you know how to initialize a new gatsby starter project

Run the following line in terminal and complete the quiz.

npm init gatsby

Step Two: Set the current directory to your project

A screenshot of terminal showing you how to setup your current directory

Set the current directory to the name of your new project. In this case, the project was called my-gatsby-site.

cd my-gatsby-site

Step Three: Add Typescript

A screenshot of terminal showing you how to add typescript to your existing gatsbyjs project.

In terminal, run the following line

yarn add typescript @types/node @types/react @types/react-dom @types/jest

Step Four: Add Gatsby's Typescript Plugin

A screenshot of terminal showing you how to add the Typescript Plugin to your existing gatsbjs starter project.

In Terminal, run the following line

yarn add gatsby-plugin-typescript

Step Five: Create your tsconfig.json

A screenshot of what the tsconfig.json looks like. Available in the gist below.

In the root of your project, create a tsconfig.json and copy in the file below.

Step Six: Rename files

A screenshot showing your javascript files renamed to typescript files.

Rename all your desired Javascript files (.js) to Typescript (.tsx).

Looking to add support for Alias's or Paths?

Check out our step by step tutorial.

Any Questions

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.

delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details