#trouble typing event listener from custom-card-helpers fireEvent()

1 messages · Page 1 of 1 (latest)

urban cliff
#

using custom-card-helpers fireEvent() method from my cards editor, im a bit confused on how to type that on the on the main card listener/handler:

  connectedCallback() {
    super.connectedCallback();
...
      document.body.addEventListener(
        "tabbed-card",
        (ev) => this._handleSelectedTab(ev),
        { signal: this.controller.signal },
      );
    }
  }
  private _handleSelectedTab(ev: ValidHassDomEvent) {
    if ("selectedTab" in ev.detail) {
      setTimeout(() => {
        this.selectedEditorTabIndex = ev.detail.selectedTab;
      }, 1);
    }
  }

Property 'detail' does not exist on type 'keyof HASSDomEvents'.
Property 'detail' does not exist on type '"undefined"'.ts(2339)
referencing fireEvent(): https://github.com/custom-cards/custom-card-helpers/blob/351921f43168cc3d1cb7c81a4c67215aa4f64103/src/fire-event.ts#L36

#

trouble typing event listener from custom-card-helpers fireEvent()

#

fireEvent type signature:

(alias) const fireEvent: <HassEvent extends keyof HASSDomEvents>(node: HTMLElement | Window, type: HassEvent, detail?: HASSDomEvents[HassEvent] | undefined, options?: {
bubbles?: boolean | undefined;
cancelable?: boolean | undefined;
composed?: boolean | undefined;
} | undefined) => Event

#

with something like:

_handleSelectedTab(ev: keyof typeof fireEvent)

you get:

Property detail does not exist on type never.

dusk cargo
#

I think you can type it as ´CustomEvent`. That's a builtin.

urban cliff
#

thanks for the reply thomas. that was my initial route but it doesnt like passing an Event to the _handleSelectedTab handler:

Argument of type 'Event' is not assignable to parameter of type 'CustomEvent<any>'.
Type 'Event' is missing the following properties from type 'CustomEvent<any>': detail, initCustomEventts(2345)