-
-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
suggestion: a default value for createAction with payload and meta #17
Comments
Hi, |
const aNormalAction = actionCreator("normal") aNormalAction(2) Benefits here is we can create a simple action without repeating (...) => ({type: ..., payload: ...}) |
Ah ok, so you basically want an escape hatch for a payload with type |
What? No, I don't want "any" either. I want to provide a type parameter to actionCreator, and then a typed function is return, like this function actionCreator<Payload, Type extends string>(type: Type, creatorFn: (payload: Payload) => ({ type: Type, payload: Payload }) = payload => ({ type, payload })) |
With this approach, I can get a typed action but without provide a creatorFn (well, this is for simple actions) |
Ok but what you want to do is technically impossible, if you don't provide a payload type when invoking a higher order function how type inference is supposed to get the payload type? EDIT: Please note that this library is against requiring the consumer to fill any generics type parameters in the API. |
@Jack-Works At least IMO there shouldn't be with the current API because that would be breaking change, maybe we could think about adding a new API but it should be generic enough to handle most of possible use cases, because I don't want to end up with a separate creator for each use case. |
Also I can see that the type string literal will lose it's type (and become |
Yes... If modify createAction directly to support explicit |
I'm about to experiment if it would be possible to infer the |
There should be a
The text was updated successfully, but these errors were encountered: