the-dr-lazy / deox

Functional Type-safe Flux Standard Utilities
https://deox.js.org
MIT License
206 stars 12 forks source link

2.1.2 breaking change on ActionCreator type #128

Closed SantoJambit closed 4 years ago

SantoJambit commented 4 years ago

I have a situation where I need to define the ActionCreator type manually:

export type ShowNotificationAction = Action<typeof SHOW_NOTIFICATION, { type: 'error' | 'success'; labelKey: TranslationKey }>;
export const showNotification: ActionCreator<ShowNotificationAction> = createAction(SHOW_NOTIFICATION,
    (resolve) => (type: 'error' | 'success', labelKey: TranslationKey) => resolve({ type, labelKey }));

This works with 2.1.0, but not with 2.1.2. In 2.1.2, I get this error:

Argument of type 'ActionCreator<{ type: "CORE/SHOW_NOTIFICATION"; payload: { type: "error" | "success"; labelKey: "..." | "...." | ...; }; }>' is not assignable to parameter of type 'ActionCreator<string> | ActionCreator<string>[]'.

Trivia: The reason why I need to do this is because TranslationKey is created via declaration merging and typescript currently has a bug, which expands the keys into the declaration file: https://github.com/microsoft/TypeScript/issues/27171

I.e. instead of generating a type (type: 'error' | 'success', labelKey: TranslationKey) => ..., typescript generates a type (type: 'error' | 'success', labelKey: 'Key1' | 'Key2' | ... | 'KeyN') => ..., which breaks the declaration merging pattern I need in this case. By defining the ActionCreator type manually as seen above, I can avoid this issue.

the-dr-lazy commented 4 years ago

Can you provide a repro? I tried to create a repro but it doesn't throw me any error.

SantoJambit commented 4 years ago

Sure, here it is: https://codesandbox.io/s/xenodochial-dan-dfthl

the-dr-lazy commented 4 years ago

Thank you for reporting it. This issue has been fixed in 2.1.4.

the-dr-lazy commented 4 years ago

:tada: This issue has been resolved in version 3.0.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: