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

[RTK v2.0] createApi (React) exceeds the maximum length the compiler will serialize #3591

Closed
eric-crowell opened this issue Jul 11, 2023 · 3 comments
Milestone

Comments

@eric-crowell
Copy link
Contributor

Version: 2.0.0-beta.0
Hello, I'm having an issue inferring types when using createApi from @reduxjs/toolkit/query/react.

I get this issue with a very minimal setup.

Code Sandbox link

import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";

/**
 * `myApiReact` defaults to the `any` type producing the TypeScript error....
 * The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.ts(7056)
 */ 
export const myApiReact = createApi({
  reducerPath: "myApiReact",
  baseQuery: fetchBaseQuery({
    baseUrl: "/",
  }),
  endpoints: (builder) => ({
    getData: builder.query<{}, string>({
      query: (id) => `data/${id}`,
    }),
  }),
});

I can't find the cause of it yet. Seems like there's some type recursion happening somewhere in enhanceEndpoints when the react module is used? Maybe someone has a better clue.

@markerikson
Copy link
Collaborator

Two questions:

  • Does that happen with 1.9? Don't think we changed any RTKQ types for 2.0
  • Does that happen if you change the {} return type to any other type?

@eric-crowell
Copy link
Contributor Author

eric-crowell commented Jul 11, 2023

Oops! I apologize. I should have added the necessary TypeScript configurations needed to get this issue.

// tsconfig.json
{
  // ...
  "moduleResolution": "Node16", // Or "NodeNext",
  "declaration": true,
  // ...
}

It only occurs with Node16 as the moduleResolution AND if one is exporting declarations; otherwise, there's no issue.

Now that I'm writing it out, it might be similar to #3568 and there's some type that needs to be exported for the new ES6 module stuff.

No changes on using a different type other than {}.

eric-crowell added a commit to amnis-dev/amnis-toolkit that referenced this issue Jul 11, 2023
eric-crowell added a commit to amnis-dev/amnis-toolkit that referenced this issue Jul 11, 2023
@eric-crowell
Copy link
Contributor Author

I think this pull request resolves the issue: #3592

It did fix it for me.

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

2 participants