-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
BaseControllerV2 metadata is required for all the properties #4612
Conversation
@@ -56,7 +56,7 @@ export type AuthenticationControllerState = { | |||
export const defaultState: AuthenticationControllerState = { | |||
isSignedIn: false, | |||
}; | |||
const metadata: StateMetadata<AuthenticationControllerState> = { | |||
const metadata = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can also be fixed with.
const metadata = { | |
const metadata: Required<StateMetadata<AuthenticationControllerState>> = { |
Type has been removed to be inline with other v2 controllers.
Maybe we could update the diff --git a/packages/base-controller/src/BaseControllerV2.ts b/packages/base-controller/src/BaseControllerV2.ts
index bda31c8cb..eb245bb70 100644
--- a/packages/base-controller/src/BaseControllerV2.ts
+++ b/packages/base-controller/src/BaseControllerV2.ts
@@ -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]>;
};
/**
|
Make sense. Included the suggestion in this commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Explanation
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
Changelog
@metamask/base-controller
metadata
in constructor params has been wrapped inRequired
to make sure metadata required for all properties, including optional properties.Checklist