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:
Array<type>
rather than type[]
syntax, as it's clearer and matches built-in types such as Map
.Record
, rather than defining your own.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.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!
[x] packages/babel-plugin-remove-graphql-queries
[ ] packages/babel-preset-gatsby
[ ] packages/gatsby
[x] packages/gatsby-cli
[x] packages/gatsby-core-utils
[ ] packages/gatsby-link (@herecydev in #22027)
[x] packages/gatsby-page-utils
[x] packages/gatsby-telemetry (@Eyas in #22532)
[x] packages/gatsby-react-router-scroll (@blainekasten in #24306)
I'll happily pick up gatsby-link. Been meaning to learn some more around there!
@herecydev That sounds great! I'll put your name down! That one is relatively small and isolated, so feel free to do that whole package in one PR if you want.
@blainekasten just a few preliminary comments. There are quite a few globals/window variables: __BASE_PATH__
, ___navigate
, ___push
, ___replace
, __PATH_PREFIX__
, ___loader
. Is there a strategy about making those available to typescript? I believe they're all defined from within the gatsby package.
@herecydev those variables are def meant to be like "private" "secret" variables.. So I don't think we'll expose any types from gatsby package as they are only meant to be used in a few places. I think the best course of action would just be to define types for them in the gatsby-link
package.
I'm excited to contribute, which package do you suggest for starting?
@aminkhp awesome!! I would love it if we could just start chunking off individual files in PRs. Want to tackle gatsby-core-utils
? I would love if you just did one file per PR as they are all very isolated.
I'd be happy to contribute some types. I'd be able to tackle gatsby-page-utils
.
I took a peek at gatsby-core-utils
by the way, and it looks like true-case-path
is just an empty file. I'm not sure if that's intentional, but it might be worth deleting from the repo and removing from the list? https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-core-utils/src/true-case-path.js
@robertrbairdii Great! If you could chunk up the work and submit 1 PR for each line I had, that would be fantastic.
Good point re the gatsby-core-utils. cc @aminkhp
I'd like to try src/commands/build-javascript.js
.
ADDITION: I'd also like to tackle babel-preset-gatsby
I spent some time in src/redux/actions/public.js
before, so I think I can help with it.
@blainekasten I was looking at the .babelrc
while converting gatsby-page-utils
and I noticed that there is no reference to @babel/plugin-transform-typescript
in babel-preset-gatsby-package
(https://github.com/gatsbyjs/gatsby/blob/master/packages/babel-preset-gatsby-package/index.js
). And running a test build, the converted .ts
files don't make it to the /dist
folder.
The babel config at the root of the repo has an override for it https://github.com/gatsbyjs/gatsby/blob/master/.babelrc.js#L12 And that config seems to be imported by other packages such as https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/babel.config.js
As far as I know, you can only pass the extensions as an argument through the CLI, so we would have to add the --extensions
flag to each babel reference in the scripts section of all the package.json
of the packages being converted. You could then either provide the override as is done in the root .babelrc
or add @babel/plugin-transform-typescript
in babel-preset-gatsby-package
and allow values like isTSX
to be configured via options passed in to the package.
I think this will block getting some of the TS conversions merged in and published.
@robertrbairdii I came to the same findings on my PR: https://github.com/gatsbyjs/gatsby/pull/22027
It wasn't obvious at first, but lucky there is some prior art in the gatsby-cli
project to look at. It might be worth a ticket to sweep through all the packages to support ts, which will make the files more approachable as a whole
I would love to help out and I don't have any preferences. Can you recommend me some parts to migrate?
@danielkov Seeing by @blainekasten's comment (https://github.com/gatsbyjs/gatsby/issues/21995#issuecomment-595965697), I think you could start in gatsby-core-utils
@MichaelDeBoey I also have my eyes on gatsby-cli/src/structured-errors if nobody else is on it and then move onto gatsby-core-utils
in another PR. Does that sound good?
@danielkov That one's already taken by @LekoArts in #20597
I see #22031 is addressing one of the files of gatsby-core-utils
. Should I wait for that merge, or start independently and resolve conflicts when done?
@danielkov You can just start working on it.
The conflicts can be fixed before merging. 馃檪
@MichaelDeBoey my currently open PRs include all the closed ones at the moment. If you have the time will you double check that this is now correct?
I'd like to work on src/utils/app-data.js
, utils/browserslist
I'd like to work on components/spinner.js
Where are we at with converting plugins to typescript? things like source plugins, manifest, offline, etc...
I'd like to work on
packages/gatsby-cli/src/reporter/loggers/ink/components/messages.js
(edited)packages/gatsby-cli/src/reporter/constants.js
Where are we at with converting plugins to typescript? things like source plugins, manifest, offline, etc...
We're not going to convert those (yet)? As we think it might be harder for people to contribute on those. Gatsby core packages are mostly only managed by us so we think it's worth doing it as it makes our lives easier when working on it.
@blainekasten I'm not 100% sure if we should refactor browser parts like gatsby-link, gatsby-image & our cache-dir. This might lead to bigger bundles.
Hello! I'd like to work on
I'd like to try
packages/gatsby/src/utils/get-cache.js
packages/gatsby/src/utils/get-latest-apis.js
packages/gatsby/src/utils/get-public-path.js
I'd like to try
packages/gatsby/src/utils/get-cache.js
packages/gatsby/src/utils/get-latest-apis.js
packages/gatsby/src/utils/get-public-path.js
@cola119 I suggest you first create a PR for all other files you're working on, so other people can maybe take a look at those file in the meantime if they want.
Just don't think we want to wait for something, when somebody else could work on it
I'll work on stack-trace-utils.js
I'm working on jobs-manager.js
I'll take on src/redux/actions/types.js
I'd like to try packages/gatsby-image/src/index.js
.
redux/actions/restricted.js
also depends on redux/actions/types.js
, so I will take it.
I'm taking care of the /redux
folder on gatsby-cli
on https://github.com/gatsbyjs/gatsby/pull/22292
I'd like to start with packages/gatsby/src/utils/eslint-config.js
- #22294
I'm working on packages/gatsby/src/utils/gatsby-dependents.js
- #22422
I'd love to help with this, @blainekasten. Any suggestions for a first time contributor?
There are quite a few globals/window variables: __BASE_PATH__, ___navigate, ___push, ___replace, __PATH_PREFIX__, ___loader.
If nobody is opposed, @blainekasten, I think I'll try converting babel-plugin-remove-graphql-queries/src/murmur.js
.
@zachtylr21 alright
@parikshitgupta1 Oh, was your previous comment directed at me? I can work on those too, if needed.
If you鈥檙e still looking for help, I鈥檇 love to do what I can. Anything specific you鈥檇 like help converting that hasn鈥檛 been assigned yet?
Hey @AmyShackles thanks for asking, although from my side there's nothing left, although let's see in the thread.
Feel free to take whatever item from that list. We appreciate any PR, no matter if small/easy or big/complicated file :)
Hi @blainekasten I'm sending PRs for:
gatsby
src/load-plugins #22504 gatsby
websocket-manager #22510gatsby-telemetry
#22532gatsby-link
#22563 Some of them are bigger than I hoped, but their dependencies ended up being hard to disentangle.
I would love to contribute! Is there any small/easy file I can start working on? I am still getting familiar with Gatsby :D
I'm here to help. Anyone asking for help specifically or I'll pick one.
@blainekasten
I wanted to give back my 2 cents to community. Last weekend I had to dig deep to gatsby.js codebase, cos I had this annoying issue with type checking in my project: #22070
So I had time on last weekend to start huge refactoring. I have no time to continue now, but I had refactored to typescript gatsby-telemetry gatsby-core-utils and partially other projects.
https://github.com/gatsbyjs/gatsby/pull/22817
I hope it will give some ideas, If needed I can explain my findings and decisions, either here, or on skype: justfly1984
Would like to contribute, any suggestions to where to start?
I'd like to try working on packages\gatsby\src\bootstrap\prefer-default.js
first to get to know more about how things work, if that's okay.
Update: submitted PR https://github.com/gatsbyjs/gatsby/pull/22958
I would really like to contribute! Could I possibly convert packages/gatsby/reducers/themes.js
?
Morning. I'm taking a pass at src/schema/infer/is-file.js
this morning. Something hopefully small to get my head around first!
I'm also having a go at src/schema/infer/inference-metadata
. I think it's nearly done, but trying to add types is giving me a few issues in terms of reachable code.
Added #23093 for is-file
. It's an untested change, so might need a prequel PR to first add tests.
Hello everyone!
Just wanted to drop in and say a HUUUUUUGE thank you! The response from the community has been amazing and (a little) overwhelming 馃槄. But keep it coming! Ya'll are invaluable and speeding up this conversion 100x.
We're making great progress. Let's keep it up!
I made a PR for babel-plugin-remove-graphql-queries/murmur.js
but I'm not sure how to get my name by the file in the description. Can anyone help with that?
@zachtylr21 Done! Thanks for the work. Once you get that PR merged and join the gatsby org you'll be able to do it all by yourself!! :partying_face:
I just noticed that the lint-staged action won't trigger if there are only changes to a TS file: https://github.com/gatsbyjs/gatsby/blob/master/package.json#L78
Hey! Are there any specific issues with src/create-cli.js
in gatsby-cli
? I'd like to take it on if it's ok
Hi锛両 made a PR for gatsby/src/query/redirects-writer.js
. Can any one help me check out in the list?Thanks a lot! BTW, it is my first PR in gatsby, so I am worried about screwing it up. Any advice will help me a lot.
Hi folks! I'm happy to join the effort, and if nobody is currently looking at src/utils/page-data.js
I'm happy to give it a try to start helping :+1:
Hey everyone 馃憢 Just made a small PR for redux/reducers/webpack-compilation-hash
#23439 . Could someone add it to the list please?
If there is nobody on it at the moment, tomorrow I might work on small reducers like redux/reducers/webpack
, redux/reducers/status
(#23474), redux/reducers/static-query-components
(#23475), redux/reducers/schema
(#23476) and so on :)
I would like to contribute with log-line-function.js
to start, ok?
Hi there! 馃憢
I would love to join in! Can I start with the src/bootstrap/remove-stale-jobs.js
at the packages/gatsby
? 馃槃
~Just checked the file list; the PR for gatsby/src/utils/page-data.js
(#23436) is missing~
(just saw I can update the list myself now, thanks!)
And I just pushed the gatsby/src/utils/webpack.ts
migration (#23566)
I'll do packages/gatsby/src/redux/reducers/config.js
(as part of some fixes)
@moonmeister Thanks for doing that! I should probably mention that the PR number for murmur.js
is #22458, if you want to put that next to my name as well.
Had a small issue with my fork so I had to close #23476 and open #23591 instead.
Same code, but new PR to review. Sorry for that.
Also this one should be ready for review (fixed last conflict with current master
): #23436
I have a migrated gatsby/src/utils/tracer/jaeger-local
ready to push up, but on reading the docs it seems like the file is there as an example for someone to feed back into gatsby, not as a part of the application itself. If it were to be migrated, and the documentation updated to point to the TS file instead, would feeding that file into gatsby as config still work?
I realise I could try and setup a jaeger instance to try it, but also someone more knowedgeable might answer it in far less time! :)
@chooban In the documentation we point to dist
directory. dist
directory will be javascript file (compiled from typescript) - so this should be fine and the documentation won't need changes. It will be good to verify that those config files work correctly, but other than that - it should be fine!
Hello 馃憢 May I start with page-hot-reloader.js
?
I'm excited to help migrate Gatsby to Typescript
Hi folks!
I'd like to contribute too. Can I start with src/schema/types/pagination.js
?
@alisson-suzigan Hi bro, I'm happy to see you here 鉂わ笍
I will take the file src/commands/build.js
wish me luck 馃
Hey folks!
I'm currently working on gatsby/src/reducers/program.js
and I have a series of questions.
At the moment, it seems like there is a lot of elements from the js
source file that is not matching the interface described in IGatsbyState
.
It should welcome an IProgram
object, but there seems to have a series of lacking elements.
In the JS file, the state
is initialized with a state
prop that I can't find in the IProgram
interface. I replaced it with status
, that might be a typo.
But then, the SET_PROGRAM_EXTENSIONS
action is setting an extensions
prop that is not at all existing in the IProgram
interface. Do you have an idea what would be its content?
Also, what's mandatory does not seem to match what's initialized.
@blainekasten: would you have more insight in this interface? It seems like you created it. I'm happy to have a quick chat on Discord if it's easier :)
Hi there,
Now I'd like to work in these files:
packages/gatsby/src/redux/reducers/index.js
packages/gatsby/src/redux/reducers/nodes.js
packages/gatsby/src/redux/reducers/last-action.js
Is that ok?
Hi! I'd like to work on 馃檶
packages/gatsby/src/schema/types/sort.js
I investigated these files( /babel-loader-helpers.js
and
/babel-loader.js
) can be migrated,
But it's likely to be hard because babel-loader doesn't provide their type.
src/utils/profile.js
is in the list but the contents of the file are entirely commented out. I could push up a PR to delete it? ;)
I'd like to finish the package I was working on and convert babel-plugin-remove-graphql-queries/src/index.js
Added #23823 for source-nodes.
I will take the file src/create-cli.js
@devrchancay Hey! Sorry for the confusion, but I've already done some initial work on it https://github.com/gatsbyjs/gatsby/pull/23650, but you can join in on it by all means
okay no problem i will take something else 馃
It is good that many of us are contributing
I'll work on gatsby-cli/src/reporter/loggers/ipc/index.js
!
Hi
I would like to work on gatsby/src/query/queue.js
@hiwelo Still working on gatsby/redux/reducer/component.js
?
I've worked on page-component
and it is quite related, let me know if I can help.
@Kornil I am not working in gatsby/redux/reducer/component
. Afaik, this file is not assigned at the moment :)
(I worked on gatsby/redux/reducer/static-query-components
, but I don't recall having a look at this one at all so far)
I'd love to start contributing! I can pick up gatsby\packages\gatsby\src\redux\reducers\page-data-stats.js
to get my feet wet.
I'm gonna attempt gatsby's babelrc.js reducer
I can pick up nodes-touched
and nodes-by-touch
reducers.
@alisson-suzigan I've done gatsby-cli/src/reporter/loggers/json/index.js
PR #24140 but I forgot to add my name in the list. I'm sorry about that
Hey @carrotderek I've seen you assigned yourself to schema-customization
, I just did it, didn't see your name there sooner, forgive me.
Taking requires-writer.js
from gatsby
Huge milestone! gatsby-cli
is 100% converted to TypeScript! Thank you everyone for your incredible work 馃挏馃挏馃挏
since some files are referenced from the docs: should also a link change in docs also considered include an PR?
Happy to take a stab at the program reducer (src/redux/reducers/program.js
). See #24941
i see this PRs are merged, but files are still unchecked:
index.js (@ascorbic in #24816)
queue.js (@chooban in #25389)
date.js (@sasurau4 in #22430)
derived-types.js (@sasurau4 in #22442)
just a suggestion. how about use https://github.com/airbnb/ts-migrate ?
One of the comments (hi, @pvdz!) I had on a PR a little while back was to use Array<string>
instead of string[]
to bring things in-line with Map, Set, etc. We ended up going in the same direction on a work project, and I wrote a codemod to do the work for me.
Has that style decision been formalised, and would you like a PR to change them all over at once?
@chooban Actually, yes :) But the lack of a codemod made it a little harder.
Does your codemod happen to come with a lint rule to prevent future regressions? Can you post the codemod?
function transform(file, api) {
const j = api.jscodeshift
const root = j(file.source)
root
.find(j.TSTypeAnnotation, {
typeAnnotation: {
type: 'TSArrayType',
},
})
.replaceWith(p => {
return j.tsTypeAnnotation(
j.tsTypeReference(
j.identifier(
'Array'
),
j.tsTypeParameterInstantiation([p.node.typeAnnotation.elementType])
)
)
})
return root.toSource()
}
module.exports = transform
module.exports.parser = 'tsx'
This is what I came up with. It's the second codemod I've written, so if anyone looks at it and thinks "why is it so complex?" then I'd love some pointers!
There's no lint rule yet, but it doesn't look like it would be too difficult to do. 馃 I'll see if I can get one of those written as well.
Turns out there's already a rule for it, and it's fixable: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md It's also more accurate than my codemod. Interesting. I'll need to run some of these other fixes in our codebase in the AST Explorer to see why I missed them.
I've added #26738.
How can I help?
Would like to take a stab at packages/gatsby/src/utils/api-node-helpers-docs.js and /packages/gatsby-link/src/parse-path.js
packages/gatsby/src/utils/profile.js seems like a pointless change although could just update the extension while i was on other things
@LekoArts @blainekasten I would like to work on these
packages/gatsby/src/schema/schema-composer.js
packages/gatsby/src/schema/types/type-defs.js
as i am new to typescript I will start with these files.
Thanks !
I'm sorry if anyone wants to take src/redux/actions/public.js
(@jlkiri in #22274) - you can take it - I might not have free time to finish it for a while.
I鈥檓 down to try refactoring gatsby/src/bootstrap/page-hot-reloader.js
I might have jumped a gun but I quickly refactored the gatsby-link/src/parse-path.js and test. Pr can be seen here:
https://github.com/gatsbyjs/gatsby/pull/27264
I'll help with load-themes/index.js
.
I want to work with gatsby/packages/gatsby/src/schema/schema-composer.js
@khushijindal There's already a PR open for it :) https://github.com/gatsbyjs/gatsby/pull/27241
Please look at previous comments and the PRs so that y'all don't work on the same things :) Thanks for all the contributions!
@khushijindal There's already a PR open for it :) #27241
Please look at previous comments and the PRs so that y'all don't work on the same things :) Thanks for all the contributions!
Actually, it was not marked in the above file that is why. Cool, I'll look for something else XD.
Hey i'll be happy to help with the migration of gatsby/src/query/query-watcher.js
Would love to pick something up if it鈥檚 not already taken. Feel free to assign me whatever is free!
Id be delighted to help with this, but this would be one of my first open source contributions and I'm not sure where to start. Is there still some potentially low-hanging fruit available?
@LinnJS and @neobats : feel free to claim any file listed above that doesn't have a name against it. Just add a comment here saying you're working on it, like @ArcaneDiver did.
Tips to get involved: first read the contribution docs, and see how to set up your local environment. Read the instrcutions in this issue for a guide on our TypeScript code style. After you've claimed the file to work on, convert it locally and ensure there are no 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!
The node-interface.js
file was already migrated and merged in this PR.
I will help with /src/query/file-parser.js
and test
I will take print.js
!
I'll work on /src/query/graphql-errors.js
Hey, I would like to work on src/query/query-compiler.js
Hey, I would like to work on /api-node-helpers-docs.js
:)
Hi, I'll take on bootstrap/load-themes/index.js
I'll work on src/schema/node-model.js
and src/schema/schema-composer.js
I'll work on src/schema/index.js
and src/schema/infer/index.js
.
Also, src/schema/schema.js
is checked as done but the associated PR doesn't actually type the file (just changes one line so it works for a different typed file)
Hi, I'd like to work on packages/gatsby/src/utils/babel-loader.js
.
Hey @davad I was already working on schema-compose.js here https://github.com/gatsbyjs/gatsby/pull/27241 . Thanks !
Hey @LekoArts I would like to work on gatsby/src/utils/webpack.config.js
Thanks.
Hey @LekoArts @ascorbic I need some help here https://github.com/gatsbyjs/gatsby/pull/27241 I am not sure what is breaking in circleci, can you point me where is the issue. Thanks !
Are either src/utils/api-runner-node.js
or src/utils/api-node-helpers-docs.js
open?
I would like to work on one of them if they are.
I will work on packages/babel-preset-gatsby/index.js + test
Most helpful comment
Huge milestone!
gatsby-cli
is 100% converted to TypeScript! Thank you everyone for your incredible work 馃挏馃挏馃挏