piotrwitek / typesafe-actions

Typesafe utilities for "action-creators" in Redux / Flux Architecture
https://codesandbox.io/s/github/piotrwitek/typesafe-actions/tree/master/codesandbox
MIT License
2.41k stars 98 forks source link

buildAction with a union type payload #23

Closed Methuselah96 closed 6 years ago

Methuselah96 commented 6 years ago

I'm currently using v1.2.0-rc.1 to take advantage of the new TypeScript features. However when I use buildAction to make an action creator with a payload that is a union type I'm running into issues. Here's what my build action looks like:

action: buildAction('ACTION').payload<string | null>(),

When I try to build it gives me a type error:

Error:(117, 14) TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((payload: null) => PayloadAction<"ACTION", null>) | ((payload: string) => PayloadAction<"AC...' has no compatible call signatures.

The same thing happens with booleans, since they are a union of true and false:

Error:(44, 12) TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((payload: true) => PayloadAction<"ACTION", true>) | ((payload: false) => Payloa...' has no compatible call signatures.

This issue on the TypeScript repo might be helpful: https://github.com/Microsoft/TypeScript/issues/4612

piotrwitek commented 6 years ago

@Methuselah96 thanks for reporting, I'll look into it today

piotrwitek commented 6 years ago

@Methuselah96 Ok it's fixed now! Check new release typesafe-actions@1.2.0-rc.4 Please ping me if this is fixed correctly. Thanks

Methuselah96 commented 6 years ago

@piotrwitek It works. Thanks!