I have a dynamic data like,
const data = {games:{type: [], sport: [], category: []}}
And I have hardcoded type like type Valid = "type" & "sport" & "category"
How can I make type Valid
dynamic based on the Object.keys(data.games)
instead of hardcoding ?
I have tried the following,
type Valid = typeof Object.keys(data.games).join(' & ');
But this gives the error as,
Unexpected token, expected ";"
Please help me to get dynamic values for the type Valid
.
Working Example:
CodePudding user response:
I think you want expression is
type Valid = keyof typeof data.games