diff --git a/types/three/src/core/EventDispatcher.d.ts b/types/three/src/core/EventDispatcher.d.ts index 403dd1c2e..fa8048a96 100644 --- a/types/three/src/core/EventDispatcher.d.ts +++ b/types/three/src/core/EventDispatcher.d.ts @@ -53,6 +53,7 @@ export class EventDispatcher { type: T, listener: EventListener, ): void; + addEventListener(type: T, listener: EventListener<{}, T, this>): void; /** * Checks if listener is added to an event type. @@ -63,6 +64,7 @@ export class EventDispatcher { type: T, listener: EventListener, ): boolean; + hasEventListener(type: T, listener: EventListener<{}, T, this>): boolean; /** * Removes a listener from an event type. @@ -73,6 +75,7 @@ export class EventDispatcher { type: T, listener: EventListener, ): void; + removeEventListener(type: T, listener: EventListener<{}, T, this>): void; /** * Fire an event type. diff --git a/types/three/test/unit/src/core/EventDispatcher.ts b/types/three/test/unit/src/core/EventDispatcher.ts index b124e7303..32cd43143 100644 --- a/types/three/test/unit/src/core/EventDispatcher.ts +++ b/types/three/test/unit/src/core/EventDispatcher.ts @@ -42,8 +42,27 @@ eveDisForTestEvent.addEventListener("bar", e => { e.foo; }); -// @ts-expect-error -eveDisForTestEvent.addEventListener("baz", e => {}); +// call addEventListener with an unknown event. The typing should allow you listen any unknown event. +eveDisForTestEvent.addEventListener("baz", e => { + e.type; // $ExpectType "baz" + e.target; // $ExpectType EventDispatcher + // @ts-expect-error + e.bar; + // @ts-expect-error + e.foo; + // @ts-expect-error + e.bar(); +}); +eveDisForTestEvent.addEventListener("NotRegistered", e => { + e.type; // $ExpectType "NotRegistered" + e.target; // $ExpectType EventDispatcher + // @ts-expect-error + e.bar; + // @ts-expect-error + e.foo; + // @ts-expect-error + e.bar(); +}); eveDisForTestEvent.dispatchEvent({ type: "foo", foo: 42 }); eveDisForTestEvent.dispatchEvent({ type: "bar", bar: "42" });