I've created a generic which map object, but I have a problem. I need to save optional parameters too
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;
};
I have an original type:
type Obj1 = {
a: number;
b: {
a: number;
};
c?: {
a: number;
}
}
I want to get a new type in next way:
type MappedObj1 = {
a: string;
b: {
a: string;
};
c?: {
a: string;
}
}
But now I have only this structure
type MappedObj1 = {
a: string;
b: {
a: string;
};
}
My optional type was lost
Could you help me please how can I map a deep object and save all parameters with optionals ?