react-native-onyx 3.0.20 → 3.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Onyx.d.ts CHANGED
@@ -139,7 +139,7 @@ declare function clear(keysToPreserve?: OnyxKey[]): Promise<void>;
139
139
  * @param data An array of objects with update expressions
140
140
  * @returns resolves when all operations are complete
141
141
  */
142
- declare function update(data: OnyxUpdate[]): Promise<void>;
142
+ declare function update<TKey extends OnyxKey>(data: Array<OnyxUpdate<TKey>>): Promise<void>;
143
143
  /**
144
144
  * Sets a collection by replacing all existing collection members with new values.
145
145
  * Any existing collection members not included in the new data will be removed.
@@ -241,7 +241,7 @@ declare function subscribeToKey<TKey extends OnyxKey>(connectOptions: ConnectOpt
241
241
  * @param subscriptionID Subscription ID returned by calling `OnyxUtils.subscribeToKey()`.
242
242
  */
243
243
  declare function unsubscribeFromKey(subscriptionID: number): void;
244
- declare function updateSnapshots(data: OnyxUpdate[], mergeFn: typeof Onyx.merge): Array<() => Promise<void>>;
244
+ declare function updateSnapshots<TKey extends OnyxKey>(data: Array<OnyxUpdate<TKey>>, mergeFn: typeof Onyx.merge): Array<() => Promise<void>>;
245
245
  /**
246
246
  * Writes a value to our store with the given key.
247
247
  * Serves as core implementation for `Onyx.set()` public function, the difference being
package/dist/types.d.ts CHANGED
@@ -175,9 +175,7 @@ type NullishObjectDeep<ObjectType extends object> = {
175
175
  * Also, the `TMap` type is inferred automatically in `mergeCollection()` method and represents
176
176
  * the object of collection keys/values specified in the second parameter of the method.
177
177
  */
178
- type Collection<TKey extends CollectionKeyBase, TValue> = Record<`${TKey}${string}`, TValue> & {
179
- [P in TKey]?: never;
180
- };
178
+ type Collection<TKey extends CollectionKeyBase, TValue> = Record<`${TKey}${string}`, TValue>;
181
179
  /** Represents the base options used in `Onyx.connect()` method. */
182
180
  type BaseConnectOptions = {
183
181
  /** If set to `false`, then the initial data will be only sent to the callback function if it changes. */
@@ -270,40 +268,39 @@ type OnyxMergeCollectionInput<TKey extends OnyxKey> = Collection<TKey, NonNullab
270
268
  */
271
269
  type OnyxSetCollectionInput<TKey extends OnyxKey> = Collection<TKey, OnyxInput<TKey>>;
272
270
  type OnyxMethodMap = typeof OnyxUtils.METHOD;
271
+ type ExpandOnyxKeys<TKey extends OnyxKey> = TKey extends CollectionKeyBase ? NoInfer<`${TKey}${string}`> : TKey;
273
272
  /**
274
273
  * OnyxUpdate type includes all onyx methods used in OnyxMethodValueMap.
275
274
  * If a new method is added to OnyxUtils.METHOD constant, it must be added to OnyxMethodValueMap type.
276
275
  * Otherwise it will show static type errors.
277
276
  */
278
- type OnyxUpdate = {
279
- [TKey in OnyxKey]: {
277
+ type OnyxUpdate<TKey extends OnyxKey = OnyxKey> = {
278
+ [K in TKey]: {
280
279
  onyxMethod: typeof OnyxUtils.METHOD.SET;
281
- key: TKey;
282
- value: OnyxSetInput<TKey>;
280
+ key: ExpandOnyxKeys<K>;
281
+ value: OnyxSetInput<K>;
283
282
  } | {
284
283
  onyxMethod: typeof OnyxUtils.METHOD.MULTI_SET;
285
- key: TKey;
284
+ key: ExpandOnyxKeys<K>;
286
285
  value: OnyxMultiSetInput;
287
286
  } | {
288
287
  onyxMethod: typeof OnyxUtils.METHOD.MERGE;
289
- key: TKey;
290
- value: OnyxMergeInput<TKey>;
288
+ key: ExpandOnyxKeys<K>;
289
+ value: OnyxMergeInput<K>;
291
290
  } | {
292
291
  onyxMethod: typeof OnyxUtils.METHOD.CLEAR;
293
- key: TKey;
294
- value?: undefined;
295
- };
296
- }[OnyxKey] | {
297
- [TKey in CollectionKeyBase]: {
292
+ key: ExpandOnyxKeys<K>;
293
+ value?: never;
294
+ } | {
298
295
  onyxMethod: typeof OnyxUtils.METHOD.MERGE_COLLECTION;
299
- key: TKey;
300
- value: OnyxMergeCollectionInput<TKey>;
296
+ key: K;
297
+ value: OnyxMergeCollectionInput<K>;
301
298
  } | {
302
299
  onyxMethod: typeof OnyxUtils.METHOD.SET_COLLECTION;
303
- key: TKey;
304
- value: OnyxSetCollectionInput<TKey>;
300
+ key: K;
301
+ value: OnyxSetCollectionInput<K>;
305
302
  };
306
- }[CollectionKeyBase];
303
+ }[TKey];
307
304
  /**
308
305
  * Represents the options used in `Onyx.set()` method.
309
306
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "3.0.20",
3
+ "version": "3.0.21",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",