mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-06 17:28:29 +08:00
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:
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
packages/core/utils/typescript-utils.d.ts
vendored
9
packages/core/utils/typescript-utils.d.ts
vendored
@ -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;
|
|
Reference in New Issue
Block a user