Skip to content

[Umbrella] TypeScript Migration (Help wanted!) #21995

@blainekasten

Description

@blainekasten

Hello Community!

Gatsby is rewriting our core codebase in TypeScript! Checkout the RFC: #21798

We would love love love your help! This work is incredibly important in Gatsby being a stable product and you could be a part of it! We are looking for community members who would be willing to jump into the codebase in transition files from .js to .ts and add the proper typings. We have a few guidelines we are wanting to stick to when doing this:

Gatsby TS Guidelines

  • Only use named exports, no export default.
  • When importing a package, always try to find community maintained types instead of typing ourselves. Look at the DefinitelyTyped github repository.
  • Opt for using Interfaces for objects and functions.
  • Type aliases should be used for primitives, unions and tuples
  • Interface declaration merging is an anti-pattern and should not be used internally.
  • Use Array<type> rather than type[] syntax, as it's clearer and matches built-in types such as Map.
  • Use TypeScript's helper types, such as Record, rather than defining your own.
  • Every function should type its input and output (even if it’s inferrable)
  • Enums are great, but beware they map to index numbers if not redefined. This can cause weird problems for public APIs that interop to normal JS.
  • The any type can be used for stubbing module types that would be out of scope to migrate. But it should not be used for any functional input/outputs. The end goal of this migration is to have ZERO any types in the codebase. See if unknown makes more sense in that context. Don't use @ts-ignore comments.
  • Lastly and most imporantly, we want to have simple types whenever possible. Primarily we should try to avoid Generics. Generic code can be highly reusable, but that can also come with the greater chance of breaking things. If you do need to use generics, please either give them default values or ensure the generic value can be inferred. Code should be simple when possible. DRY is not always best.

If you're interested in getting involved, check out the list below. If you're interested in doing something, please respond as a comment, i'll put your name by a file so others know it's "claimed", when the PR is merged i'll check the box.

Tips to get involved: first read the contribution docs, and see how to set up your local environment. After you've claimed the file to work on, convert it locally and ensure there are no typing or lint errors displayed in your IDE. Run yarn typecheck and yarn lint:code in the root before opening the PR, which will show any errors. Once you're ready, open the PR and one of us will review it. Thanks, and good luck!

File list








  • packages/gatsby-page-utils
    • src/
      • /create-path.js + test
      • /ignore-path.js + test
      • /index.js
      • /validate-path.js + test
      • /watch-directory.js


Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedIssue with a clear description that the community can help with.not staletopic: TypeScriptIssues and PRs related to TS in general, public typings or gatsby-plugin-typescript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions