Skip to content

[@types/react] Including KeyboardEvent.key values in the type #45062

@dimitropoulos

Description

@dimitropoulos
  • I tried using the @types/react package and had problems.
  • I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • Mention the authors (see Definitions by: in index.d.ts) so they can respond.

Authors: @johnnyreilly @bbenezech @pzavolinsky @digiguru @ericanderson @DovydasNavickas @theruther4d @guilhermehubner @ferdaber @jrakotoharisoa @pascaloliv @Hotell @franklixuefei @Jessidhia @saranshkataria @lukyth @eps1lon @zieka @dancerphil @dimitropoulos @disjukr @vhfmag


In the context of a PR moving the (deprecated) KeyboardEvent.keyCode usages in a codebase to KeyboardEvent.key I noticed that the types for this are:

interface KeyboardEvent<...> {
    ...
    /**
     * See the [DOM Level 3 Events spec](https://www.w3.org/TR/uievents-key/#named-key-attribute-values). for possible values
     */
    key: string;
    ...
}

Which makes me wonder if there's any opposition to just including the list of possible named key attribute values into the react types? Here is the list (just item 3 from this document).

Although in the end any value will be accepted because it's still going to need to | string at the end (since all unicode characters are possible values of KeyboardEvent.key), it will help end users because it will provide completion for common values like Enter, Control, Tab, etc.

Any interest?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions