ngxs / store

🚀 NGXS - State Management for Angular
http://ngxs.io
MIT License
3.53k stars 400 forks source link

feat(store): improve action decorator types #2158

Closed ConnorUllmann closed 5 months ago

ConnorUllmann commented 5 months ago

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?

The @Action decorator does not enforce that the actions passed to the decorator match the payloads expected by the method it decorates.

A simple example is the following—the below action has a payload { value: string } but the handler expects { value: number } incorrectly. This does not produce an error.

class ActionString {
  static type = 'action1';
  constructor(public value: string) {}
}

...

@Action(ActionString)
handler(context: StateContext<any>, payload: { value: number }) {}

Issue Number: N/A

What is the new behavior?

In the above example, a type error occurs. The case of multiple actions is also handled, requiring that a union of the payloads is accepted by the method.

Does this PR introduce a breaking change?

[ ] Yes
[X] No

This change is likely to introduce type errors, but it is not intended to impact runtime behavior.

nx-cloud[bot] commented 5 months ago

☁️ Nx Cloud Report

CI is running/has finished running commands for commit a9f4ff32f245ff2a24de189ff49c1432d4698a45. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 4 targets - [`nx lint-types store`](https://cloud.nx.app/runs/8pzlIy0WIO?utm_source=pull-request&utm_medium=comment) - [`nx run-many --target=test --all --configuration=ci --maxWorkers=4`](https://cloud.nx.app/runs/blRATQGTRE?utm_source=pull-request&utm_medium=comment) - [`nx run-many --target=lint --all`](https://cloud.nx.app/runs/2VTPYUXB6J?utm_source=pull-request&utm_medium=comment) - [`nx run-many --target=build --all`](https://cloud.nx.app/runs/gd9QXy6IOd?utm_source=pull-request&utm_medium=comment)

Sent with 💌 from NxCloud.

bundlemon[bot] commented 5 months ago

BundleMon (Integration Projects)

Unchanged files (2) Status | Path | Size | Limits :------------: | ------------ | :------------: | :------------: :white_check_mark: | Main bundles(Gzip)
hello-world-ng17/dist-integration/main.(hash)
.js
| 68.5KB | +1% :white_check_mark: | Main bundles(Gzip)
hello-world-ng16/dist-integration/main.(hash)
.js
| 67.03KB | +1%

Total files change -3B 0%

Final result: :white_check_mark:

View report in BundleMon website ➡️


Current branch size history | Target branch size history

codeclimate[bot] commented 5 months ago

Code Climate has analyzed commit a9f4ff32 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 95.3% (0.0% change).

View more on Code Climate.