Skip to content

Why 'input' event has Event type of event instead of InputEvent #39925

@kaczor6418

Description

@kaczor6418

"input": Event;

Hi I am wondering why type of 'input' event type is a Event type (I thought it should be InputEvent)?

I came across on this problem doing this:

interface OnInputTextFieldListenerProps extends BaseTextFieldListenerProps {
    eventName: Extract<keyof GlobalEventHandlersEventMap, 'input'>;
    callback(e?: InputEvent): void;
}

if (isOnInputTextFieldProps(listenerProps)) {
    this.input.addEventListener<'input'>(listenerProps.eventName, listenerProps.callback.bind(this));
}

And now I am getting this error:

TS2345: Argument of type '(e?: InputEvent | undefined) => void' is not assignable to parameter of type '(this: HTMLInputElement, ev: Event) => any'.

Which is absolutely correct.

But why GlobalEventHandlersEventMap 'input' is typed as Event instead of InputEvent. If MDN documentation says that GlobalEventHandlers.oninput interface is InputEvent. oninput is probalby equivalent of typescript input. I think like that because in MDN docs every key of GlobalEventHandlers interface starts with on.

You can find this GlobalEventHandlersEventMap interface here lib.dom.d.ts - L:5715 at line 5715.

I also created a question at StackOverflow - Why 'input' event has Event type of event instead of InputEvent

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions