remix-run / remix

Build Better Websites. Create modern, resilient user experiences with web fundamentals.

Home Page:https://remix.run

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

useFetcher return type is `any` since upgrading to remix 2.9.0

nejsimon opened this issue · comments

Reproduction

  1. Create a new remix app using npx create-remix@latest test-fetcher
  2. 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>
  );
}
  1. Add the following code a route called api.tsx
import { json } from "@remix-run/node";

export function loader() {
  return json({ message: "hello world!" });
}
  1. Check the type of fetcher or fetcher.data, it's any.
  2. 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 property message of type string.

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.

Same problem as #9295 ?

yes - this is a dup of #9295 - will be releasing a patch with a fix soon