Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decide on how to handle TypeScript for Gatsby plugins and themes #950

Closed
jxnblk opened this issue May 22, 2020 · 3 comments
Closed

Decide on how to handle TypeScript for Gatsby plugins and themes #950

jxnblk opened this issue May 22, 2020 · 3 comments
Assignees

Comments

@jxnblk
Copy link
Member

jxnblk commented May 22, 2020

Based on discussion in #668, we should decouple the TypeScript conversion of Gatsby-related packages from the core packages, due to how Gatsby currently handles TypeScript in plugins.

Currently, the plugins and themes are written in standard JavaScript, and Gatsby uses these packages as-is, without a compilation step needed in this repo. This can be beneficial for users who "eject" (copy and paste) files from these plugins and themes, when using Gatsby's shadowing feature, because it means the files copied over are the same as they are written.

In the future, once Gatsby supports TypeScript language in plugins, we should still consider backwards compatibility and those who use Gatsby with JavaScript -- introducing another language could be unexpected.

There are several PRs already in-progress for converting these packages, and they should remain open until a solution is decided upon:

Potential solutions

Off the top of my head, there are a few ways to handle this, but I'm open to hearing more suggestions:

  1. Keep all Gatsby related packages written in JavaScript -- this is not ideal for TypeScript users
  2. Convert packages to TypeScript and add a compilation step -- this is probably not ideal for anyone
  3. Add type definitions for the packages, but keep them written in JavaScript -- I'm unsure of how big the downside is, but TypeScript users who eject files would still get JavaScript
  4. Create separate TypeScript-specific packages in addition to the JavaScript ones -- this has a bigger maintenance cost
  5. Wait for future support in Gatsby that could help with this -- it's unclear what this would look like or how long this would take

Additional context

Some of these packages have very low usage and are somewhat experimental:

  • gatsby-theme-code-recipes: 1 download per week (I think it's theme-ui.com)
  • gatsby-theme-ui-layout: 28 downloads per week
  • gatsby-theme-ui-blog: 88 downloads per week
@mxstbr mxstbr mentioned this issue May 22, 2020
32 tasks
@hasparus
Copy link
Member

I'd like to add one potential solution. I'm not sure if the 3 is the one I'm thinking about.

Preact is written as JavaScript with really good JSDoc comments (powered by TS).
We could steal that approach for plugins and themes.

Pros:

  • It's still JavaScript, and most developers are either familiar with JSDoc, or will just disregard it as a normal comment. We preserve accessibility for JS users. IDEs of JavaScript users should pick these types and provide autocomplete, and the comments are not hard too remove if somebody doesn't like them.
  • With checkJs: true in plugin tsconfig, we'll get type errors during development if a change to theme-ui packages breaks the plugin.

Cons:

  • TS users will need to turn checkJs to true if they want typecheck ejected files. (that's not a huge problem, I think)

@jxnblk
Copy link
Member Author

jxnblk commented May 26, 2020

That sounds a lot better than what I was thinking! If we go that route, would it make sense to keep the in-flight PRs open? Or, is there a way we should preserve that work if Gatsby provides better support for TS-based plugins in the future?

@lachlanjc
Copy link
Member

Closing since I think we know what we want to do here, & there's separate issues/PRs for implementing it? (Feel free to reopen.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants