So now that typescript 4 is out I expected this to be easier but I still have not found a way to accomplish this.
I am trying to make a function that takes in a tuple containing a specific Generic and returns a Generic returning containing the values.
interface STORE<T> {
data: T;
}
const merge = <U extends any, T extends readonly STORE<U>[]>(values: T): STORE<U[]> =>
values.reduce<STORE<U[]>>(
(acc, item) => {
return { data: [...acc.data, item.data] };
},
{ data: [] },
);
for example calling this should result in the following
assert(merge([{ data: 'test' }, { data: 2 }]), { data: ['test', 2]});
This however will return the value as STORE<unknown[]>
instead of maintaining the type from the input.