Answer the question
In order to leave comments, you need to log in
How to assign a type to a cloned object whose values have been changed recursively?
Hello. I make a deep copy of 1 object into a new object, changing the key values from numbers to strings. How to set the type for a new object, correcting all values to type "string" recursively in depth? Here is the file https://codesandbox.io/s/epic-platform-mezbe
Answer the question
In order to leave comments, you need to log in
You can add this type:
type RulersMap<R extends Record<string, unknown>> = {
[K in keyof R]: R[K] extends number
? `${R[K]}px`
: R[K] extends Record<string, unknown>
? RulersMap<R[K]>
: R[K];
};
and cast the result to the type RulersMap<typeof rulers>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question