Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type bug: Query's createApi throws annotation error when declaration: true #1090

Closed
colemars opened this issue May 25, 2021 · 4 comments
Closed

Comments

@colemars
Copy link
Contributor

colemars commented May 25, 2021

Error:

The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

Reproduced:

RTK example repo with tsconfig updated to set declaration: true
https://codesandbox.io/s/heuristic-ellis-49zgc?file=/src/services/api.ts

@colemars colemars changed the title Type bug: createApi throws annotation error when declaration: true Type bug: Query's createApi throws annotation error when declaration: true May 25, 2021
@colemars
Copy link
Contributor Author

microsoft/TypeScript#43817

may be useful

@kasparkallas
Copy link

kasparkallas commented Sep 8, 2021

I was going to create a new issue but it's too related:
fakeBaseQuery with tsconfig's "declaration": true causes:

TS2527: The inferred type of '***' references an inaccessible 'unique symbol' type. A type annotation is necessary.

To reproduce, just use the fakeBaseQuery example from: https://redux-toolkit.js.org/rtk-query/usage-with-typescript with "declaration": true.

@phryneas
Copy link
Member

phryneas commented Sep 8, 2021

Unless the TypeScript team finally gives a good explanation when & why exactly those errors occur and how to prevent them (apart from exporting every single type, which is not a valid solution) I'm sorry there is not much we can do about that.

@kasparkallas
Copy link

kasparkallas commented Sep 10, 2021

Unless the TypeScript team finally gives a good explanation when & why exactly those errors occur and how to prevent them (apart from exporting every single type, which is not a valid solution) I'm sorry there is not much we can do about that.

FYI, I copy-pasted fakeBaseQuery implementation into my own codebase, the error(s) went away and everything compiled, including the auto-generated React hooks. I'll update if anything comes up.

EDIT: I had to also export const _NEVER = /* @__PURE__ */ Symbol() which means I changed it to: export const _NEVER = /* @__PURE__ */ Symbol().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants