From 453adef5fa2a27cc4cb284605fcdb753d2775af0 Mon Sep 17 00:00:00 2001 From: shirakaba <14055146+shirakaba@users.noreply.github.com> Date: Wed, 23 Nov 2022 13:14:48 +0900 Subject: [PATCH] fix: global types --- packages/core/application/application-common.ts | 10 +++++----- packages/core/global-types.d.ts | 12 +----------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/packages/core/application/application-common.ts b/packages/core/application/application-common.ts index a9bdbfd92..7667bc328 100644 --- a/packages/core/application/application-common.ts +++ b/packages/core/application/application-common.ts @@ -4,7 +4,7 @@ import '../globals'; // Types import { AndroidApplication, iOSApplication } from '.'; import { CssChangedEventData, DiscardedErrorEventData, LoadAppCSSEventData, UnhandledErrorEventData } from './application-interfaces'; -import { EventData } from '../data/observable'; +import type { EventData, Observable } from '../data/observable'; import { View } from '../ui/core/view'; // Requires @@ -50,10 +50,10 @@ export function setResources(res: any) { export const android: AndroidApplication = undefined; export const ios: iOSApplication = undefined; -export const on = global.NativeScriptGlobals.events.on.bind(global.NativeScriptGlobals.events); -export const off = global.NativeScriptGlobals.events.off.bind(global.NativeScriptGlobals.events); -export const notify = global.NativeScriptGlobals.events.notify.bind(global.NativeScriptGlobals.events); -export const hasListeners = global.NativeScriptGlobals.events.hasListeners.bind(global.NativeScriptGlobals.events); +export const on = global.NativeScriptGlobals.events.on.bind(global.NativeScriptGlobals.events) as Observable['on']; +export const off = global.NativeScriptGlobals.events.off.bind(global.NativeScriptGlobals.events) as Observable['off']; +export const notify = global.NativeScriptGlobals.events.notify.bind(global.NativeScriptGlobals.events) as Observable['notify']; +export const hasListeners = global.NativeScriptGlobals.events.hasListeners.bind(global.NativeScriptGlobals.events) as Observable['hasListeners']; let app: iOSApplication | AndroidApplication; export function setApplication(instance: iOSApplication | AndroidApplication): void { diff --git a/packages/core/global-types.d.ts b/packages/core/global-types.d.ts index 4a5f224c0..43bb67539 100644 --- a/packages/core/global-types.d.ts +++ b/packages/core/global-types.d.ts @@ -25,17 +25,7 @@ declare namespace NodeJS { * Global framework event handling */ events: { - on(eventNames: string, callback: (data: any) => void, thisArg?: any); - on(event: 'propertyChange', callback: (data: any) => void, thisArg?: any); - off(eventNames: string, callback?: any, thisArg?: any); - addEventListener(eventNames: string, callback: (data: any) => void, thisArg?: any); - removeEventListener(eventNames: string, callback?: any, thisArg?: any); - set(name: string, value: any): void; - setProperty(name: string, value: any): void; - get(name: string): any; - notify(data: any): void; - notifyPropertyChange(propertyName: string, value: any, oldValue?: any): void; - hasListeners(eventName: string): boolean; + [Key in keyof import('data/observable').Observable]: import('data/observable').Observable[Key]; }; launched: boolean; // used by various classes to setup callbacks to wire up global app event handling when the app instance is ready