Skip to content

Commit 2458c4e

Browse files
committed
Use Partial instead of RecursivePartial for persisted state
The current state metadata takes an all-or-nothing approach to persisting each state property. There is no mechanism for omitting nested properties from the persisted state. As such, `Partial` is a better description of the return type than `RecursivePartial`.
1 parent 339818f commit 2458c4e

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/BaseControllerV2.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,12 @@ export function getAnonymizedState<S extends Record<string, any>>(
191191
* @param metadata - The controller state metadata, which describes which pieces of state should be persisted
192192
* @returns The subset of controller state that should be persisted
193193
*/
194-
export function getPersistentState<S extends Record<string, any>>(
195-
state: S,
196-
metadata: StateMetadata<S>,
197-
): RecursivePartial<S> {
194+
export function getPersistentState<S extends Record<string, any>>(state: S, metadata: StateMetadata<S>): Partial<S> {
198195
return Object.keys(state).reduce((persistedState, _key) => {
199196
const key: keyof S = _key; // https://stackoverflow.com/questions/63893394/string-cannot-be-used-to-index-type-t
200197
if (metadata[key].persist) {
201198
persistedState[key] = state[key];
202199
}
203200
return persistedState;
204-
}, {} as RecursivePartial<S>);
201+
}, {} as Partial<S>);
205202
}

0 commit comments

Comments
 (0)