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]: Function createApi Types are not Portable #3568

Closed
eric-crowell opened this issue Jun 29, 2023 · 2 comments
Closed

[RTK v2.0]: Function createApi Types are not Portable #3568

eric-crowell opened this issue Jun 29, 2023 · 2 comments
Milestone

Comments

@eric-crowell
Copy link
Contributor

eric-crowell commented Jun 29, 2023

For those experimenting with Redux Toolkit v2 (currently 2.0.0-Beta.0) and must export their own type declarations, there are quite a few issues with the portability of types from Redux Toolkit Query’s function createApi..

(There are also issues with functions like createSlice too, but I haven’t delved as deep into it, so I’m just focusing on createApi right now.)

Using createApi...

import { createApi } from '@reduxjs/toolkit/query';
export const myApi = createApi({ /** ... */ });

results in an error like so…

The inferred type of 'myApi' cannot be named without a reference to '../node_modules/@reduxjs/toolkit/dist/query/core/module.js'. This is likely not portable. A type annotation is necessary. ts(2742)

Significant TypeScript configurations:

{
   "moduleResolution": "Node16",
   "declaration": true,
}

Minimal Example with Error

https://codesandbox.io/p/sandbox/rtk-type-portability-j99lyh?file=%2Fsrc%2Frtk%2FmyApi.ts%3A1%2C1

Note: I believe this error does not occur for a majority of developers using RTK because it's normally included in applications that don’t need compiled declarations (declarations: false in tsconfig.json). This may be why this issue isn’t frequently brought to attention.

@markerikson
Copy link
Collaborator

Done in #3678 .

@markerikson
Copy link
Collaborator

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