-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better typings for KeyboardEvent.key #143
Comments
https://www.w3.org/TR/uievents-key/#keys-unicode
Listing all possible value is possible but impractical considering all the keyboard configurations around the globe and ever changing Unicode standard. Quick good enough solution could be only including US keyboard keys plus predefined keys. |
Related: microsoft/TypeScript#38886 |
Hack to make autocompletion work: microsoft/TypeScript#29729 (comment) type LiteralUnion<T extends U, U = string> = T | (U & { zz_IGNORE_ME?: never })
type Color = LiteralUnion<'red' | 'black'>
var c: Color = 'red' // Has intellisense
var d: Color = 'any-string' // Any string is OK
var d: Color = { zz_IGNORE_ME: '' } // { zz_IGNORE_ME } placeholder is at the bottom of intellisense list and errors because of never
type N = LiteralUnion<1 | 2, number> // Works with numbers too |
KeyboardEvent.key is typed as a string, even though it's a union of string literals.
Would be really nice to get autocomplete here =D
The text was updated successfully, but these errors were encountered: