diff --git a/lib/Onyx.d.ts b/lib/Onyx.d.ts index 4e7d4327a..0c7fdd319 100644 --- a/lib/Onyx.d.ts +++ b/lib/Onyx.d.ts @@ -1,15 +1,7 @@ import {Component} from 'react'; import {PartialDeep} from 'type-fest'; import * as Logger from './Logger'; -import { - CollectionKey, - CollectionKeyBase, - DeepRecord, - KeyValueMapping, - OnyxCollection, - OnyxEntry, - OnyxKey, -} from './types'; +import {CollectionKey, CollectionKeyBase, DeepRecord, KeyValueMapping, OnyxCollection, OnyxEntry, OnyxKey, NullableProperties} from './types'; /** * Represents a mapping object where each `OnyxKey` maps to either a value of its corresponding type in `KeyValueMapping` or `null`. @@ -210,7 +202,7 @@ declare function multiSet(data: Partial): Promise * @param key ONYXKEYS key * @param value Object or Array value to merge */ -declare function merge(key: TKey, value: PartialDeep): Promise; +declare function merge(key: TKey, value: NullableProperties>): Promise; /** * Clear out all the data in the store diff --git a/lib/types.d.ts b/lib/types.d.ts index 6bb36dae1..c43d06403 100644 --- a/lib/types.d.ts +++ b/lib/types.d.ts @@ -1,4 +1,4 @@ -import {IsEqual, Merge} from 'type-fest'; +import {Merge} from 'type-fest'; /** * Represents a deeply nested record. It maps keys to values, @@ -106,9 +106,7 @@ type OnyxKey = Key | CollectionKey; * The mapping is derived from the `values` property of the `TypeOptions` type. */ type KeyValueMapping = { - [TKey in keyof TypeOptions['values'] as TKey extends CollectionKeyBase - ? `${TKey}${string}` - : TKey]: TypeOptions['values'][TKey]; + [TKey in keyof TypeOptions['values'] as TKey extends CollectionKeyBase ? `${TKey}${string}` : TKey]: TypeOptions['values'][TKey]; }; /** @@ -182,6 +180,16 @@ type OnyxEntry = TOnyxValue | null; */ type OnyxCollection = OnyxEntry>; +/** + * The `NullableProperties` sets the values of all properties in `T` to be nullable (i.e., `| null`). + * It doesn't recurse into nested property values, this means it applies the nullability only to the top-level properties. + * + * @template T The type of the properties to convert to nullable properties. + */ +type NullableProperties = { + [P in keyof T]: T[P] | null; +}; + export { CollectionKey, CollectionKeyBase, @@ -193,4 +201,5 @@ export { OnyxEntry, OnyxKey, Selector, + NullableProperties, };