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

fix(store): allow union of types in props #2301

Merged
merged 2 commits into from
Jan 10, 2020
Merged

fix(store): allow union of types in props #2301

merged 2 commits into from
Jan 10, 2020

Conversation

alex-okrushko
Copy link
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

Instead of modifying the type of the Creator, it appears to be better to add intersection & NotAllowedCheck where it used.

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

     interface A {
        sameProp: 'A';
      }
      interface B {
        sameProp: 'B';
        extraProp: string;
      }
      type U = A | B;
      const foo = createAction('FOO', props<U>()); // <--- Error

Closes #2300

What is the new behavior?

Allows to take props<U>() where U = A | B.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@ngrxbot
Copy link
Collaborator

ngrxbot commented Jan 3, 2020

Preview docs changes for 7ed56c8 at https://previews.ngrx.io/pr2301-7ed56c8/

Copy link
Member

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments.
Out of curiosity, what's the use case to provide a union type? I would usually say to create a new action, but now I'm interested 🙂

modules/store/src/models.ts Show resolved Hide resolved
modules/store/src/action_creator.ts Outdated Show resolved Hide resolved
@alex-okrushko
Copy link
Member Author

Out of curiosity, what's the use case to provide a union type?

The author of the code is being creative 😎
E.g. a limited list of strings are allowed, e.g. 'A', 'B', 'C' and 'D', which serve as a particular differentiator for the object, lets call it type SomeKind
When one of the kinds would require additional info, such as extraRequiredProp 🙂

See here: https://www.typescriptlang.org/play/index.html#code/C4TwDgpgBAyg9gWwgaQJYDsAmUC8UDkAgvlAD4EBCJ5+AwtQQCL4DcAUGxsBAE4BmAQwDG0AGJw4UAN5Q2UeVADWGTAC4oAUQAewHsOAAeeEjRYANAWIA+dgqgQdegEoQAjgFdUPCJgAKPODB1AGddDABzdgBfDi5eQREoCgEeaVk7ZSx1bSEAG3dMCCNEFBULInwbNhi2UEgoAFV0VDh0XChxSXJknnY2IVbQqAAjdSaWtrwpOQVMtUp8CwB6JagACwFgqAFc3KhgNehA4AmtjFgS00xqjgH0IYEx5tb26YyVdQqzGfkHXQEXB4vD5-IFPgh3ENhtBghBgIsbmwgA

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

Successfully merging this pull request may close these issues.

store: ActionCreator unable to take the union of types in props
4 participants