Skip to content

Untyped "this" parameter in the type declarations. #2164

@Artikash

Description

@Artikash

Here's some TSX

const App = {
	processData(data: string) {},
	forwardEvent(this: { processData(data: string): void }, data: Event) {
		this.processData(event?.type || "");
	}
}

render(<input
	type="text"
	onChange={App.forwardEvent} // NOOOOOO!!!!
/>, document.body);

Expected behavior: compile error due to incompatible this types.
Actual behavior: compiles fine with the undeclared this parameter in jsx.d.ts, runtime error as soon as the event fires 😢 .

In Preact version 10.0.5.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No 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