Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions lib/withOnyx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ type EntryBaseMapping<TOnyxKey extends OnyxKey> = {
* },
* ```
*/
type BaseMappingKey<TComponentProps, TOnyxProps, TOnyxProp extends keyof TOnyxProps, TOnyxKey extends OnyxKey, TOnyxValue> = IsEqual<TOnyxValue, TOnyxProps[TOnyxProp]> extends true
type BaseMappingKey<
TComponentProps,
TOnyxProps,
TOnyxProp extends keyof TOnyxProps,
TOnyxKey extends OnyxKey,
TOnyxValue
> = IsEqual<TOnyxValue, TOnyxProps[TOnyxProp]> extends true
? {
key: TOnyxKey | ((props: Omit<TComponentProps, keyof TOnyxProps>) => TOnyxKey);
key: TOnyxKey | ((props: TComponentProps & TOnyxProps) => TOnyxKey);
}
: never;

Expand All @@ -61,7 +67,12 @@ type BaseMappingKey<TComponentProps, TOnyxProps, TOnyxProp extends keyof TOnyxPr
* },
* ```
*/
type BaseMappingStringKeyAndSelector<TComponentProps, TOnyxProps, TOnyxProp extends keyof TOnyxProps, TOnyxKey extends OnyxKey> = {
type BaseMappingStringKeyAndSelector<
TComponentProps,
TOnyxProps,
TOnyxProp extends keyof TOnyxProps,
TOnyxKey extends OnyxKey
> = {
key: TOnyxKey;
selector: Selector<TOnyxKey, TOnyxProps[TOnyxProp]>;
};
Expand All @@ -81,16 +92,23 @@ type BaseMappingStringKeyAndSelector<TComponentProps, TOnyxProps, TOnyxProp exte
* },
* ```
*/
type BaseMappingFunctionKeyAndSelector<TComponentProps, TOnyxProps, TOnyxProp extends keyof TOnyxProps, TOnyxKey extends OnyxKey> = {
key: (props: Omit<TComponentProps, keyof TOnyxProps>) => TOnyxKey;
type BaseMappingFunctionKeyAndSelector<
TComponentProps,
TOnyxProps,
TOnyxProp extends keyof TOnyxProps,
TOnyxKey extends OnyxKey
> = {
key: (props: TComponentProps & TOnyxProps) => TOnyxKey;
selector: Selector<TOnyxKey, TOnyxProps[TOnyxProp]>;
};

/**
* Represents the mapping options between an Onyx key and the component's prop with all its possibilities.
*/
type Mapping<TComponentProps, TOnyxProps, TOnyxProp extends keyof TOnyxProps, TOnyxKey extends OnyxKey> = BaseMapping<TComponentProps, TOnyxProps> &
EntryBaseMapping<TOnyxKey> &
type Mapping<TComponentProps, TOnyxProps, TOnyxProp extends keyof TOnyxProps, TOnyxKey extends OnyxKey> = BaseMapping<
TComponentProps,
TOnyxProps
> & EntryBaseMapping<TOnyxKey> &
(
| BaseMappingKey<TComponentProps, TOnyxProps, TOnyxProp, TOnyxKey, OnyxEntry<KeyValueMapping[TOnyxKey]>>
| BaseMappingStringKeyAndSelector<TComponentProps, TOnyxProps, TOnyxProp, TOnyxKey>
Expand All @@ -100,8 +118,12 @@ type Mapping<TComponentProps, TOnyxProps, TOnyxProp extends keyof TOnyxProps, TO
/**
* Represents the mapping options between an Onyx collection key without suffix and the component's prop with all its possibilities.
*/
type CollectionMapping<TComponentProps, TOnyxProps, TOnyxProp extends keyof TOnyxProps, TOnyxKey extends CollectionKeyBase> = BaseMapping<TComponentProps, TOnyxProps> &
CollectionBaseMapping<TOnyxKey> &
type CollectionMapping<
TComponentProps,
TOnyxProps,
TOnyxProp extends keyof TOnyxProps,
TOnyxKey extends CollectionKeyBase
> = BaseMapping<TComponentProps, TOnyxProps> & CollectionBaseMapping<TOnyxKey> &
(
| BaseMappingKey<TComponentProps, TOnyxProps, TOnyxProp, TOnyxKey, OnyxCollection<KeyValueMapping[TOnyxKey]>>
| BaseMappingStringKeyAndSelector<TComponentProps, TOnyxProps, TOnyxProp, TOnyxKey>
Expand Down Expand Up @@ -131,9 +153,11 @@ type OnyxPropCollectionMapping<TComponentProps, TOnyxProps, TOnyxProp extends ke
*/
declare function withOnyx<TComponentProps, TOnyxProps>(
mapping: {
[TOnyxProp in keyof TOnyxProps]: OnyxPropMapping<TComponentProps, TOnyxProps, TOnyxProp> | OnyxPropCollectionMapping<TComponentProps, TOnyxProps, TOnyxProp>;
[TOnyxProp in keyof TOnyxProps]:
| OnyxPropMapping<TComponentProps, TOnyxProps, TOnyxProp>
| OnyxPropCollectionMapping<TComponentProps, TOnyxProps, TOnyxProp>;
},
shouldDelayUpdates?: boolean,
): (component: React.ComponentType<TComponentProps>) => React.ComponentType<Omit<TComponentProps, keyof TOnyxProps>>;
): (component: React.ComponentType<TComponentProps>) => React.ComponentType<TComponentProps & TOnyxProps>;

export default withOnyx;