I have an array with as const
:
// just a simple mock class
class Child { _ = "" }
const child = new Child();
const schema = [[child], child] as const; // readonly [readonly [Child], Child];
This array represents a union of types, so here, it would represent an array of Child
or another array of Child
(one level deeper). In essence, I want to transform the type of schema
into (Child | Child[])[]
.
type T = UnwrapAsConstArray<readonly [readonly [Child], Child]> // => (child | Child[])[]
I'm struggling with the logic to make this transformation possible. This here is my pitiful attempt which does not work that well as you can see at the bottom.
A playground where you can try to make a solution, with some test cases and expected behavior.
Please keep in mind that I would like the solution to be recursive and to work for any amount of nesting.
Similar question: Create a type tuple from an array without "as const". I need the "opposite" which I know is possible.