Check out example codes for "install typescript in gatsby". It will help you in understanding the concepts better.

Code Example 1

yarn add gatsby-plugin-typescript
yarn add typescript --dev

# npm

npm i gatsby-plugin-typescript 
npm i typescript --save-dev

Learn ReactJs, React Native from akashmittal.com