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
41.67k stars 2.83k forks source link

Build fails due to Typescript Error - 'QueriesOptions' circularly references itself #3583

Closed kevinnnz closed 2 years ago

kevinnnz commented 2 years ago

Describe the bug

When I'm running npm run build the compiler returns this error:

Type alias 'QueriesOptions' circularly references itself. TS2456

Your minimal, reproducible example

n/a

Steps to reproduce

These are my dependencies in the project:

"dependencies": { "@types/dinero.js": "^1.9.0", "axios": "^0.24.0", "bootstrap": "^4.6.1", "connected-react-router": "6.5.2", "dinero.js": "^1.9.1", "file-saver": "^2.0.5", "history": "4.10.1", "jquery": "^3.6.0", "merge": "1.2.1", "popper.js": "^1.16.0", "react": "16.11.0", "react-dom": "16.11.0", "react-query": "^3.38.1", "react-redux": "7.1.1", "react-router": "5.1.2", "react-router-dom": "5.1.2", "react-scripts": "^3.4.4", "react-toastify": "^8.2.0", "reactstrap": "8.1.1", "redux": "4.0.4", "redux-thunk": "2.3.0", "svgo": "1.3.0", "tabler-icons-react": "^1.47.0", "ts-money": "^0.4.7" }, "devDependencies": { "@types/history": "4.7.3", "@types/jest": "24.0.19", "@types/node": "12.11.6", "@types/react": "16.9.9", "@types/react-dom": "16.9.2", "@types/react-redux": "7.1.5", "@types/react-router": "5.1.2", "@types/react-router-dom": "5.1.0", "@types/reactstrap": "8.0.6", "@typescript-eslint/parser": "^2.34.0", "cross-env": "6.0.3", "eslint": "^6.5.1", "eslint-plugin-flowtype": "^3.13.0", "eslint-plugin-import": "2.18.2", "eslint-plugin-jsx-a11y": "6.2.3", "eslint-plugin-react": "7.16.0", "nan": "^2.15.0", "typescript": "^4.6.4" },

Expected behavior

I'm expecting my project to be built for production.

How often does this bug happen?

Every time

Screenshots or Videos

image

Platform

Windows

react-query version

3.38.1

TypeScript version

4.6.4

Additional context

No response

kevinnnz commented 2 years ago

I've fixed this by using @ts-ignore in the useQueries.d.ts file.


export declare type QueriesOptions<T extends any[], Result extends any[] = [], Depth extends ReadonlyArray<number> = []> = Depth['length'] extends MAXIMUM_DEPTH ? UseQueryOptions[] : T extends [] ? [] : T extends [infer Head] ? [...Result, GetOptions<Head>] : T extends [infer Head, ...infer Tail] ? QueriesOptions<[...Tail], [...Result, GetOptions<Head>], [...Depth, 1]> : unknown[] extends T ? T : T extends UseQueryOptions<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>[] ? UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>[] : UseQueryOptions[];
/**
 * QueriesResults reducer recursively maps type param to results
 */
// @ts-ignore
export declare type QueriesResults<T extends any[], Result extends any[] = [], Depth extends ReadonlyArray<number> = []> = Depth['length'] extends MAXIMUM_DEPTH ? UseQueryResult[] : T extends [] ? [] : T extends [infer Head] ? [...Result, GetResults<Head>] : T extends [infer Head, ...infer Tail] ? QueriesResults<[...Tail], [...Result, GetResults<Head>], [...Depth, 1]> : T extends UseQueryOptions<infer TQueryFnData, infer TError, infer TData, any>[] ? UseQueryResult<unknown extends TData ? TQueryFnData : TData, TError>[] : UseQueryResult[];
// @ts-ignore
export declare function useQueries<T extends any[]>(queries: readonly [...QueriesOptions<T>]): QueriesResults<T>;
export {}; ```
TkDodo commented 2 years ago

Haven't seen that one before. Please show a reproduction in either codesandbox or typescript playground

gosunman commented 2 years ago

In my case, it was fixed when I upgrade typescript version 3 -> 4.

you can check the announcement with a link below. https://github.com/tannerlinsley/react-query/blob/master/docs/src/pages/typescript.md

TkDodo commented 2 years ago

we have different types for ts versions < 3.8. please note that with v4, we will require TS 4.1 or greater:

https://github.com/tannerlinsley/react-query/blob/beta/docs/src/pages/typescript.md