Evaluate stronger event typing for custom elements
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 39
- Forks
- 14
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 13
Description
🧹 Tech Debt
We override HTMLElementTagNameMap to add definitions for our custom elements like:
declare global {
interface HTMLElementTagNameMap {
'nimble-select': Select;
}
}
It seems possible to also override definitions in HTMLElementEventMap like:
declare global {
interface HTMLElementEventMap {
'filter-input': CustomEvent<SelectFilterInputEventDetail>;
}
}
Which would result in lines like the following having strong typing without any casts:
selectElement.addEventListener('filter-input', evt => evt.detail.filterText);
We should evaluate:
- Is this a good idea / is there precedence in other custom element libraries?
- What happens for multiple definitions of the same event name?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing HTMLElementTagNameMap declarations and the proposed HTMLElementEventMap augmentation for custom elements. Compare this approach with precedent in other custom element libraries and investigate how multiple definitions of the same event name behave. Done means documenting whether stronger event typing is appropriate and how duplicate event names should be handled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100