remix: Type of `useLoaderData()` doesn’t get inferred when using Yarn PnP
What version of Remix are you using?
1.19.1
Are all your remix dependencies & dev-dependencies using the same version?
- Yes
Steps to Reproduce
yarn create remixwith default settings (my-remix-app, Just the basics, Remix App Server, TypeScript, runyarn install)cd my-remix-app- Make the following changes:
diff --git a/app/root.tsx b/app/root.tsx index 8cb74a167..ad3a65b41 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -7,13 +7,17 @@ import { Outlet, Scripts, ScrollRestoration, + useLoaderData, } from "@remix-run/react"; export const links: LinksFunction = () => [ ...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []), ]; +export const loader = () => ({ some: "data" }); + export default function App() { + const data = useLoaderData<typeof loader>(); return ( <html lang="en"> <head> yarn set version berryyarn(you should see the message “automatically enabling the compatibility node-modules linker 👍”, a linenodeLinker: node-moduleswill be added to.yarnrc.yml)- When using VSCode: open command panel (
⇧ ⌘ Pon macOS) →TypeScript: Select TypeScript Version…→Use Workspace Version - Observe that the inferred type of
datais still (correctly)SerializeObject<UndefinedToOptional<{ some: string; }>> - Remove
nodeLinker: node-modulesfrom.yarnrc.yml(or change it tonodeLinker: pnp) and runyarnagain. This will remove yournode_modulesfolder and enable the Plug‘n’Play module resolution mechanism - Run
yarn dlx @yarnpkg/sdks vscode - You’ll have to set the VSCode TypeScript version again like in step 6
- Observe that the inferred type of
datais nowSerializeFrom<T>.Cmd+clicking onuseLoaderDatawill go to line 114 incomponents.d.ts:
but it’s not possible to/** * Returns the JSON parsed data from the current route's `loader`. * * @see https://remix.run/hooks/use-loader-data */ export declare function useLoaderData<T = AppData>(): SerializeFrom<T>;Cmd+click further onSerializeFrom.
Expected Behavior
The inferred type of useLoaderData<typeof loader>() remains SerializeObject<UndefinedToOptional<{ some: string; }>> as in step 7
Actual Behavior
The inferred type of useLoaderData<typeof loader>() is SerializeFrom<T> as described in step 11
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 16 (16 by maintainers)
Commits related to this issue
- followed steps outlined in https://github.com/remix-run/remix/issues/6994#issue-1828010686 — committed to nextbook/serialize-from by lensbart 10 months ago
@lensbart Thanks for the tip about the underlying
SerializeFromtype. Looks like this is due to the fact that@remix-run/server-runtimeis a dev dependency. I’ve just opened a PR fixing this: https://github.com/remix-run/remix/pull/7137@markdalgleish Maybe I was confused and did something wrong when posting this message. Using the nightly seems to resolve my initial issue now. Apologies for any time lost.
I don’t have the issue with
Record<string, number>in my main repository, but not sure if that’s relevant since we have a reproduction already.