8000 revert "feat(observable): enhance event callback type specificity" by NathanWalker · Pull Request #10721 · NativeScript/NativeScript · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/core/data/observable/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Optional, EndsWith } from '../../utils/typescript-utils';
import { Optional } from '../../utils/typescript-utils';

/**
* Base event data.
Expand Down Expand Up @@ -160,7 +160,7 @@ export class Observable {
* `this` context when the callback is called. Falsy values will be not be
* 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);
}

Expand All @@ -175,7 +175,7 @@ export class Observable {
* `this` context when the callback is called. Falsy values will be not be
* 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);
}

Expand All @@ -188,7 +188,7 @@ export class Observable {
* @param thisArg An optional parameter which, when set, will be used to
* 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);
}

Expand Down
9 changes: 0 additions & 9 deletions packages/core/utils/typescript-utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,3 @@
* // returns: { eventName: string; object?: Observable }
*/
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;
Loading
0