I have a method with the following signature
function unboxer(data, ...unbox) {
return unbox.reduce((acc, key) => acc ? acc[key] : acc, data);
}
it will iteratively go over supplied keys in unbox array until value is unboxed. example:
unboxer({a: 'somevalue1', b: {c: 'somevalue2', d: {e: 'somevalue3'}}}, ['b', 'c'])
will return somevalue2
unboxer({a: 'somevalue1', b: {c: 'somevalue2', d: {e: 'somevalue3'}}}, ['a'])
will return somevalue1
what is the correct type for unbox parameter? I'd like to reflect that it contains iterative keyof values. Something along the lines of:
unboxer(data: T, unbox: [keyof T, keyof data[keyof T],keyof data[keyof data[keyof T]],.....]
however expression should create a connection between each level of unboxing keys. Meaning, for array ['a','e'] I should receive a compilation error for object:
{a: 'somevalue1', b: {c: 'somevalue2', d: {e: 'somevalue3'}}}