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

Single Fetch: useFetcher without generics arg triggers TS error instantiation is excessively deep... #9428

Closed
PhilDL opened this issue May 13, 2024 · 2 comments

Comments

@PhilDL
Copy link

PhilDL commented May 13, 2024

Reproduction

https://stackblitz.com/edit/remix-run-remix-k6ghpy?file=app%2Froutes%2F_index.tsx

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @remix-run/dev: ^2.9.2 => 2.9.2 
    @remix-run/node: ^2.9.2 => 2.9.2 
    @remix-run/react: ^2.9.2 => 2.9.2 
    @remix-run/serve: ^2.9.2 => 2.9.2 
    vite: ^5.1.0 => 5.2.11

Used Package Manager

npm

Expected Behavior

Hi! For better typesafety we should give a loader/action function type parameter to the generic of useFetcher. But we sometimes don't do it, because of laziness or the action is too simple to bother, or nothing is done with the data. In these cases useFetcher (without generics arg) was just behaving normally, silently casting the "data": any.

Actual Behavior

With SingleFetch the definition of useFetcher changed and it seems that we don't have default type parameter anymore:

  export function useFetcher<T extends Loader | Action>(
    opts?: Parameters<typeof useFetcherRR>[0]
  ): FetcherWithComponents<Serialize<T>>;

Would it be possible to have the = any default parameter back?

@dmarkow
Copy link
Contributor

dmarkow commented May 14, 2024

Having the same problem starting a migration to use singleFetch with 2.9.2. If I change from useFetcher() to useFetcher<unknown>() it seems to work fine.

@pcattori
Copy link
Contributor

Should be fixed in 2.12

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