I have the following (example-)array:
[
'test-string',
foo => ({ foo }),
'other-string',
bar => ({ bar })
]
with the (example-)interface
interface MyValues { foo: string; bar: string; }
A function that expects this array type must ensure that the unification of the results of all functions implements the complete interface. Is that possible? Currently, I have:
type Fn<Values> = (part: string) => { [key in keyof Values]?: string }
type Item<Values> = string | Fn<Values>;
function extract<Values>(items: Item<Values>[]) {
const values = {} as Values;
// (...)
return values;
}
However, this typing only checks that all functions return objects that match the keys of Values
and not that all keys are finally present.
I am not quite sure if this check is even possible with TypeScript, I have found this answer which also goes towards "calculations" of types, but I am not sure if this is applicable for this use-case.