remix icon indicating copy to clipboard operation
remix copied to clipboard

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

Open PhilDL opened this issue 9 months ago • 1 comments

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?

PhilDL avatar May 13 '24 11:05 PhilDL

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.

dmarkow avatar May 14 '24 18:05 dmarkow

Should be fixed in 2.12

pcattori avatar Sep 18 '24 02:09 pcattori