Skip to content

NoInfer around TData causes TS error with object type #9937

@jameshoward

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

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