-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat: add typescript support #767
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
Conversation
This pull request is being automatically deployed with Vercel (learn more). |
a4f165f
to
80eff96
Compare
Welcome to the long line of people that have and will continue to try and convince me to use TS for OSS libraries :) I hope it works this time! Here's my standard thoughts when it comes to TS and more or less my requirements for migrating to TS:
With all that said, I am open to it. I can't give any guarantees that I won't smash my computer in a TS rage and put it off for another year... but I'm willing to try. Thoughts? |
Hope it works out too let’s see ;) I think your requirements make sense and I actually agree to all of them. It should definitely be a gradual process while keeping everything backwards compatible, including the current type definitions. This gives us time to work on the internal typings without affecting anyone. At some point the new types could be published as breaking change, or removed if it does turn out to be too difficult. Because transpilation is still done with Babel, and TypeScript is only used as advanced linter, it should be pretty easy to revert if needed. This setup at least gives us the possibility to try without much risk. How would you like to proceed with this? |
I think the best way forward would be to start "migrating" the types from the type definitions into the primitive-ish interfaces of the library. Queries, instances, caches, etc. Not really focus on typing all of the functions and what not yet, but just working on all of the different versions of the objects and interfaces, all with the primary goal of just not touching any of the original source code other than simply adding type references to the objects going in and out. Sure, there will be tons of errors at that point. But once it's done, that will be a good point to know if and how much the library actually needs to change logically to accomodate the types. If it's only a little, we'll make the changes and stay non-breaking :) If it's a lot, then we'll just have to discuss on how to go forward (complex types, a breaking rewrite, etc). But I think ingesting as much of the type definitions as possible and seeing what's left will be a good start. |
80eff96
to
b746396
Compare
b746396
to
17e5ae6
Compare
Run into anything tricky yet? |
17e5ae6
to
5cb64f8
Compare
5cb64f8
to
d17b335
Compare
I managed to get almost everything typed while fixing some bugs along the way. The tricky parts are these:
A possible solution would be to create specific queries like What do you think of the MR? The types might not be 100% yet, but they could be refined along the way as they are not exposed yet. |
Nothing jumped out at me on my initial pass through. Moving to classes was interesting... but I realize that they might be easier to type than object closures. I really dislike classes, but if that's a necessary change, then I think I can live with it. |
d17b335
to
05ef597
Compare
05ef597
to
f90605b
Compare
f90605b
to
470e3a2
Compare
470e3a2
to
a8e94bf
Compare
a8e94bf
to
bb90bec
Compare
It is mostly to keep the types simple for other contributors but also for library consumers who want to define the error type or create their own hooks. Personally I don't have a strong opinion on it though it is open for discussion. The impact on keeping this functionality can be seen here: boschni@0ff7972 |
7e47bf5
to
bedb0f2
Compare
bedb0f2
to
34aabe5
Compare
Hi @boschni , I was wondering if we want to rename the types etc. in core which are prefixed with React (eg. |
34aabe5
to
78c0987
Compare
Hi @ayush987goyal , I think eventually the When creating a separate The actual logic around suspense could then hopefully be implemented within |
78c0987
to
4b85d8b
Compare
4b85d8b
to
819ca04
Compare
819ca04
to
699131f
Compare
699131f
to
0ee0932
Compare
0ee0932
to
f46f87a
Compare
f46f87a
to
20bbedf
Compare
🎉 This PR is included in version 2.5.7 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hi there! While working on the project as a newcomer I noticed it was challenging at times to know which type of arguments some functions accept, which properties should be available on certain objects or which type a certain value should have.
Some of this information can be gathered from the docs, some of it from the tests, and some of it from the type definition file. But the docs only document the public APIs and are (together with the types) not always in sync with the code. Which means spending time on reading and debugging the code itself, while not knowing for sure what the intended behaviour exactly is.
I think adding types to the code will help people understand the project more easily and provide more confidence when making changes because mistakes can be caught early. It would also reduce the number of type related issues and knowing the project is written in TypeScript can be a selling point for TypeScript users.
This PR is mostly intended to get the discussion going and to see what would be needed to add support for it. At first glance not much is needed, but there would be some work involved in typing the code and it could potentially uncover some bugs here and there.
Would you be interested in exploring this direction?