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

Surprising type outcome (i.e. compile error) #54

Closed flq closed 5 years ago

flq commented 6 years ago

Hi, in the context of creating custom action creators on top of yours, I have come across this compile-time error which identifies an action to not have a payload property even though the runtime (and my brain compiler) says yes. I have reproed the context over here - https://github.com/flq/ts-react-playground/blob/df7f931be2e052f767e65c2639b1873e201a6708/src/repro/actionsAndReducer.ts#L38 . Not super small but it kind of condenses the situation. The idea is to have a factory which produces the typical actions for REST-call lifecycle, and which can be used multiple times where the isolation scope is introduced by using the meta-property of the actions.

The problem appears to be introduced when a generic type P is introduced for the payload.

I am not sure if this is actually a thing of your library or if this is something to do with Typescript itself, but I hope that maybe you know what is happening.

piotrwitek commented 5 years ago

Sorry no idea, I might only guess it might lack some constraints, as this is the most common reason of widening when using generic type params.

Closing as I'm cleaning up issues backlog.