Skip to content

keypress e.code is not valid TypeScript, but is valid JavaScript #9206

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

Closed
ChicagoDave opened this issue Jun 16, 2016 · 2 comments
Closed

keypress e.code is not valid TypeScript, but is valid JavaScript #9206

ChicagoDave opened this issue Jun 16, 2016 · 2 comments
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@ChicagoDave
Copy link

TypeScript Version:

1.8.10

Code

// A self-contained demonstration of the problem follows...

Grrr - I don't have time for this

in an input element onkeypress, you can't touch e.code. You have to create a plain JS function to read that totally legitimate property on the event argument.

Expected behavior:

(e.code == "Enter") is valid

Actual behavior:

(e.code == "Enter") is not valid because .code is not recognized as a legit property

@kitsonk
Copy link
Contributor

kitsonk commented Jun 16, 2016

.code is relatively new with only support in Firefox 32+. Things like this take a while to flow through the libraries (and may not be considered until there is wider browser support). These additions can be contributed.

Interfaces though are open ended, and if you are writing code that only works in Firefox, you can quite easily add it yourself:

interface KeyboardEvent {
    code: string;
}

function listener(e: KeyboardEvent) {
    if (e.code === 'Enter') {
        //
    }
}

It would be best though to place the extension in a custom .d.ts file which you maintain and include in projects where this valid at runtime (Firefox 32+ only).

@mhegazy mhegazy added Suggestion An idea for TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Revisit An issue worth coming back to labels Jun 16, 2016
@mhegazy mhegazy added Fixed in TSJS repo and removed Revisit An issue worth coming back to labels Aug 15, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Aug 15, 2016

should be addressed by microsoft/TypeScript-DOM-lib-generator#138

@zhengbli zhengbli added Fixed A PR has been merged for this issue and removed Fixed in TSJS repo labels Aug 22, 2016
@mhegazy mhegazy added this to the TypeScript 2.0.1 milestone Aug 22, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants