ptol/ts-reducer-creator

Can't use booleans and Enums as payload values

Closed this issue · 2 comments

Thanks for making this project. Using an interface + reducer object to build the action creators is pretty clever.

I tried it out on some of my project's existing reducers and actions and hit some issues with boolean and enum based payload values.

I forked your project and added boolean and enum based values to the react example store

When I try to run the forked code with npm run start, I get the following errors:

ERROR in /Users/mbusby/gits/ts-reducer-creator/examples/react/src/app.tsx
./app.tsx
[tsl] ERROR in /Users/mbusby/gits/ts-reducer-creator/examples/react/src/app.tsx(21,32)
      TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((payload: true) => Action<true>) | ((payload: false) => Action<false>)' has no compatible call signatures.

ERROR in /Users/mbusby/gits/ts-reducer-creator/examples/react/src/app.tsx
./app.tsx
[tsl] ERROR in /Users/mbusby/gits/ts-reducer-creator/examples/react/src/app.tsx(22,32)
      TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((payload: SwitchState.On) => Action<SwitchState.On>) | ((payload: SwitchState.Off) => Action<Swi...' has no compatible call signatures.
ℹ 「wdm」: Failed to compile.

It looks like typescript is treating boolean like true | false, and similar with Enums. Looking at stackoverflow, this might just be a typescript limitation.

I was wondering if you knew of any way to resolve this issue and make the project compatible with boolean and enum values.

ptol commented

Could you try current version?

This seems to fix it! Thanks