Skip to content
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

[react-redux] Should redux's Dispatch be covariant in type #2279

Open
rostero1 opened this issue May 27, 2018 · 5 comments
Open

[react-redux] Should redux's Dispatch be covariant in type #2279

rostero1 opened this issue May 27, 2018 · 5 comments

Comments

@rostero1
Copy link

Current definition is

type Dispatch<A: { type: $Subtype<string> }> = DispatchAPI<A>;

Would this be better as

type Dispatch<A: { +type: string }> = DispatchAPI<A>;

It'd still allow for tagged literals

type Action = { type: "fire", payload: string};
const func = (dispatch: Dispatch<Action>) => { ... }

But also allow me to mark the type as read-only:

type ActionType<T: string, P> = { +type: T, +payload: P };
type Action = ActionType<"fire", string> | ActionType<"forget", string>;

Which I couldn't do with the current definition. I don't know the answer, which is why I'm filing this as an issue instead of a PR.

@AndrewSouthpaw
Copy link
Contributor

cc @villesau

@AndrewSouthpaw AndrewSouthpaw changed the title Should redux's Dispatch be covariant in type [react-redux] Should redux's Dispatch be covariant in type May 31, 2018
@martinschayna
Copy link

Still relevant, because of deprecation warning of utility class $Subtype in Flow 0.98+

@villesau
Copy link
Member

To be honest, I'm not sure what $Subtype<string> actually even means. Maybe it's fine just to remove the $Subtype?

@AndrewSouthpaw
Copy link
Contributor

Where is this happening? I'm not seeing it in redux or react-redux.

@Brianzchen
Copy link
Member

I don't know what the impact of this would be if we changed just one, probably would be better once there's an ability to share types between libdefs

Screen Shot 2022-02-03 at 1 39 03 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants