@@ -29,6 +29,24 @@ export type Mapper<
2929 mapperOptions ?: MapperOptions ,
3030] | typeof mapObjectSkip ;
3131
32+ /**
33+ Mapper used when `{deep: true}` is enabled.
34+
35+ In deep mode we may visit nested objects with keys and values unrelated to the top-level object, so we intentionally widen the key and value types.
36+ */
37+ export type DeepMapper <
38+ MappedObjectKeyType extends string ,
39+ MappedObjectValueType ,
40+ > = (
41+ sourceKey : string ,
42+ sourceValue : any ,
43+ source : any
44+ ) => [
45+ targetKey : MappedObjectKeyType ,
46+ targetValue : MappedObjectValueType ,
47+ mapperOptions ?: MapperOptions ,
48+ ] | typeof mapObjectSkip ;
49+
3250export interface Options {
3351 /**
3452 Recurse nested objects and objects in arrays.
@@ -98,11 +116,7 @@ export default function mapObject<
98116 MappedObjectValueType ,
99117> (
100118 source : SourceObjectType ,
101- mapper : Mapper <
102- SourceObjectType ,
103- MappedObjectKeyType ,
104- MappedObjectValueType
105- > ,
119+ mapper : DeepMapper < MappedObjectKeyType , MappedObjectValueType > ,
106120 options : DeepOptions & TargetOptions < TargetObjectType >
107121) : TargetObjectType & Record < string , unknown > ;
108122export default function mapObject <
@@ -111,11 +125,7 @@ export default function mapObject<
111125 MappedObjectValueType ,
112126> (
113127 source : SourceObjectType ,
114- mapper : Mapper <
115- SourceObjectType ,
116- MappedObjectKeyType ,
117- MappedObjectValueType
118- > ,
128+ mapper : DeepMapper < MappedObjectKeyType , MappedObjectValueType > ,
119129 options : DeepOptions
120130) : Record < string , unknown > ;
121131export default function mapObject <
0 commit comments