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

feat(store): ofAction* methods should have strong types #1808

Merged
merged 1 commit into from
May 21, 2022

Conversation

bbarry
Copy link
Contributor

@bbarry bbarry commented Dec 3, 2021

Improving the type definitions of the ofAction pipe operators improves the type of the
rxjs pipe and subscriptions and helps identify bugs in user code.

closes #1807

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[X] 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?

Issue Number: #1807

What is the new behavior?

ofAction* functions now have strong type restrictions (no more any)

Does this PR introduce a breaking change?

[X] Yes
[ ] No

This change may nominally break application code in that it will uncover existing defects in said code where the application is passing types to these functions which will never be matched, or is attempting to use the pipe downstream in a way that can never occur. Every fix will be case specific and involves correcting the action type definition and/or downstream pipe methods.

Other information

Thank you https://github.com/typescript-eslint/typescript-eslint for providing the rule https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-unsafe-argument.md which made me identify a dozen such defects that the changes here also error on.

@splincode
Copy link
Member

@arturovt @markwhitfeld could you see please?

Copy link
Member

@arturovt arturovt left a comment

Choose a reason for hiding this comment

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

I love the change. Thanks @bbarry . Just to ensure that won't be a breaking change, right?

@bbarry
Copy link
Contributor Author

bbarry commented Dec 10, 2021

It depends on what is considered a breaking change.

This change does not introduce any new functionality or have any impact on runtime code at all.

Yet once merged, users running the version post change may find their application fails to compile if they were using these functions in such a way that they already had a defect in their code.

@arturovt
Copy link
Member

It depends on what is considered a breaking change.

This change does not introduce any new functionality or have any impact on runtime code at all.

Yet once merged, users running the version post change may find their application fails to compile if they were using these functions in such a way that they already had a defect in their code.

Well, that is what considered a breaking change if apps will fail to compile.

Copy link
Member

@markwhitfeld markwhitfeld left a comment

Choose a reason for hiding this comment

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

@bbarry I am a BIG fan of this change, and it aligns perfectly with everything else going into the next minor release. We are adding some massive typings improvements 🎉 .
Requested Change: Could you update the changelog in this PR with a description of this improvement?
Also, a question, is there a minimum version of Typescript that is required for these changes?

Regarding the 'breaking change', I think that even though there may be compile failures when users upgrade to this, it is identifying issues that exist in their code. I would class this as a 'fixing change' instead and a welcome improvement in any codebase.
I can't think of a single case where a user might be unhappy that the upgrade has showcased a bug.

@arturovt and @splincode, I would be happy for this to be included in the next minor release as a non "breaking change" if you agree with my logic here?

@splincode
Copy link
Member

I would be happy for this to be included in the next minor release as a non "breaking change" if you agree with my logic here?

I think it's not problem! TypeScript does exactly the same in its minor versions

@bbarry
Copy link
Contributor Author

bbarry commented Mar 6, 2022

Also, a question, is there a minimum version of Typescript that is required for these changes?

I believe the minimum version of typescript for this change is 2.8 but I am unable to test and verify (2.8 is when Exclude<> and Conditional Types were added and the changes here are similar to ones described in the documentation for that release). That said CT are already in use elsewhere in the code (https://github.com/ngxs/store/search?q=infer) so I am thinking nothing has changed?

When using the actions stream and the ofAction* operators, restrict the
parameters of these functions to valid action types and the resulting stream
to the union type of the set of actions supplied to the operators.

Eg, before:

```
this.store.actions.pipe(
  ofActionSuccessful(MyAction1, MyAction2),
  tap((a/* : any */) => { });
```

After:

```
this.store.actions.pipe(
  ofActionSuccessful(MyAction1, MyAction2),
  tap((a/* : MyAction1 | MyAction2 */) => { });
```

This change may identify broken code in downstream applications.

closes ngxs#1807
@bbarry
Copy link
Contributor Author

bbarry commented Mar 6, 2022

@markwhitfeld is that description better?

@markwhitfeld
Copy link
Member

@bbarry Thank you for your updates. Could you add an entry in ./CHANGELOG.md for this update as part of this PR?

@splincode Unfortunately Typescript does not follow strict semantic versioning because they introduce multiple breaking changes in each minor release, so they are not quite a goldens standard 😁 . But, thank you for your vote on this.

I'll wait to hear from @arturovt too. Hopefully he is still ok with all the bombing going on in his city 😭 .

@markwhitfeld
Copy link
Member

PS. @bbarry If you are particularly skilled in TypeScript types magic, then please DM me on Twitter (markwhitfeld) if you would like to help out with some of the other complex aspects of typing in NGXS.

@arturovt
Copy link
Member

arturovt commented Mar 8, 2022

Hey, as I said I love the change and I don't mind considering it as a fix.

@markwhitfeld markwhitfeld merged commit e58cb22 into ngxs:master May 21, 2022
@markwhitfeld
Copy link
Member

Waoh, that the build on master is failing from merging this PR. I see now that the CI checks never ran on this PR. Very strange indeed.
I'll push a fix.

markwhitfeld added a commit that referenced this pull request Jun 8, 2022
This reverts commit e58cb22.
(This has been reverted as part of pushing a patch release out with no new features)
markwhitfeld added a commit that referenced this pull request Jun 8, 2022
This reverts commit 1508fea.
(This has been reverted as part of pushing a patch release out with no new features)
markwhitfeld added a commit that referenced this pull request Jun 10, 2022
This reverts commit edf2aad.
The effectively reinstates the changelog related to #1808 by reapplying
the changes from commit 1508fea.
markwhitfeld added a commit that referenced this pull request Jun 10, 2022
This reverts commit e9e3a6b.
The effectively reinstates the changes related to #1808 by reapplying
the changes from commit e58cb22.
markwhitfeld added a commit that referenced this pull request Jun 10, 2022
)""

This reverts commit eb56df0.
The effectively reinstates the changes related to #1808 by reapplying
the changes from commit 8834f50.
markwhitfeld added a commit that referenced this pull request Jun 10, 2022
)""

This reverts commit eb56df0.
The effectively reinstates the changes related to #1808 by reapplying
the changes from commit 8834f50.
@markwhitfeld markwhitfeld added this to the v3.next-minor milestone Jun 11, 2022
markwhitfeld added a commit that referenced this pull request Aug 8, 2022
This reverts commit e58cb22.
(This has been reverted as part of pushing a patch release out with no new features)
markwhitfeld added a commit that referenced this pull request Aug 8, 2022
This reverts commit e58cb22.
(This has been reverted as part of pushing a patch release out with no new features)
markwhitfeld added a commit that referenced this pull request Mar 29, 2023
@markwhitfeld markwhitfeld modified the milestones: v3.next-minor, v3.8.0 Mar 29, 2023
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Mar 29, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@ngxs/form-plugin](https://github.com/ngxs/store) | dependencies | minor | [`3.7.6` -> `3.8.0`](https://renovatebot.com/diffs/npm/@ngxs%2fform-plugin/3.7.6/3.8.0) |
| [@ngxs/storage-plugin](https://github.com/ngxs/store) | dependencies | minor | [`3.7.6` -> `3.8.0`](https://renovatebot.com/diffs/npm/@ngxs%2fstorage-plugin/3.7.6/3.8.0) |
| [@ngxs/store](https://github.com/ngxs/store) | dependencies | minor | [`3.7.6` -> `3.8.0`](https://renovatebot.com/diffs/npm/@ngxs%2fstore/3.7.6/3.8.0) |

---

### Release Notes

<details>
<summary>ngxs/store</summary>

### [`v3.8.0`](https://github.com/ngxs/store/blob/HEAD/CHANGELOG.md#&#8203;380-2023-03-29)

[Compare Source](ngxs/store@v3.7.6...v3.8.0)

-   Feature: Build packages in Ivy format [#&#8203;1945](ngxs/store#1945)
-   Feature: Add advanced selector utilities [#&#8203;1824](ngxs/store#1824)
-   Feature: Expose `ActionContext` and `ActionStatus` [#&#8203;1766](ngxs/store#1766)
-   Feature: `ofAction*` methods should have strong types [#&#8203;1808](ngxs/store#1808)
-   Feature: Improve contextual type inference for state operators [#&#8203;1806](ngxs/store#1806) [#&#8203;1947](ngxs/store#1947)
-   Feature: Enable warning on unhandled actions [#&#8203;1870](ngxs/store#1870) [#&#8203;1951](ngxs/store#1951)
-   Feature: Router Plugin - Provide more actions and navigation timing option [#&#8203;1932](ngxs/store#1932)
-   Feature: Storage Plugin - Allow providing namespace for keys [#&#8203;1841](ngxs/store#1841)
-   Feature: Storage Plugin - Enable providing storage engine individually [#&#8203;1935](ngxs/store#1935)
-   Feature: Devtools Plugin - Add new options to the `NgxsDevtoolsOptions` interface [#&#8203;1879](ngxs/store#1879)
-   Feature: Devtools Plugin - Add trace options to `NgxsDevtoolsOptions` [#&#8203;1968](ngxs/store#1968)
-   Feature: Form Plugin - Allow `ngxsFormDebounce` to be string [#&#8203;1972](ngxs/store#1972)
-   Performance: Tree-shake patch errors [#&#8203;1955](ngxs/store#1955)
-   Fix: Get descriptor explicitly when it's considered as a class property [#&#8203;1961](ngxs/store#1961)
-   Fix: Avoid delayed updates from state stream [#&#8203;1981](ngxs/store#1981)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4yNC41IiwidXBkYXRlZEluVmVyIjoiMzUuMjQuNSJ9-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1837
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀[FEATURE]: improve types of "ofAction*" functions
4 participants