I've been trying to create a Generic type that could do the following:
// Given types that looks like this
interface ModelBase {
general: {
a: string;
b: string;
}
};
interface ModelA extends ModelBase {
c: [string, string];
d: [string, number];
e: [string, Record<string,any>];
};
interface ModelB extends ModelBase {
f: [string, number];
g: [string, boolean];
};
// Write a Generic, which could do the following
// Take any of ModelA or ModelB, and convert it to the following
type ConvertedModelA = {
c: string;
d: number;
e: string; // Record first parameter
}
type ConvertedModelB = {
f: number;
g: boolean;
}
I've tried mapping the other way around, but realised I would have issues with converting string, because I wouldn't be able to tell if string should be transformed into string or Record<string,any>
I have no idea on how to extract the second part of the arrays and how to get just the Record first argument.