Skip to content

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

Merged
brandonroberts merged 2 commits into
ngrx:masterfrom
alex-okrushko:not-allowed-check
Jan 10, 2020
Merged

fix(store): allow union of types in props#2301
brandonroberts merged 2 commits into
ngrx:masterfrom
alex-okrushko:not-allowed-check

Conversation

@alex-okrushko

Copy link
Copy Markdown
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

ngrxbot commented Jan 3, 2020

Copy link
Copy Markdown
Collaborator

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

@timdeschryver timdeschryver left a comment

Copy link
Copy Markdown
Member

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 🙂

Comment thread modules/store/src/models.ts
Comment thread modules/store/src/action_creator.ts Outdated
@alex-okrushko

Copy link
Copy Markdown
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