I have the following code:
const KeyboardEventKeys = {
Escape: 'Escape',
Enter: 'Enter',
Tab: 'Tab'
};
type KeyboardEventKeys = keyof (typeof KeyboardEventKeys);
function doSomething(key: KeyboardEventKeys) {}
When I'm passing to a function the value of one of the object properties it yells at me:
doSomething(KeyboardEventKeys.Enter);
One solution is to cast as KeyboardEventKeys
, but it's a redundant solution. How can I do it without it?
I also don't want to add doSomething(key: KeyboardEventKeys | string)
because I will lose the type guard.