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 alias 'ExcludeFromTuple' circularly references itself. #2462

Closed
srinivasan-ayyasamy opened this issue Jun 27, 2022 · 12 comments
Closed

Comments

@srinivasan-ayyasamy
Copy link

srinivasan-ayyasamy commented Jun 27, 2022

We are trying to use redux-toolkit in our stencil js, typescript project. Once we import the createAsyncThunk , I'm getting the below error.

[51:07.6] transpile started ...
[51:08.8] transpile finished in 1.20 s

[ ERROR ] TypeScript: ../../node_modules/@reduxjs/toolkit/dist/tsHelpers.d.ts:43:21
Type alias 'ExcludeFromTuple' circularly references itself.

 L42:  export declare type IsUnknownOrNonInferrable<T, True, False> = AtLeastTS35<IsUnknown<T, True, False>, IsEmptyObj<T, True, IsUnknown<T, True, False>>>;
 L43:  export declare type ExcludeFromTuple<T, E, Acc extends unknown[] = []> = T extends [
 L44:      infer Head,

[ ERROR ] TypeScript: ../../node_modules/@reduxjs/toolkit/dist/tsHelpers.d.ts:46:5
Type 'ExcludeFromTuple' is not generic.

 L45:      ...infer Tail
 L46:  ] ? ExcludeFromTuple<Tail, E, [...Acc, ...([Head] extends [E] ? [] : [Head])]> : Acc;
 L47:  declare type ExtractDispatchFromMiddlewareTuple<MiddlewareTuple extends any[], Acc extends {}> = MiddlewareTuple extends [infer Head, ...infer Tail] ? ExtractDispatchFromMiddlewareTuple<Tail, Acc & (Head extends Middleware<infer D, any> ? IsAny<D, {}, D> : {})> : Acc;

[ ERROR ] TypeScript: ../../node_modules/@reduxjs/toolkit/dist/tsHelpers.d.ts:47:14
Type alias 'ExtractDispatchFromMiddlewareTuple' circularly references itself.

 L46:  ] ? ExcludeFromTuple<Tail, E, [...Acc, ...([Head] extends [E] ? [] : [Head])]> : Acc;
 L47:  declare type ExtractDispatchFromMiddlewareTuple<MiddlewareTuple extends any[], Acc extends {}> = Middlewa
 L48:  export declare type ExtractDispatchExtensions<M> = M extends MiddlewareArray<infer MiddlewareTuple> ? ExtractDispatchFromMiddlewareTuple<MiddlewareTuple, {}> : M extends Middleware[] ? ExtractDispatchFromMiddlewareTuple<[...M], {}> : never;

[ ERROR ] TypeScript: ../../node_modules/@reduxjs/toolkit/dist/tsHelpers.d.ts:47:152
Type 'ExtractDispatchFromMiddlewareTuple' is not generic.

 L46:  ] ? ExcludeFromTuple<Tail, E, [...Acc, ...([Head] extends [E] ? [] : [Head])]> : Acc;
 L47:  uple<MiddlewareTuple extends any[], Acc extends {}> = MiddlewareTuple extends [infer Head, ...infer Tail]                                                                                                              
 L48:  export declare type ExtractDispatchExtensions<M> = M extends MiddlewareArray<infer MiddlewareTuple> ? ExtractDispatchFromMiddlewareTuple<MiddlewareTuple, {}> : M extends Middleware[] ? ExtractDispatchFromMiddlewareTuple<[...M], {}> : never;

[ ERROR ] TypeScript: ../../node_modules/@reduxjs/toolkit/dist/getDefaultMiddleware.d.ts:26:36
Type 'ExcludeFromTuple' is not generic.

 L25:      serializableCheck: true;
 L26:  }>(options?: O) => MiddlewareArray<ExcludeFromTuple<[ThunkMiddlewareFor<S, O>], never>>;
 L27:  export declare function curryGetDefaultMiddleware<S = any>(): CurriedGetDefaultMiddleware<S>;

[51:08.8] build failed in 1.22 s

error Command failed with exit code 1.

@phryneas
Copy link
Member

Which TypeScript version are you using?

@Ramchandirane
Copy link

I am getting the same error when upgrading existig application from redux core to RTK

ERROR in [at-loader] ./node_modules/@reduxjs/toolkit/dist/utils.d.ts:12:127
TS1256: A rest element must be last in a tuple type.

ERROR in [at-loader] ./node_modules/@reduxjs/toolkit/dist/utils.d.ts:13:130
TS1256: A rest element must be last in a tuple type.

ERROR in [at-loader] ./node_modules/@reduxjs/toolkit/dist/utils.d.ts:14:128
TS1256: A rest element must be last in a tuple type.

ERROR in [at-loader] ./node_modules/@reduxjs/toolkit/dist/utils.d.ts:15:131
TS1256: A rest element must be last in a tuple type.

ERROR in [at-loader] ./node_modules/@reduxjs/toolkit/dist/tsHelpers.d.ts:43:21
TS2456: Type alias 'ExcludeFromTuple' circularly references itself.

ERROR in [at-loader] ./node_modules/@reduxjs/toolkit/dist/tsHelpers.d.ts:45:5
TS2574: A rest element type must be an array type.

ERROR in [at-loader] ./node_modules/@reduxjs/toolkit/dist/tsHelpers.d.ts:46:5
TS2315: Type 'ExcludeFromTuple' is not generic.

ERROR in [at-loader] ./node_modules/@reduxjs/toolkit/dist/tsHelpers.d.ts:46:32
TS1256: A rest element must be last in a tuple type.

ERROR in [at-loader] ./node_modules/@reduxjs/toolkit/dist/tsHelpers.d.ts:47:14
TS2456: Type alias 'ExtractDispatchFromMiddlewareTuple' circularly references itself.

ERROR in [at-loader] ./node_modules/@reduxjs/toolkit/dist/tsHelpers.d.ts:47:135
TS2574: A rest element type must be an array type.

ERROR in [at-loader] ./node_modules/@reduxjs/toolkit/dist/tsHelpers.d.ts:47:152
TS2315: Type 'ExtractDispatchFromMiddlewareTuple' is not generic.

ERROR in [at-loader] ./node_modules/@reduxjs/toolkit/dist/tsHelpers.d.ts:48:103
TS2315: Type 'ExtractDispatchFromMiddlewareTuple' is not generic.

ERROR in [at-loader] ./node_modules/@reduxjs/toolkit/dist/tsHelpers.d.ts:48:186
TS2315: Type 'ExtractDispatchFromMiddlewareTuple' is not generic.

ERROR in [at-loader] ./node_modules/@reduxjs/toolkit/dist/tsHelpers.d.ts:48:222
TS2574: A rest element type must be an array type.

ERROR in [at-loader] ./node_modules/@reduxjs/toolkit/dist/getDefaultMiddleware.d.ts:26:36
TS2315: Type 'ExcludeFromTuple' is not generic.

ERROR in [at-loader] ./node_modules/@reduxjs/toolkit/dist/getDefaultMiddleware.d.ts:44:34
TS2315: Type 'ExcludeFromTuple' is not generic.

@Ramchandirane
Copy link

Which TypeScript version are you using?

The typescript version is 4.3

@Ramchandirane
Copy link

It works in RTK 1.7.0 wihtout any issues

@markerikson
Copy link
Collaborator

markerikson commented Jun 28, 2022

We made changes to the types of configureStore in RTK 1.8.

Just listing errors isn't going to help us debug or understand what's going on, though. At a minimum, we'd need to see an actual repo or CodeSandbox that shows this happening, including the tsconfig.json.

Given that this works fine for our other users so far, it's most likely an issue with your build setup or config somehow.

@phryneas
Copy link
Member

The error messages are pretty bogus, ExtractDispatchFromMiddlewareTuple has always been a type with generic arguments, so this is very weird.

Do you maybe have multiple versions of RTK installed in your project side-by-side?
npm ls @reduxjs/toolkit or yarn why @reduxjs/toolkit

@Ramchandirane
Copy link

Not sure how this works with previous version. I will re assess my tsconfig.json once again to see any errors in my build steps.

@Ramchandirane
Copy link

The error messages are pretty bogus, ExtractDispatchFromMiddlewareTuple has always been a type with generic arguments, so this is very weird.

Do you maybe have multiple versions of RTK installed in your project side-by-side? npm ls @reduxjs/toolkit or yarn why @reduxjs/toolkit

Will it be helpful if I share my build steps and tsconfig files ?

@markerikson
Copy link
Collaborator

@Ramchandirane : yes, like I said above, it would really help if you could share an actual repo+project that demonstrates this happening

@Ramchandirane
Copy link

@Ramchandirane : yes, like I said above, it would really help if you could share an actual repo+project that demonstrates this happening

Sure will get back to you on this. We are not having public repo's. I will figure out a way to set a bolier plate code, like what I have in my current project and share it with the error occurance.

@lindapaiste
Copy link
Contributor

This definitely sounds like a TypeScript versioning issue to me. Rest elements can be at any position in a tuple since TS 4.2. The circular references type issue if I think solved by 3.7.

I know that the Redux package has some built-in support for backwards compatibility with these newer features.

I have a theory about what your problem is. I think that you are running your transpile command with a different version of TS than what is specified in your package.json. If you are initiating the command through an IDE, make sure that the IDE settings have the correct TS version. Related SO answer.

@markerikson
Copy link
Collaborator

I'm going to assume this is a project-specific build issue for now. If you do come up with a totally separate reproduction of the issue and it's still happening, please comment and we can take a look.

@markerikson markerikson closed this as not planned Won't fix, can't repro, duplicate, stale Jul 1, 2022
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

5 participants