Skip to content

Type inference fail to report error on queryFn return if TData is different in onSuccess/generic types #4770

@mbret

Description

@mbret

Describe the bug

If I manually set a type on the generic useQuery<> or on the onSuccess callback typescript will not fail regarding of what is returned by the actual query function. It should fail and prevent returning something wrong when we type the query elsewhere

Your minimal, reproducible example

https://stackblitz.com/edit/vitejs-vite-vspsam?file=src%2FApp.tsx,src%2Fmain.tsx&terminal=dev

Steps to reproduce

Go to https://stackblitz.com/edit/vitejs-vite-vspsam?file=src%2FApp.tsx,src%2Fmain.tsx&terminal=dev and check the code

Expected behavior

typescript should fail

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

all

TanStack Query version

4.20.9

TypeScript version

4.9.4

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions