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

useFetcher cannot infer type of data if data is an array of objects with data key #5607

Closed
1 task done
wolthers opened this issue Feb 28, 2023 · 2 comments
Closed
1 task done
Labels
bug Something isn't working

Comments

@wolthers
Copy link

wolthers commented Feb 28, 2023

What version of Remix are you using?

1.13.0

Are all your remix dependencies & dev-dependencies using the same version?

  • Yes

Steps to Reproduce

import { useFetcher } from "@remix-run/react";

export default function Component () {
  type MyWronglyInferredResponse = Array<{
    data: {
      key1: number;
      key2: string
    }
  }>
  const wrongFetcher = useFetcher<MyWronglyInferredResponse>()

  if (wrongFetcher.state === "idle" && wrongFetcher.type === "done") {
    wrongFetcher.data
    // ---------- ⬆️
    // (property) data: SerializeDeferred<{
    //     key1: number;
    //     key2: string;
    // }>[]
  }

  type MyCorrectlyInferredResponse = Array<{
    someOtherKeyThanData: {
      key1: number;
      key2: string
    }
  }>
  const correctFetcher = useFetcher<MyCorrectlyInferredResponse>()

  if (correctFetcher.state === "idle" && correctFetcher.type === "done") {
    correctFetcher.data
    // ------------ ⬆️
    // (property) data: SerializeObject<UndefinedToOptional<{
    //   someOtherKeyThanData: {
    //       key1: number;
    //       key2: string;
    //   };
    // }>>[]
  }
}

Expected Behavior

wrongFetcher.data should work as correctFetcher.

Actual Behavior

wrongFetcher isn't inferring the returned data correctly.

I'm almost certain that this change by @jacob-ebey introduced the bug in 1.11.0: https://github.com/remix-run/remix/pull/4920/files#diff-73d5f419b6a2e6f026b68dd66fcf6ac019072255943a18bf69fa94acc2451746R23

@machour
Copy link
Collaborator

machour commented Mar 5, 2023

Probably related to #5211

@machour
Copy link
Collaborator

machour commented Apr 29, 2023

This will be fixed in 1.16.0 🎉
Here's the result with 1.16.0-pre.0:

Screenshot 2023-04-29 at 1 20 48 PM

@machour machour added awaiting release This issue has been fixed and will be released soon bug Something isn't working and removed bug:unverified awaiting release This issue has been fixed and will be released soon labels Apr 29, 2023
@machour machour closed this as completed May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants