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

Add support for an error field to createAction #207

Open
piotrwitek opened this issue Nov 4, 2019 · 2 comments
Open

Add support for an error field to createAction #207

piotrwitek opened this issue Nov 4, 2019 · 2 comments

Comments

@piotrwitek
Copy link
Owner

piotrwitek commented Nov 4, 2019

Is your feature request related to a real problem or use-case?

Add support for an error field to createAction so it is compliant with Flux standard action specification.

This will open the possibility to use typesafe-actions with other solutions or applications that are relying on that pattern.

Describe a solution including usage in code example

  1. How it would work type-wise?
    Most probably an optional error field added to the base Action type:
type Action = {
  type: string;
  error?: boolean;
}
  1. How it would work at runtime?
    I would go with a forced convention by having a payload to be an instance of Error (easy to implement, backward compatible does not change API and I think that's the most popular option)

This would automatically set the error property to true, but also it could allow leveraging conditional types to refine Action type even further to show or hide error property from the action type. That would be the most optimal solution.

Who does this impact? Who is this for?

All users

Describe alternatives you've considered (optional)

Additional context (optional)

Related #108

@ncuillery
Copy link

When I started working with your library, I naturally tried to pass an instance of Error to the createAction and I was secretly hoping that the boolean error was automatically set, but it wasn't.

So when I'm reading this:

I would go with a forced convention by having a payload to be an instance of Error (easy to implement, backward compatible does not change API and I think that's the most popular option)

This would automatically set the error property to true, but also it could allow leveraging conditional types to refine Action type even further to show or hide error property from the action type. That would be the most optimal solution.

I definitely agree 👍

@piotrwitek
Copy link
Owner Author

piotrwitek commented Feb 25, 2020

@ncuillery thanks for your feedback
Part 2) is quite easy so I consider accepting PRs with that part separately.

Part 1) is quite complex and most probably will need my expertise

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

No branches or pull requests

2 participants