useFetcher return type is `any` since upgrading to remix 2.9.0
nejsimon opened this issue · comments
Simon Strandman commented
Reproduction
- Create a new remix app using
npx create-remix@latest test-fetcher
- Add the following code to the
_index.tsx
route:
import { useFetcher } from "@remix-run/react";
import { useEffect } from "react";
import { loader as apiLoader } from "./api";
export default function Index() {
const fetcher = useFetcher<typeof apiLoader>();
useEffect(() => {
fetcher.load('/api');
}, []);
return (
<div>
The message is: {fetcher.data?.message}
</div>
);
}
- Add the following code a route called
api.tsx
import { json } from "@remix-run/node";
export function loader() {
return json({ message: "hello world!" });
}
- Check the type of
fetcher
orfetcher.data
, it'sany
. - Downgrade to remix 2.8.x by setting all package.json dependencies to "~2.8.0" and it works as expected. Check the type of
fetcher.data
property and it'll be an object with a propertymessage
of typestring
.
System Info
System:
OS: macOS 14.4.1
CPU: (10) arm64 Apple M1 Pro
Memory: 696.36 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
pnpm: 8.2.0 - ~/Library/pnpm/pnpm
bun: 1.1.0 - /opt/homebrew/bin/bun
Browsers:
Chrome: 124.0.6367.62
Safari: 17.4.1
npmPackages:
@remix-run/dev: ^2.9.0 => 2.9.0
@remix-run/node: ^2.9.0 => 2.9.0
@remix-run/react: ^2.9.0 => 2.9.0
@remix-run/serve: ^2.9.0 => 2.9.0
vite: ^5.1.0 => 5.2.10
Used Package Manager
npm
Expected Behavior
The fetcher should have a proper type. The fetcher.data
should be typed according to the loader that's passed as a generic.
Actual Behavior
The type of fetcher.data
is any
so you get no type safety.
Simon Strandman commented
Same problem as #9295 ?
Matt Brophy commented
yes - this is a dup of #9295 - will be releasing a patch with a fix soon