Skip to content

DOM lib doesn't have the concrete event signatures like the React synthetic event declared? #21825

@zheeeng

Description

@zheeeng

TypeScript Version: 2.7.0

Search Terms:

Code

declare const $input: HTMLInputElement

// Property 'value' does not exist on type 'EventTarget'
$input.onchange = e => { console.log(e.target.value) }

Expected behavior:

The e.target be inferred as HTMLInputElement instead of EventTarget.

The HTMLInputElement could be signatured as below or other proposals:

interface HTMLElement<E> extends Element {
    onchange: (this: E, ev: Event) => any;
}

interface HTMLInputElement extends HTMLElement<HTMLInputElement> {
}

Actual behavior:

Error Property 'value' does not exist on type 'EventTarget'

Playground Link:
Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions