I have the following types:
interface USER {
email: string;
age: number;
}
interface SCORES {
likes: number;
followers: number;
}
and then composite state as shown below:
interface UserStats {
user: USER;
stats: SCORES;
}
Now I get a payload which looks like this:
{type: 'user', values: {email:"[email protected]",age: 21}}
or
{type: 'stats', values: {likes:20,followers: 21}}
While destructuring the above payload, I need to assign its type such that it covers both the cases, something like:
type payloadKeyTypes = 'user' | 'stats'
type configPayload = USER | SCORES
interface payloadType {
[payloadKeyTypes]: configPayLoad
}
But this says: A computed property name in an interface must refer to an expression whose type is a literal type or a 'unique symbol' type
How do I go for resolving it?
type Recordinstead ofinterface. See here. Btw, there is nonumerictype - onlynumbersymbolsandtemplate stringsas index signature in interface you can see docs and PR