You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously when using the json() method we were able to type narrow the loader data properly.
If we just return plain objects, TypeScript is still marking the property as undefined even though it never is. It also contains the other property as possibly that should never be present given the type narrowing.
Tested this with @remix-run/node / @remix-run/react and react-router v7 and the issue is present in both.
I'm using React Router as a...
framework
Reproduction
Previously when using the
json()
method we were able to type narrow the loader data properly.If we just return plain objects, TypeScript is still marking the property as undefined even though it never is. It also contains the other property as possibly that should never be present given the type narrowing.
Tested this with
@remix-run/node / @remix-run/react
andreact-router
v7 and the issue is present in both.https://github.com/AndreSilva1993/single-fetch-type-narrowing -> React Router v7
https://github.com/AndreSilva1993/json-vs-single-fetch-type-narrowing -> remix-run/node and remix-run/react with v3_singleFetch enabled.
System Info
Used Package Manager
npm
Expected Behavior
I would expect the type narrowing to work as expected.
Actual Behavior
The returned object ends up being an union of all possible properties stating that they could be undefined rendering type narrowing unusable.
The text was updated successfully, but these errors were encountered: