Basically, I have this type
type X = {
a: {
b?: string;
c?: string;
d: {
e:{
f:{
g?: boolean
}
}
};
};
};
// and a helper
const as = <T,>(arg: T):T => arg;
and I need to be able to create an object, in the shape of X where all properties, on all levels of nesting, are replaced by:
as({
// autocomplete here with actual object property
// unless it's not an object
})
// like so
const x = as<X>({
a: as({
b: as("some string"),
d: as({
e: as({
f: as({
g: as(false)
})
})
})
})
})
I got it working to a degree, but at more than 2 levels of nesting, the autocomplete no longer …autocompletes
Please refer to the Typescript playground link for a better understanding of the problem.
So… I got it working
Everything is working as expected with one exception I am forced to cast ALL properties to be mandatory, meaning the resulting type cannot have any optional params. Maybe somebody can help with that?