How to add Typescript to GatsbyJS

A step by step guide on how to add Typescript. Includes an open source GitHub starter project.

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 06/27/2022 at 13:50
Last Updated on 06/29/2022 at 12:00
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.

Download Opensource Project

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
Read GatsbyJS's Quick Start Guide

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.

How to add Alias's / Paths in Typescript + Gatsby

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.

SubscribeInquireView All PostsView All ServicesView All Work

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe