Skip to content

Commit

Permalink
BaseControllerV2 metadata is required for all the properties (#4612)
Browse files Browse the repository at this point in the history
## Explanation

<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->
The StateMetadata type in BaseControllerV2 was intended to require each
state property to have associated metadata. However, currently it
doesn't require metadata for optional fields. This is problematic
because all top-level state properties are expected to have metadata,
and will throw an error at runtime if it's missing.

We should update the StateMetadata type to require metadata for all
properties, including optional properties.

## References

<!--
Are there any issues that this pull request is tied to? Are there other
links that reviewers should consult to understand these changes better?

For example:

* Fixes #12345
* Related to #67890
-->
* Fixes #4252 

## Changelog

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/base-controller`

- **FIXED**: Type of `metadata` in constructor params has been wrapped
in `Required` to make sure metadata required for all properties,
including optional properties.

## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
  • Loading branch information
kanthesha committed Aug 21, 2024
1 parent 0ddfdd6 commit 6a72ae1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/base-controller/src/BaseControllerV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export type StateDeriver<T extends Json> = (value: T) => Json;
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/naming-convention
export type StateMetadata<T extends StateConstraint> = {
[P in keyof T]: StatePropertyMetadata<T[P]>;
[P in keyof T]-?: StatePropertyMetadata<T[P]>;
};

/**
Expand Down

0 comments on commit 6a72ae1

Please sign in to comment.