Skip to content

Commit

Permalink
fix: input type
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispader committed Jun 4, 2024
1 parent b0d2505 commit d44df56
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 38 deletions.
2 changes: 0 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type {
OnyxValue,
Selector,
OnyxInputValue,
OnyxCollectionInput,
OnyxInput,
OnyxSetInput,
OnyxMultiSetInput,
Expand All @@ -34,7 +33,6 @@ export type {
OnyxEntry,
OnyxKey,
OnyxInputValue,
OnyxCollectionInput,
OnyxInput,
OnyxSetInput,
OnyxMultiSetInput,
Expand Down
37 changes: 1 addition & 36 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,47 +342,13 @@ type Mapping<TKey extends OnyxKey> = ConnectOptions<TKey> & {
*/
type OnyxInputValue<TOnyxValue> = TOnyxValue | null;

/**
* Represents an Onyx collection of inputs, that can be either a record of `TOnyxValue`s or `null` if the key should be deleted.
*
* It can be used to specify collection data retrieved from Onyx e.g. `withOnyx` HOC mappings.
*
* @example
* ```ts
* import Onyx, {OnyxCollection, withOnyx} from 'react-native-onyx';
*
* type OnyxProps = {
* reports: OnyxCollection<Report>;
* };
*
* type Props = OnyxProps & {
* prop1: string;
* };
*
* function Component({prop1, reports}: Props) {
* // ...
* }
*
* export default withOnyx<Props, OnyxProps>({
* reports: {
* key: ONYXKEYS.COLLECTION.REPORT,
* },
* })(Component);
* ```
*/
type OnyxCollectionInput<TOnyxValue> = OnyxInputValue<Record<string, TOnyxValue | null>>;

/**
* Represents an input value that can be passed to Onyx methods, that can be either `TOnyxValue` or `null`.
* Setting a key to `null` will remove the key from the store.
* `undefined` is not allowed for setting values, because it will have no effect on the data.
*/
// type OnyxInput<TOnyxValue> = TOnyxValue | null;
type OnyxInput<TKey extends OnyxKey> = string extends TKey
? unknown
: TKey extends CollectionKeyBase
? OnyxCollectionInput<KeyValueMapping[TKey]>
: OnyxInputValue<NullishDeep<KeyValueMapping[TKey]>>;
type OnyxInput<TKey extends OnyxKey> = OnyxInputValue<NullishDeep<KeyValueMapping[TKey]>>;

/**
* Represents a mapping object where each `OnyxKey` maps to either a value of its corresponding type in `KeyValueMapping` or `null`.
Expand Down Expand Up @@ -512,7 +478,6 @@ export type {
OnyxEntry,
OnyxKey,
OnyxInputValue,
OnyxCollectionInput,
OnyxInput,
OnyxSetInput,
OnyxMultiSetInput,
Expand Down

0 comments on commit d44df56

Please sign in to comment.