Skip to content

Commit

Permalink
Fixed type errors (#2222)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Sep 17, 2024
1 parent 36e0497 commit e542797
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/utils/src/EventTargetShimUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { Event, EventTarget } from 'event-target-shim';
import type {
Event as EventT,
EventTarget as EventTargetT,
} from 'event-target-shim';

export type EventT<T extends string = string> = Event<T>;
export type { EventT };

/**
* A CustomEvent extension which combines the browser CustomEvent and event-target-shim's Event types for type safety
Expand All @@ -17,13 +20,13 @@ export class EventShimCustomEvent<
// https://github.com/babel/babel/issues/12128#issuecomment-702119272
declare type: T;

declare target: EventTarget | null;
declare target: (EventTargetT & EventTarget) | null;

declare srcElement: EventTarget | null;
declare srcElement: (EventTargetT & EventTarget) | null;

declare currentTarget: EventTarget | null;
declare currentTarget: (EventTargetT & EventTarget) | null;

declare composedPath: () => EventTarget[];
declare composedPath: () => (EventTargetT & EventTarget)[];

// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(typeArg: T, eventInitDict?: CustomEventInit<D>) {
Expand All @@ -40,8 +43,8 @@ export type CustomEventMap<M extends Record<string, Event | CustomEvent>> = {
[T in keyof M]: T extends string
? M[T] extends CustomEvent<infer D>
? EventShimCustomEvent<T, D>
: M[T] extends Event
? Event<T>
: M[T] extends EventT
? EventT<T>
: never
: never;
};

0 comments on commit e542797

Please sign in to comment.