test.tswindow.addEventListener("load", async () => {
console.log("hello");
});
deno test.tsThe program prints hello, then exits with no errors.
The following error is printed to the console and the program exits without printing hello:
error TS2345: Argument of type '() => Promise<void>' is not assignable to parameter of type '(event: Event) => void | null'.
Type 'Promise<void>' is not assignable to type 'void'.
â–º file:///Path/To/CWD/test.ts:1:33
1 window.addEventListener("load", async () => {
test.js it runs without a problem.I think marking the return types of callbacks to be any might be reasonable here.
I also noticed that addEventListener should also be able to take objects implementing EventListener interface, not just plain functions.
We really should follow the TypeScript typings for stuff like this as they get a lot of more real world use. TypeScript has:
addEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
@kitsonk I think that is only for AbortSignal.
The actual lines we should follow are:
https://github.com/microsoft/TypeScript/blob/0326534a2a6c361f5334a66197a3cdd84cb45b6f/lib/lib.webworker.d.ts#L5667
https://github.com/microsoft/TypeScript/blob/0326534a2a6c361f5334a66197a3cdd84cb45b6f/lib/lib.webworker.d.ts#L1504