TanStack / query

🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
https://tanstack.com/query
MIT License
42.36k stars 2.89k forks source link

preserveSymlinks breaks useQuery return type #7632

Closed dylan-chong closed 4 months ago

dylan-chong commented 4 months ago

Describe the bug

// package.json
{
  "dependencies": {
    "@tanstack/react-query": "5.48.0"
  },
  "devDependencies": {
    "typescript": "5.5.2"
  }

// tsconfig.json
{
    "compilerOptions": {
        "lib": ["dom", "esnext"],
        "preserveSymlinks": true
    }
}

// index.js
import { useQuery } from '@tanstack/react-query';
const { data } = useQuery({ queryFn: () => Promise.resolve(3), queryKey: ['alskdjf'] })
data; // hover this in IDE

with preserveSymlinks true, hovering in IDE shows "const data: QueryObserverResult<TData, TError>". bad type inference with preserveSymlinks false, hovering in IDE shows "const data: number" which is (almost) correct. it should be "number | undefined"

2 problems here, but the first one is the main one

Your minimal, reproducible example

see above

Steps to reproduce

see above

Expected behavior

see above

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

Tanstack Query adapter

None

TanStack Query version

5.48.0

TypeScript version

5.5.2

Additional context

No response

TkDodo commented 4 months ago

works on my machine (same TS version, flag on): Screenshot 2024-06-27 at 14 44 42

could also be an issue with TS 5.5.2

but in any case, I don't think there's any action we can take.