Skip to content

NoInfer around TData causes TS error with object type #9937

Description

@jameshoward

Describe the bug

We recently updated @tanstack/react-query to version 5.90.11 and it introduced type errors, we believe related to the change in #8683

We have a map from an enum value to an interface so that we can have generic data loaders with the correct data type returned (simplified example in the attached TS Playground link) and then use that elsewhere to make other functions generic.

We are now getting this TS error:

Argument of type 'NoInfer<DataTypeToEntity[DT]>' is not assignable to parameter of type 'DataTypeToEntity[DT]'.
  Type '[DataTypeToEntity[DT]]' is not assignable to type 'DataTypeToEntity'.

I created a very simple reproduction of the issue with NoInfer that also shows the issue not happening with the built-in NoInfer from TS 5.4 - https://www.typescriptlang.org/play/?#code/KYOwrgtgBAIghgFzgFQJ4AdhQN4CgpQCCAxsQPZggJQC8UA5HKRVfQDT5QAKATmQCZhi1OvXR9Bw+rgC+uXAEsqwHgDMmWEuUrU8BEHAjAAXFADOCHkoDmAblnylCFeuJZeAobs7l+J85Y29nK4wAAe6GQ81AgYWPBIaJjIZACiVAqxtDicANoJKHEAdFosCAC6pqU69gT5iIWYRR6SFaYtXg64APTdUMgAFgpmUMNQCANYsZhQqnzQAEoAirjTWAByZACSIKoqAEwAPMgAfNm5yOUXUOHOIPwjcCCoUAD8UAAMUKYgwABuKnK9lw5BAFnGwHBdEOMGQNzCdwesAaSWAJwAFPwUXFTLC2FAsUhTJsdnseDDsck0hlYvlLicAJS0M56KCg8FwMxmBTWX78XGU4ApdIITKoOnlbKEuDBeTsmKQhD7bIwuG3UBIgqojHS1G45D46XE7a7A4UxJxYU08Ww8qM5k5AjyqCc7m84D85EWqkisUSqUNYJAA

Also doesn't seem to happen with a simpler type NoInfer<T> = [T] extends [T] ? T : never approach.

I know this is very much an edge-case but I'm struggling to find a workaround other than casting or passing generics into useQuery, neither of which are ideal.

Your minimal, reproducible example

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgVwM4FMCKz1QJ5wC+cAZlBCHAOQACMAhgHaoMDGA1gPRTr2swBaAI458VANwAoSZ05wAyqDAAbYCWDoAJnHSNkIVHAgk4MABbo4m+g1N4w6Q+csBBAAoBJOKmRhIsVAA6SV19OAARG3oAFXtLBEk4OBdWVghkRngAXmo+NIyYKgAaRLg3ck1kfjgcqjAKqsLJQmlZOGiAdwhvJVV1LTgeVEhmSxg4oOlgTNwSPldU9MzEUsZ6EHQALm8YKGmAcykWyWmYWfmyhuqEpLTNLZ29xkPm1rkAWXowJwsrKLsHKZus5Bo4RhgAZZ0AAPBz8LTBGH+eDjQGRBixBzRCAAUUywHGNRWSQA2uiYnFAil8pkALrbalLGBSUnkzHoQLlCCVfj0y7cxqvGRyRTgPoabT7XS4YCsODKCD0e5QUxmGygmDIKDMOBMIwAIwAVuhqh0zBAIajLMBDPr6BhtBBGKrrYwwMh4GB6FB1ugzlBgmlmPApTByUT7XhGHKADzhaI6aFnRiaQxsuIAPgAFNYMXFtvGAJTbLkgG3oONRdnYvEwAl4MnRWkZmotm7eDoE1hmOA5qtxQvEpJwVj2yzphxUxYFTalYcarXOpBrDbbKiMgpUIi6tP9rG4-HjRu0lnD0cQiccrk8mCz+cL7WIEfch51ACMW+I9oie-QNcPDbxiepQtMcbQuCgdaqIS5jqmqPyWKgvpwFKjAynKVpOMCjgomquGWAAbvQyg4COer6pY9qoMA+xoZogRwJIQYsChfoADL0BRyhEnGCYwsmqY-nmDjZrmFIOAW0RFH8DAFr+-51keQGDlkbalDwmqPlQZwsBIQqnOcrCWNEOFct8vGJgJu7CegalJGJ7KSUK4FwCAEAcM+4BOrouHqmgjgoBg2C4AQnbmC6rFoXscoKkquDBCQGT8MATrtDhFn8bogmXtmSAOXERDbCZLBmagvEZoO7bMfAeX-MQOT+cF+BZu2SQiCFADS6B4NsJLaThVC0iU87tfgABijDbFmKktqG5J9jZhYgYWUjqX6i72f8AD8rEwBxXELeJ6DSWJg7bHoyjKM0QA

Steps to reproduce

The error is shown at the bottom of the TS Playground link, where we attempt to assign data to a type that should match fine.

Expected behavior

The type should be fine because NoInfer<SomeType> should be able to be assigned to SomeType.

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

@tanstack/react-query: v5.90.11
TypeScript: 5.7.2 (our codebase) / 5.9.3 (TS Playground)

Tanstack Query adapter

None

TanStack Query version

5.90.11

TypeScript version

5.9.3

Additional context

No response

Activity

  1. TkDodo commented on Dec 2, 2025

    @TkDodo
    Collaborator

    I think we can try switching to your simpler version of NoInfer - I don’t see any failing type-tests that we have with that.

    For the next major, we’ll bump the types dependency and use the built-in version.

    Do you want to contribute it?

  2. added theissue type on Dec 2, 2025
  3. jameshoward commented on Dec 2, 2025

    @jameshoward
    Author

    It does seem to cause some errors in packages/query-core/src/__tests__/queryClient.test-d.tsx though, and other popular NoInfer implementations seem to cause errors in one place or another. 🤔

  4. TkDodo commented on Dec 2, 2025

    @TkDodo
    Collaborator

    yeah I just double checked and that implementation doesn’t really do anything. I think this will have to wait until the next major, sorry.

  5. added a commit that references this issue on May 22, 2026
    d423168
  6. danielwaltz commented on May 29, 2026

    @danielwaltz

    @TkDodo I am seeing type issues in my project after updating to the latest release that includes #10593

    NoInfer is now preventing data returned from useQuery from being narrowed. For instance:

    const isMyFirstResult(value: unknown): value is MyFirstResult => { ... };
    
    // queryFn return type is MyFirstResult | MySecondResult
    const { data } = useQuery(...);
    
    // Before:
    const secondResult = isMyFirstResult(data) ? undefined : data;
    //    ^ output type is MySecondResult | undefined
    
    // After:
    const secondResult = isMyFirstResult(data) ? undefined : data;
    //    ^ output type is NoInfer<MyFirstResult | MySecondResult> | undefined

    This breaks usage anywhere the narrowed data is expected when used.

    Let me know if this should be a new issue!

  7. TkDodo commented on May 29, 2026

    @TkDodo
    Collaborator

    @TkDodo I am seeing type issues in my project after updating to the latest release that includes #10593

    NoInfer is now preventing data returned from useQuery from being narrowed. For instance:

    const isMyFirstResult(value: unknown): value is MyFirstResult => { ... };

    // queryFn return type is MyFirstResult | MySecondResult
    const { data } = useQuery(...);

    // Before:
    const secondResult = isMyFirstResult(data) ? undefined : data;
    // ^ output type is MySecondResult | undefined

    // After:
    const secondResult = isMyFirstResult(data) ? undefined : data;
    // ^ output type is NoInfer<MyFirstResult | MySecondResult> | undefined
    This breaks usage anywhere the narrowed data is expected when used.

    Let me know if this should be a new issue!

    please open a new issue with a typescript playground if possible that shows the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions