Event handler in JSX + TS (Preact). Issue with generated typing

Open
#2,528 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
frontend

Research direction

Start with the generated components.d.ts entry for the Dropdown event and the JSX examples in the report; compare the generated handler name with the runtime name accepted by Preact. Reproduce both forms and verify that the documented, typed form invokes the handler without a TypeScript error.

Written by the indexing model from the issue text.

Description

Bug: Validated

Stencil version:

 @stencil/core@<1.11.3>

I'm submitting a:

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:
I have a component with an EventEmitter, called Dropdown. According to the docs and the generated typefile, i should be able to access the event handle using camel-case: <Dropdown onDropdownSelect={handler}> in JSX, but the event is never called.

Although if i use ondropdownSelect the event fires. I have checked in the components.d.ts file, and the event is typed as onDropDown, so if i use the handler that works, I get a TS error.

Expected behavior:

I would expect that the event handler would be the same as the type that is created in the types file.

Steps to reproduce:

Related code:
Stencil component

@Component({
  tag: 'dropdown',
})
export class Dropdown {
  @Event() dropdownSelect!: EventEmitter<string>;

  ...

  protected handleSomething(value: string) {
    this.dropdownSelect.emit(value);
  }
}

preact
doesn't work

<dropdown onDropdownSelect={ev => this.someMethod(ev)} />

works

<dropdown ondropdownSelect={ev => this.someMethod(ev)} />

Other information:

Dominant language
TypeScript
Stars
13.1k
Forks
855
Avg merge
4h 7m
Merged PRs (30d)
44

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stenciljs/core

All issues in stenciljs/core

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.