Closed anilanar closed 4 years ago
This looks like as a design limitation in TypeScript.
I don't see anyway to infer polymorphic action type.
declare const foo: <S extends string>(s: S) => { type: 'FOO', payload: S }
type Action = ReturnType<typeof foo> //=> any
@anilanar do you have any idea?
You are right @the-dr-lazy, it's currently not possible.
I have created an action such as:
The action type is correct, the output function has the correct generic constraints and types.
However, using such an action creator with
createReducer
causes type of action to benever
in the handler function.This is a simplified version of the actual use case. We really do use polymorphic actions in a useful way.