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

data utility does not pass types the same as json #10407

Closed
prescottprue opened this issue Jan 14, 2025 · 7 comments
Closed

data utility does not pass types the same as json #10407

prescottprue opened this issue Jan 14, 2025 · 7 comments

Comments

@prescottprue
Copy link

Reproduction

Follow react-router docs on Form Validation

Notice that the types of useFetcher().data (or useActionData if you use that instead) are any instead of including errors as was done with json

This issue is also described in this discussion

When attempting to do a reproduction in [integration/bug-report-test.ts](https://github.com/remix-run/remix/blob/dev/integration/bug-report-test.ts) I noticed that is still using json instead of data even though json is marked as deprecated

System Info

System:
    OS: macOS 14.6.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 97.42 MB / 18.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.12.0 - ~/.nvm/versions/node/v22.12.0/bin/node
    Yarn: 4.6.0 - ~/.nvm/versions/node/v22.12.0/bin/yarn
    npm: 10.9.0 - ~/.nvm/versions/node/v22.12.0/bin/npm
  Browsers:
    Chrome: 131.0.6778.265
    Safari: 17.6
  npmPackages:
    @remix-run/css-bundle: 2.15.2 => 2.15.2 
    @remix-run/dev: 2.15.2 => 2.15.2 
    @remix-run/express: 2.15.2 => 2.15.2 
    @remix-run/node: 2.15.2 => 2.15.2 
    @remix-run/react: 2.15.2 => 2.15.2 
    vite: 6.0.7 => 6.0.7

Used Package Manager

yarn

Expected Behavior

It is expected that data would correctly type response data as happens with json or if you return an object directly within an action/loader

Actual Behavior

useFetcher().data and useActionData do not correctly contain types when data is used as it did previously with json (now marked as deprecated)

As mentioned this is also described in this discussion

@eliashelleborn
Copy link

I managed to fix the initial problem of the data type being incorrect by doing the following step: https://remix.run/docs/en/main/guides/single-fetch#enable-single-fetch-types

But after that I have another issue:
The inferred type of 'loader' cannot be named without a reference to '.pnpm/@[email protected]/node_modules/@remix-run/router'. This is likely not portable. A type annotation is necessary.ts(2742)

There is an old PR that fixes a similar issue for the json utility, but maybe the same fix needs to be applied for data?
#3797

@brookslybrand
Copy link
Contributor

@eliashelleborn is correct. To use the data() util you have to enable the new types while enabling the single fetch v3 flag

@eliashelleborn
Copy link

@brookslybrand Should I open a separate issue for the other type-error I'm running into? Or do you have ideas on what could cause this. This happens after declaring the Future type.

@brookslybrand
Copy link
Contributor

@eliashelleborn yes, if you can open that with a reproduction that would be very helpful

@douweknook
Copy link

douweknook commented Jan 29, 2025

I am running into the same issue as @eliashelleborn while trying to upgrade remix. When I swap the json helper for data, Typescript returns this error::

The inferred type of 'action' cannot be named without a reference to '.pnpm/@[email protected]/node_modules/@remix-run/router'. This is likely not portable. A type annotation is necessary.

It happens both for actions and loaders where I swap the helper. Any way to fix this?

@brookslybrand
Copy link
Contributor

@douweknook if there's not already an issue open will you please open one with a reproduction?

@eliashelleborn
Copy link

I've tried to reproduce this in the StackBlitz without success so far unfortunately 😕

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

4 participants