Type alias 'ExcludeFromTuple' circularly references itself.
See original GitHub issueWe 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.
Issue Analytics
- State:
- Created a year ago
- Comments:12 (3 by maintainers)
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.
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.