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: Properly merge structs #2512

Merged
merged 3 commits into from
Jun 25, 2024
Merged

fix: Properly merge structs #2512

merged 3 commits into from
Jun 25, 2024

Conversation

FrederikBolding
Copy link
Member

@FrederikBolding FrederikBolding commented Jun 24, 2024

This PR introduces mergeStructs which merges structs, including refinements, which superstructs assign does not do by default. This also fixes a bug where endowment:rpc: {} would not be reported as invalid until attempting to install the Snap.

Fixes #2405

@FrederikBolding FrederikBolding marked this pull request as ready for review June 24, 2024 10:32
@FrederikBolding FrederikBolding requested a review from a team as a code owner June 24, 2024 10:32
Copy link

codecov bot commented Jun 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.40%. Comparing base (d738f7c) to head (95816c3).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2512   +/-   ##
=======================================
  Coverage   94.40%   94.40%           
=======================================
  Files         442      442           
  Lines        9127     9134    +7     
  Branches     1412     1412           
=======================================
+ Hits         8616     8623    +7     
  Misses        511      511           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

* @returns The merged struct.
*/
export function mergeStructs(...structs: Struct<any>[]): Struct<any> {
const mergedStruct = (assign as (...structs: Struct<any>[]) => Struct)(
Copy link
Member

Choose a reason for hiding this comment

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

Why is this type assertion necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm assuming it is caused by the type declarations for Superstruct being overwritten. The type declarations does not contain types for the function with a rest parameter.

Without the cast we get A spread argument must either have a tuple type or be passed to a rest parameter., but everything still works.

Copy link
Member Author

Choose a reason for hiding this comment

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

@FrederikBolding FrederikBolding merged commit 6b2fe2a into main Jun 25, 2024
156 checks passed
@FrederikBolding FrederikBolding deleted the fb/properly-merge-structs branch June 25, 2024 10:53
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.

Snaps CLI should warn or error if “endowment:rpc” object is empty
2 participants