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

unstable_data with LoaderFunction using unstable_singleFetch breaks type inference #9970

Closed
0t4u opened this issue Sep 10, 2024 · 1 comment

Comments

@0t4u
Copy link

0t4u commented Sep 10, 2024

Reproduction

https://stackblitz.com/edit/remix-run-remix-qkcaqv?file=app%2Froot.tsx%3AL44

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (32) x64 Intel(R) Core(TM) i9-14900HX
    Memory: 5.18 GB / 31.73 GB
Binaries:
    Node: 20.17.0 - ~\AppData\Local\Volta\tools\image\node\20.17.0\node.EXE
    npm: 10.8.2 - ~\AppData\Local\Volta\tools\image\node\20.17.0\npm.CMD
    pnpm: 9.7.1 - C:\Program Files\Volta\pnpm.EXE
    bun: 1.1.20 - ~\.bun\bin\bun.EXE
Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
npmPackages:
    @remix-run/dev: ^2.12.0 => 2.12.0
    @remix-run/node: ^2.12.0 => 2.12.0
    @remix-run/react: ^2.12.0 => 2.12.0
    @remix-run/serve: ^2.12.0 => 2.12.0
    vite: ^5.4.3 => 5.4.3

Used Package Manager

npm

Expected Behavior

Types of data returned from LoaderFunction should be inferred correctly.

Actual Behavior

Types are being incorrectly inferred by useLoaderData<typeof loader>(), resulting in {}.

@brophdawg11
Copy link
Contributor

This looks like the same issue as #7700. By using const loader: LoaderFunction you are telling TS the return type is the underlying looser type for any loader and prevents TS from inferring the type this specific loader returns.

Using const loader = (args: LoaderFunctionArgs) allows TS to properly infer as does satisfies LoaderFunction.

https://stackblitz.com/edit/remix-run-remix-jfrnfq?file=app%2Froot.tsx

@brophdawg11 brophdawg11 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 11, 2024
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

2 participants