From 8b3981c16ea67e2a129db8939845d2f4aaad9563 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Mon, 18 Sep 2023 10:42:53 +0200 Subject: [PATCH 1/3] Allow null properties for Onyx.merge --- lib/Onyx.d.ts | 12 ++---------- lib/types.d.ts | 27 ++++++++++++--------------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/lib/Onyx.d.ts b/lib/Onyx.d.ts index 4e7d4327..7960de4b 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, Nullable} 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: Nullable>): Promise; /** * Clear out all the data in the store diff --git a/lib/types.d.ts b/lib/types.d.ts index 6bb36dae..267707e0 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,15 +180,14 @@ type OnyxEntry = TOnyxValue | null; */ type OnyxCollection = OnyxEntry>; -export { - CollectionKey, - CollectionKeyBase, - CustomTypeOptions, - DeepRecord, - Key, - KeyValueMapping, - OnyxCollection, - OnyxEntry, - OnyxKey, - Selector, +/** + * 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, CustomTypeOptions, DeepRecord, Key, KeyValueMapping, OnyxCollection, OnyxEntry, OnyxKey, Selector, NullableProperties as Nullable}; From ca46f48189c219028f7e38716312d6a4274d3fbd Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Mon, 18 Sep 2023 10:44:58 +0200 Subject: [PATCH 2/3] Fix names --- .prettierrc.js | 9 +++++++++ lib/Onyx.d.ts | 4 ++-- lib/types.d.ts | 14 +++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 .prettierrc.js diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 00000000..c5debcb1 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,9 @@ +module.exports = { + tabWidth: 4, + singleQuote: true, + trailingComma: "all", + bracketSpacing: false, + arrowParens: "always", + printWidth: 160, + singleAttributePerLine: true, +}; diff --git a/lib/Onyx.d.ts b/lib/Onyx.d.ts index 7960de4b..0c7fdd31 100644 --- a/lib/Onyx.d.ts +++ b/lib/Onyx.d.ts @@ -1,7 +1,7 @@ import {Component} from 'react'; import {PartialDeep} from 'type-fest'; import * as Logger from './Logger'; -import {CollectionKey, CollectionKeyBase, DeepRecord, KeyValueMapping, OnyxCollection, OnyxEntry, OnyxKey, Nullable} 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`. @@ -202,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: Nullable>): 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 267707e0..c43d0640 100644 --- a/lib/types.d.ts +++ b/lib/types.d.ts @@ -190,4 +190,16 @@ type NullableProperties = { [P in keyof T]: T[P] | null; }; -export {CollectionKey, CollectionKeyBase, CustomTypeOptions, DeepRecord, Key, KeyValueMapping, OnyxCollection, OnyxEntry, OnyxKey, Selector, NullableProperties as Nullable}; +export { + CollectionKey, + CollectionKeyBase, + CustomTypeOptions, + DeepRecord, + Key, + KeyValueMapping, + OnyxCollection, + OnyxEntry, + OnyxKey, + Selector, + NullableProperties, +}; From f71af27b513e228307924b6e7a6262d27f7e6a93 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Mon, 18 Sep 2023 10:45:26 +0200 Subject: [PATCH 3/3] Remove prettierrc --- .prettierrc.js | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 .prettierrc.js diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index c5debcb1..00000000 --- a/.prettierrc.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - tabWidth: 4, - singleQuote: true, - trailingComma: "all", - bracketSpacing: false, - arrowParens: "always", - printWidth: 160, - singleAttributePerLine: true, -};