Skip to content

The type of this is not event.currentTarget onChange events #3137

@esanzgar

Description

@esanzgar
  • Check if updating to the latest Preact version resolves the issue

Describe the bug
The type of this onChange events is not event.currentTarget as the type definition implies:

preact/src/jsx.d.ts

Lines 368 to 373 in c7f57db

interface EventHandler<E extends TargetedEvent> {
/**
* The `this` keyword always points to the DOM element the event handler
* was invoked on. See: https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Event_handlers#Event_handlers_parameters_this_binding_and_the_return_value
*/
(this: E['currentTarget'], event: E): void;

Also implied in this test:

// Test `this` binding on event handlers
function onHandler(this: HTMLInputElement, event: any) {
return this.value;
}
const foo = <input onChange={onHandler} />;

To Reproduce

https://codesandbox.io/embed/ancient-tree-6kj30?expanddevtools=1

Steps to reproduce the behavior:

  1. Click on the input checkbox
  2. See error in the console

Expected behavior
The type of this should be the same as event.currentTarget

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions