One of the interfaces I have is the Basic interface:
interface Basic {
[key: string]: {
data: string;
};
}
There is another interface that extends the Basic interface:
interface Another extends Basic {
'onekey': OneKeyData;
'secondkey': SeconKeyData;
}
An issue arises when using the generic T extends keyof Another
because it allows any string keys due to the Basic interface. Both OneKeyData and SecondKeyData contain a data
property, just like Basic. If it wasn't used in scenarios like this:
interface Options<TKey extends keyof Another> {
field: Another[TKey]['data'];
}
What would be the best solution in this scenario? Is there a way to only get the keyof
the Another interface?