revert "feat(observable): enhance event callback type specificity" (#10721)

Revert "feat(observable): enhance event callback type specificity (#10720)"

This reverts commit e2f9687e72f8cbb618a22ad5e9a81633a984a0d5.
This commit is contained in:
Nathan Walker
2025-03-16 15:53:53 -07:00
committed by GitHub
parent cfc27ebb90
commit 922f6ce56a
2 changed files with 4 additions and 13 deletions

View File

@ -1,4 +1,4 @@
import { Optional, EndsWith } from '../../utils/typescript-utils'; import { Optional } from '../../utils/typescript-utils';
/** /**
* Base event data. * Base event data.
@ -160,7 +160,7 @@ export class Observable {
* `this` context when the callback is called. Falsy values will be not be * `this` context when the callback is called. Falsy values will be not be
* bound. * bound.
*/ */
public on<S extends string>(eventName: S, callback: (data: EndsWith<S, 'Change', PropertyChangeData, EventData>) => void, thisArg?: any): void { public on(eventName: string, callback: (data: EventData) => void, thisArg?: any): void {
this.addEventListener(eventName, callback, thisArg); this.addEventListener(eventName, callback, thisArg);
} }
@ -175,7 +175,7 @@ export class Observable {
* `this` context when the callback is called. Falsy values will be not be * `this` context when the callback is called. Falsy values will be not be
* bound. * bound.
*/ */
public once<S extends string>(eventName: S, callback: (data: EndsWith<S, 'Change', PropertyChangeData, EventData>) => void, thisArg?: any): void { public once(eventName: string, callback: (data: EventData) => void, thisArg?: any): void {
this.addEventListener(eventName, callback, thisArg, true); this.addEventListener(eventName, callback, thisArg, true);
} }
@ -188,7 +188,7 @@ export class Observable {
* @param thisArg An optional parameter which, when set, will be used to * @param thisArg An optional parameter which, when set, will be used to
* refine search of the correct event listener to be removed. * refine search of the correct event listener to be removed.
*/ */
public off<S extends string>(eventName: S, callback?: (data: EndsWith<S, 'Change', PropertyChangeData, EventData>) => void, thisArg?: any): void { public off(eventName: string, callback?: (data: EventData) => void, thisArg?: any): void {
this.removeEventListener(eventName, callback, thisArg); this.removeEventListener(eventName, callback, thisArg);
} }

View File

@ -4,12 +4,3 @@
* // returns: { eventName: string; object?: Observable } * // returns: { eventName: string; object?: Observable }
*/ */
export type Optional<T, K extends keyof T> = Omit<T, K> & { [P in K]?: T[P] }; export type Optional<T, K extends keyof T> = Omit<T, K> & { [P in K]?: T[P] };
/**
* Determines if a string type ends with a specified suffix.
* @example type IsChangeEvent = EndsWith<"propertyNameChange", "Change", true, false>
* // returns: true
* @example type IsChangeEvent = EndsWith<"someEvent", "Change", true, false>
* // returns: false
*/
export type EndsWith<T extends string, S extends string, PassType = true, FailType = false> = T extends `${infer _}${S}` ? PassType : FailType;