3 ms·
Hi, I'm a Redux maintainer. As my co-maintainer Lenz Weber just said on Twitter: > No other language I know allows us library authors to have that much influe
by acemarke 4y ago
Hi, I'm a Redux maintainer.
As my co-maintainer Lenz Weber just said on Twitter:
> No other language I know allows us library authors to have that much influence on autocomplete and dev experience. We could all just ship mediocre types with some added runtime exceptions, like we are forced to do in other languages - but we see this opportunity and we go for it. We are not forced to do that, it's the same masochistic drive that makes us write the lib in the first place.
We've deliberately done a lot of work internally to make sure that our end users _don't_ have to write very complex types in their app code.
As I mentioned in another comment, the linked `createAction` example is specifically representing an object that looks like `{type: string, payload?, meta?, error?}`, and strongly typing the possible combinations of which fields exist.
The net result here is that depending on how you've defined your reducer and action, when you type `action.` in the editor, you'll get correct autocomplete listing exactly which fields _do_ exist based on this specific action type.
Normal app code won't have to write anything like those types.
- brap 4y agoIn something like Java this could have been solved with method overloading, e.g: ActionWithPayloadAndError createAction(String, Payload, Error) If I understand correctly, overloading doesn’t exist in TS.