Closed jollytoad closed 5 years ago
I think it makes a lot of sense to make Payload
type parameter default to unknown
.
However, AnyAction
still makes sense forisType()
(and ActionCreator.match()
, and ofAction()
), because what they do is narrow the widest type there is with a type
property to an FSA. Imagine if your app had multiple sources of actions — your app itself dispatching FSAs and some third-party library using its own convention. Then it would be incorrect to say that all actions in your store are Action<unknown>
. That's what AnyAction
is — the type of any possible action ever.
I'm going to close this, please feel free to reopen.
I've recently updated to TS3, and although
typescript-fsa@3.0.0-beta-2
isn't currently working for me (reported in a separate issue), i'm continuing to use 2.5.0.I have found that the new
unknown
type is incredibly useful as the payload type of anAction
, especially in combination with redux-observable, and theofAction
operator (see https://github.com/m0a/typescript-fsa-redux-observable/issues/6).With this introduction of
unknown
, and some refactoring it's become clear to me that all of my use case ofAnyAction
should really beAction<unknown>
, and I find I now haveAction<unknown>
appearing all over the place. This is making me think thatunknown
should be the default payload type, and there really is no place forAnyAction
in well typed code.I'm wondering whether it would be appropriate for
Action
type declaration to default its payload type param tounknown
(obviously backwards compatibly would need to be accounted for).This may just be due to my use-cases and usage of redux-observable Epics, and the narrowing effect of the
ofAction
fromAction<unknown>
toAction<P>
. I'm not sure if it would be appropriate for users of thunk, saga, or other non-redux based uses.