I've been working on a custom object mapping function, but I've encountered an issue. I'm trying to preserve optional parameters as well.
export declare type DeepMap<Values, T> = {
[K in keyof Values]:
Values[K] extends any[]
? Values[K][number] extends object
? DeepMap<Values[K][number], T>[] | T | T[] : T | T[]
: Values[K] extends object
? DeepMap<Values[K], T>
: T;
};
The original type is defined as:
type Obj1 = {
a: number;
b: {
a: number;
};
c?: {
a: number;
}
}
My desired new type looks like this:
type MappedObj1 = {
a: string;
b: {
a: string;
};
c?: {
a: string;
}
}
However, currently I only have the following structure:
type MappedObj1 = {
a: string;
b: {
a: string;
};
}
I seem to have lost the optional type in the process. Can someone please advise me on how to map a deep object and retain all parameters with optionals?