react-router icon indicating copy to clipboard operation
react-router copied to clipboard

feat: improve the Await props generics

Open GiveMe-A-Name opened this issue 2 years ago • 10 comments

Now, when we use Await in ts project, the type will ignore because the define of Awaitcomponents.

For examples: image

It no good for developer developed in IDE.

we can improve the Await Type System by generics.

e12d4589-fca9-44ad-a9e5-25fef2fd42bd

GiveMe-A-Name avatar May 17 '23 10:05 GiveMe-A-Name

⚠️ No Changeset found

Latest commit: 0c040ff0b443e697d6d7ddab7e6b1def311e9082

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar May 17 '23 10:05 changeset-bot[bot]

Hi @GiveMe-A-Name,

Welcome, and thank you for contributing to React Router!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at [email protected].

Thanks!

- The Remix team

remix-cla-bot[bot] avatar May 17 '23 10:05 remix-cla-bot[bot]

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

remix-cla-bot[bot] avatar May 17 '23 10:05 remix-cla-bot[bot]

Thank you so much! Lots of types can be synced between remix and react-router. I’ll do some more.

fredericoo avatar May 23 '23 14:05 fredericoo

Thank you so much! Lots of types can be synced between remix and react-router. I’ll do some more.

Thank you for your reply. Is there any other MR to improve it?

GiveMe-A-Name avatar May 24 '23 09:05 GiveMe-A-Name

Thank you so much! Lots of types can be synced between remix and react-router. I’ll do some more.

Thank you for your reply. Is there any other MR to improve it?

what's an MR? 😆

We need to make defer and json return the actual values rather than Response and DeferredValue, but that's quite the challenge. And also useLoaderData, useActionData, useRouteLoaderData could benefit from the same generics as in remix

fredericoo avatar May 24 '23 09:05 fredericoo

Thank you so much! Lots of types can be synced between remix and react-router. I’ll do some more.

Thank you for your reply. Is there any other MR to improve it?

what's an MR? 😆

We need to make defer and json return the actual values rather than Response and DeferredValue, but that's quite the challenge. And also useLoaderData, useActionData, useRouteLoaderData could benefit from the same generics as in remix

Sorry, My fault. That means PR.

In GitHub we called it PR(Pull Request) and in GitLab we called it MR(Merged Request). :joy:

As your said, you will do some more work for this problem. Is means it will have an other PR to resolve it?

GiveMe-A-Name avatar May 24 '23 10:05 GiveMe-A-Name

Thank you so much! Lots of types can be synced between remix and react-router. I’ll do some more.

Thank you for your reply. Is there any other MR to improve it?

what's an MR? 😆 We need to make defer and json return the actual values rather than Response and DeferredValue, but that's quite the challenge. And also useLoaderData, useActionData, useRouteLoaderData could benefit from the same generics as in remix

Sorry, My fault. That means PR.

In GitHub we called it PR(Pull Request) and in GitLab we called it MR(Merged Request). 😂

As your said, you will do some more work for this problem. Is means it will have an other PR to resolve it?

Im working on it right now but it's much trickier than I first envisioned! It's all very intertwined: add a generic in one place and it errors out in 10 files. Feel free to implement it yourself too, as I’m finding it difficult to find the time to tackle all the type issues after work hours xd

fredericoo avatar May 24 '23 10:05 fredericoo

Thank you so much! Lots of types can be synced between remix and react-router. I’ll do some more.

Thank you for your reply. Is there any other MR to improve it?

what's an MR? 😆 We need to make defer and json return the actual values rather than Response and DeferredValue, but that's quite the challenge. And also useLoaderData, useActionData, useRouteLoaderData could benefit from the same generics as in remix

Sorry, My fault. That means PR. In GitHub we called it PR(Pull Request) and in GitLab we called it MR(Merged Request). 😂 As your said, you will do some more work for this problem. Is means it will have an other PR to resolve it?

Im working on it right now but it's much trickier than I first envisioned! It's all very intertwined: add a generic in one place and it errors out in 10 files. Feel free to implement it yourself too, as I’m finding it difficult to find the time to tackle all the type issues after work hours xd

Well, maybe I could also give it a try. This is not a serious problem for the developer. It only affects the development experience, so we can work on it during our free time.

GiveMe-A-Name avatar May 24 '23 10:05 GiveMe-A-Name

I just wanted to drop in here and say that in many cases we've specifically avoided adding the generics in React Router that we have in Remix (for things like useLoaderData, etc.) because they've never really been perfect, and are really just a lie to the compiler due to the indirection (and the fact that the types are serialized/deserialized in Remix). We weren't satisfied with them in Remix and didn't want to bring over a less-than-ideal set of generics to RR. Instead, we have ideas to improve on the types in Remix v2 and hopefully improve inference and reduce some of the needs for the generics.

So for now in RR, instead of useLoaderData<typeof loader>() just go with useLoaderData() as typeof loader.

Hopefully this'll all get much cleaner in the future.

brophdawg11 avatar Jul 07 '23 14:07 brophdawg11