From 6a72ae11dd368d110c2f9f0052a2e1d2d788bc78 Mon Sep 17 00:00:00 2001 From: Kanthesha Devaramane Date: Wed, 21 Aug 2024 12:50:50 +0100 Subject: [PATCH] BaseControllerV2 metadata is required for all the properties (#4612) ## 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 * Fixes #4252 ## Changelog ### `@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 --- packages/base-controller/src/BaseControllerV2.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/base-controller/src/BaseControllerV2.ts b/packages/base-controller/src/BaseControllerV2.ts index 5cd162548f..00ea682e5f 100644 --- a/packages/base-controller/src/BaseControllerV2.ts +++ b/packages/base-controller/src/BaseControllerV2.ts @@ -51,7 +51,7 @@ export type StateDeriver = (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 = { - [P in keyof T]: StatePropertyMetadata; + [P in keyof T]-?: StatePropertyMetadata; }; /**