Reputation: 21430
In following code variable x
has properties a
and z
, but I want it to have a
and b
. How can I express that in typescript?
const enum CE {
a = "a",
b = "z",
}
declare var x: Record<CE, any> // has 'a' and 'z'
Upvotes: 1
Views: 190
Reputation: 37988
Enum is variable itself, so you can query its type with typeof CE
, then get its keys with keyof
:
declare var x: Record<keyof typeof CE, any> // Record<"a" | "b", any>
Upvotes: 1