Looking to retrieve the name of a CustomEvent parameter in a function, which is basically the string it was created with (new CustomEvent('foo')
)
If you need a reference, check out https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
public addEvent(iChannel: number, oEvent: CustomEvent)
{
if (App.isDebugging)
{
console.log(CustomEvent+' emitted '+CustomEvent.typeArg+' on channel '+iChannel);
console.log(CustomEvent);
}
this.aEventChannels[iChannel].dispatchEvent(oEvent);
}
//here's what lib.dom.d.ts has to say
declare var CustomEvent: {
prototype: CustomEvent;
new<T>(typeArg: string, eventInitDict?: CustomEventInit<T>):
CustomEvent<T>;
};
I've experimented with using type
and typeArg
, but both give me an error:
tsc --build src-webui/ts
src-webui/ts/App.ts(162,53): error TS2339: Property 'typeArg' does not exist on type '{ new <T>(typeArg: string, eventInitDict?: CustomEventInit<T> | undefined): CustomEvent<T>; prototype: CustomEvent<any>; }'.`
Reacquainting myself with TS can be tricky, so I'm sure the solution is straightforward and I just need it to "click". Any guidance would be greatly appreciated, thank you!
PS: This is targeted for the browser.