- Install a Gatsby project but do not select TypeScript as language
- Install the dependencies and generate
tsconfig.json
as stated in Gatsby docs - Make sure to add
"jsx": "react"
intsconfig.json
- [OPTIONAL] Install
prop-types
and useInferProps
to guarantee runtime erros will still be caught. Read more here. - In order to import JS files in components, set
allowJs: true
intsconfig.json
. Source. - You also need to set
outDir: "./dist"
after setting the above config. Source. - [OPTIONAL] If you want to use CSS Modules in
.tsx
files, then you need to createglobals.d.ts
in/src
. Source - [OPTIONAL] If ESLint is enabled, it may raise a parsing error on the
*.d.ts
files. A possible workaround is to disable the linter on those files. Source - [OPTIONAL] If importing .svg files as React components, you also will need to add it to
globals.d.ts
. Source
- https://blog.logrocket.com/comparing-typescript-and-proptypes-in-react-applications/
- https://dillionmegida.com/p/convert-blog-to-typescript/
- [BEST PRACTICES] Refer to this website for great React + TS best practices