Skip to content

Commit

Permalink
feat(api): add generics for INotify, Event, Listener types
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Aug 3, 2023
1 parent 834b076 commit dd0a6ed
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/api/src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import type { Fn } from "./fn.js";
import type { IID } from "./id.js";

/**
* Event listener.
* Event listener for {@link Event}.
*/
export type Listener = Fn<Event, void>;
export type Listener<T extends string = string> = Fn<Event<T>, void>;

/**
* Event type used in combination with {@link INotify}.
*/
export interface Event<T extends PropertyKey = PropertyKey> extends IID<T> {
export interface Event<T extends string = string> extends IID<T> {
target?: any;
canceled?: boolean;
value?: any;
Expand All @@ -22,8 +22,8 @@ export interface Event<T extends PropertyKey = PropertyKey> extends IID<T> {
* The type param `T` can be used to constrain the event type/id.
*/
export interface INotify<T extends string = string> {
addListener(id: T, fn: Listener, scope?: any): boolean;
removeListener(id: T, fn: Listener, scope?: any): boolean;
addListener(id: T, fn: Listener<T>, scope?: any): boolean;
removeListener(id: T, fn: Listener<T>, scope?: any): boolean;
/**
* Broadcasts all registered listeners for given event type (in order
* registration) and returns true if any of them have been successfully
Expand Down

0 comments on commit dd0a6ed

Please sign in to comment.