diff --git a/lib/withOnyx.d.ts b/lib/withOnyx.d.ts index e5dfc1dfd..0b52e256d 100644 --- a/lib/withOnyx.d.ts +++ b/lib/withOnyx.d.ts @@ -40,9 +40,15 @@ type EntryBaseMapping = { * }, * ``` */ -type BaseMappingKey = IsEqual extends true +type BaseMappingKey< + TComponentProps, + TOnyxProps, + TOnyxProp extends keyof TOnyxProps, + TOnyxKey extends OnyxKey, + TOnyxValue +> = IsEqual extends true ? { - key: TOnyxKey | ((props: Omit) => TOnyxKey); + key: TOnyxKey | ((props: TComponentProps & TOnyxProps) => TOnyxKey); } : never; @@ -61,7 +67,12 @@ type BaseMappingKey = { +type BaseMappingStringKeyAndSelector< + TComponentProps, + TOnyxProps, + TOnyxProp extends keyof TOnyxProps, + TOnyxKey extends OnyxKey +> = { key: TOnyxKey; selector: Selector; }; @@ -81,16 +92,23 @@ type BaseMappingStringKeyAndSelector = { - key: (props: Omit) => TOnyxKey; +type BaseMappingFunctionKeyAndSelector< + TComponentProps, + TOnyxProps, + TOnyxProp extends keyof TOnyxProps, + TOnyxKey extends OnyxKey +> = { + key: (props: TComponentProps & TOnyxProps) => TOnyxKey; selector: Selector; }; /** * Represents the mapping options between an Onyx key and the component's prop with all its possibilities. */ -type Mapping = BaseMapping & - EntryBaseMapping & +type Mapping = BaseMapping< + TComponentProps, + TOnyxProps +> & EntryBaseMapping & ( | BaseMappingKey> | BaseMappingStringKeyAndSelector @@ -100,8 +118,12 @@ type Mapping = BaseMapping & - CollectionBaseMapping & +type CollectionMapping< + TComponentProps, + TOnyxProps, + TOnyxProp extends keyof TOnyxProps, + TOnyxKey extends CollectionKeyBase +> = BaseMapping & CollectionBaseMapping & ( | BaseMappingKey> | BaseMappingStringKeyAndSelector @@ -131,9 +153,11 @@ type OnyxPropCollectionMapping( mapping: { - [TOnyxProp in keyof TOnyxProps]: OnyxPropMapping | OnyxPropCollectionMapping; + [TOnyxProp in keyof TOnyxProps]: + | OnyxPropMapping + | OnyxPropCollectionMapping; }, shouldDelayUpdates?: boolean, -): (component: React.ComponentType) => React.ComponentType>; +): (component: React.ComponentType) => React.ComponentType; export default withOnyx;