ni / ni/nimble

Evaluate stronger event typing for custom elements

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

Nobody has claimed this yet.

tech debt
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

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.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.