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

circular references in type-helpers.d.ts using tsc 3.4rc #130

Closed
harrybin opened this issue Mar 19, 2019 · 8 comments
Closed

circular references in type-helpers.d.ts using tsc 3.4rc #130

harrybin opened this issue Mar 19, 2019 · 8 comments

Comments

@harrybin
Copy link

Using tsc 3.4rc a circular reference is detected in type-helpers.d.ts.

tanspiler error message:
_node_modules/typesafe-actions/dist/type-helpers.d.ts
(1,21): Type alias 'ActionType' circularly references itself.

@harrybin harrybin reopened this Mar 19, 2019
@harrybin
Copy link
Author

harrybin commented Mar 19, 2019

suggested solution: (see: microsoft/TypeScript#30483)

export declare type ActionType<ActionCreatorOrMap> = ActionCreatorOrMap extends ActionCreator<StringType> ? ReturnType<ActionCreatorOrMap> : {
    1: ActionCreators<ActionCreatorOrMap[keyof ActionCreatorOrMap]>;
    0: never;
}[ActionCreatorOrMap extends object ? 1 : 0];

type ActionCreators<T> = T extends any ? ActionType<T> : never;

updated/corrected 29.03.

@AustinBrunkhorst
Copy link

Were you able to get the proposed solution to work? I still get the circular reference error with typescript@3.2.4

@fightingcat
Copy link

Sorry for the incorrect code, I recently only use my phone viewing github. This should be working:

export declare type ActionType<ActionCreatorOrMap> = ActionCreatorOrMap extends ActionCreator<StringType> ? ReturnType<ActionCreatorOrMap> : {
    1: ActionCreators<ActionCreatorOrMap[keyof ActionCreatorOrMap]>;
    0: never;
}[ActionCreatorOrMap extends object ? 1 : 0];

type ActionCreators<T> = T extends any ? ActionType<T> : never;

@AustinBrunkhorst
Copy link

@fightingcat that solution is brilliant! I forgot objects were fair game at compile time. TypeScript is pretty neat 👍. Thanks for sharing

@ethanneff
Copy link

ethanneff commented Mar 30, 2019

Typescript 3.4.1 just released. Confirming typesafe-actions breaks with this update.

 FAIL  src/components/Markdown/__tests__/index.tsx
  ● Test suite failed to run

    TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
    src/screens/Debug/screens/Checklists/models/Item/index.tsx:21:27 - error TS2315: Type 'ActionType' is not generic.

     21 export type ItemActions = ActionType<
                                  ~~~~~~~~~~~
     22   | typeof createItem
        ~~~~~~~~~~~~~~~~~~~~~
    ... 
     25   | typeof toggleActiveItem
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~
     26 >;
        ~

Current solution is to revert to "typescript": "3.3.4000"

@pwentz
Copy link

pwentz commented Mar 30, 2019

I'm also running into the same issue @ethanneff is seeing. Looks like TypeScript 3.4.1 breaks ActionType. Looks like the new TS version no longer allows types to circularly reference themselves:

type ActionType<ActionCreatorOrMap> = any
Type alias 'ActionType' circularly references itself.ts(2456)

@piotrwitek
Copy link
Owner

@fightingcat thanks for the suggested solution it looks good 👍
I have published a new version typesafe-actions@3.3.0-rc containing @fightingcat fix.
Updated the codesandbox project and all is working great.

@piotrwitek
Copy link
Owner

piotrwitek commented Mar 31, 2019

Related TS issues:
microsoft/TypeScript#29511
microsoft/TypeScript#30188

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

6 participants