UNPKG

12.6 kBTypeScriptView Raw
1interface ModuleResolver {
2 /**
3 * A function used to resolve the exports for a module.
4 * @param uri The name of the module to be resolved.
5 */
6 (uri: string): any;
7}
8
9/**
10 * An extended JavaScript Error which will have the nativeError property initialized in case the error is caused by executing platform-specific code.
11 */
12declare interface NativeScriptError extends Error {
13 /**
14 * Represents the native error object.
15 */
16 nativeError: any;
17}
18
19//Augment the NodeJS global type with our own extensions
20declare namespace NodeJS {
21 interface Global {
22 NativeScriptHasInitGlobal?: boolean;
23 NativeScriptGlobals?: {
24 /**
25 * Global framework event handling
26 */
27 events: {
28 on(eventNames: string, callback: (data: any) => void, thisArg?: any);
29 on(event: 'propertyChange', callback: (data: any) => void, thisArg?: any);
30 off(eventNames: string, callback?: any, thisArg?: any);
31 addEventListener(eventNames: string, callback: (data: any) => void, thisArg?: any);
32 removeEventListener(eventNames: string, callback?: any, thisArg?: any);
33 set(name: string, value: any): void;
34 setProperty(name: string, value: any): void;
35 get(name: string): any;
36 notify<T>(data: any): void;
37 notifyPropertyChange(propertyName: string, value: any, oldValue?: any): void;
38 hasListeners(eventName: string): boolean;
39 };
40 launched: boolean;
41 // used by various classes to setup callbacks to wire up global app event handling when the app instance is ready
42 appEventWiring: Array<any>;
43 // determines if the app instance is ready upon bootstrap
44 appInstanceReady: boolean;
45
46 /**
47 * Ability for classes to initialize app event handling early even before the app instance is ready during boot cycle avoiding boot race conditions
48 * @param callback wire up any global event handling inside the callback
49 */
50 addEventWiring(callback: () => void): void;
51 };
52 android?: any;
53 require(id: string): any;
54
55 moduleMerge(sourceExports: any, destExports: any): void;
56
57 registerModule(name: string, loader: (name: string) => any): void;
58 /**
59 * Register all modules from a webpack context.
60 * The context is one created using the following webpack utility:
61 * https://webpack.js.org/guides/dependency-management/#requirecontext
62 *
63 * The extension map is optional, modules in the webpack context will have their original file extension (e.g. may be ".ts" or ".scss" etc.),
64 * while the built-in module builders in {N} will look for ".js", ".css" or ".xml" files. Adding a map such as:
65 * ```
66 * { ".ts": ".js" }
67 * ```
68 * Will resolve lookups for .js to the .ts file.
69 * By default scss and ts files are mapped.
70 */
71 registerWebpackModules(context: { keys(): string[]; (key: string): any }, extensionMap?: { [originalFileExtension: string]: string });
72
73 /**
74 * The NativeScript XML builder, style-scope, application modules use various resources such as:
75 * app.css, page.xml files and modules during the application life-cycle.
76 * The moduleResolvers can be used to provide additional mechanisms to locate such resources.
77 * For example:
78 * ```
79 * global.moduleResolvers.unshift(uri => uri === "main-page" ? require("main-page") : null);
80 * ```
81 * More advanced scenarios will allow for specific bundlers to integrate their module resolving mechanisms.
82 * When adding resolvers at the start of the array, avoid throwing and return null instead so subsequent resolvers may try to resolve the resource.
83 * By default the only member of the array is global.require, as last resort - if it fails to find a module it will throw.
84 */
85 readonly moduleResolvers: ModuleResolver[];
86
87 /**
88 *
89 * @param name Name of the module to be loaded
90 * @param loadForUI Is this UI module is being loaded for UI from @nativescript/core/ui/builder.
91 * Xml, css/scss and js/ts modules for pages and custom-components should load with loadForUI=true.
92 * Passing "true" will enable the HMR mechanics this module. Default value is false.
93 */
94 loadModule(name: string, loadForUI?: boolean): any;
95
96 /**
97 * Checks if the module has been registered with `registerModule` or in `registerWebpackModules`
98 * @param name Name of the module
99 */
100 moduleExists(name: string): boolean;
101
102 getRegisteredModules(): string[];
103
104 _unregisterModule(name: string): void;
105
106 _isModuleLoadedForUI(moduleName: string): boolean;
107
108 onGlobalLayoutListener: any;
109 zonedCallback(callback: Function): Function;
110 Reflect?: any;
111 Deprecated(target: Object, key?: string | symbol, descriptor?: any): any;
112 Experimental(target: Object, key?: string | symbol, descriptor?: any): any;
113
114 __native?: any;
115 __inspector?: any;
116 __extends: any;
117 __onLiveSync: (context?: { type: string; path: string }) => void;
118 __onLiveSyncCore: (context?: { type: string; path: string }) => void;
119 __onUncaughtError: (error: NativeScriptError) => void;
120 __onDiscardedError: (error: NativeScriptError) => void;
121 __snapshot?: boolean;
122 TNS_WEBPACK?: boolean;
123 isIOS?: boolean;
124 isAndroid?: boolean;
125 __requireOverride?: (name: string, dir: string) => any;
126
127 // used to get the rootlayout instance to add/remove childviews
128 rootLayout: any;
129 }
130}
131declare const __DEV__: boolean;
132declare const __CSS_PARSER__: string;
133declare const __NS_WEBPACK__: boolean;
134declare const __UI_USE_EXTERNAL_RENDERER__: boolean;
135declare const __UI_USE_XML_PARSER__: boolean;
136declare const __USE_TEST_ID__: boolean | undefined;
137declare const __ANDROID__: boolean;
138declare const __IOS__: boolean;
139
140declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): number;
141declare function clearTimeout(timeoutId: number): void;
142declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): number;
143declare function clearInterval(intervalId: number): void;
144
145declare type ModuleType = 'markup' | 'script' | 'style';
146
147/**
148 * Define a module context for Hot Module Replacement.
149 */
150interface ModuleContext {
151 /**
152 * The type of the module for replacement.
153 */
154 type: ModuleType;
155
156 /**
157 * The path of the module for replacement.
158 */
159 path: string;
160}
161
162interface NodeModule {
163 exports: any;
164 id: string;
165 filename: string;
166}
167
168declare enum RequestContext {
169 'audio',
170 'beacon',
171 'cspreport',
172 'download',
173 'embed',
174 'eventsource',
175 'favicon',
176 'fetch',
177 'font',
178 'form',
179 'frame',
180 'hyperlink',
181 'iframe',
182 'image',
183 'imageset',
184 'import',
185 'internal',
186 'location',
187 'manifest',
188 'object',
189 'ping',
190 'plugin',
191 'prefetch',
192 'script',
193 'serviceworker',
194 'sharedworker',
195 'subresource',
196 'style',
197 'track',
198 'video',
199 'worker',
200 'xmlhttprequest',
201 'xslt',
202}
203
204// Extend the lib.dom.d.ts Body interface with `formData`
205// interface Body {
206// formData(): Promise<FormData>;
207// }
208
209declare type HeaderInit = Headers | Array<string>;
210
211declare function fetch(url: string, init?: RequestInit): Promise<Response>;
212
213// declare var console: Console;
214declare var require: NodeRequire;
215
216// Extend NodeRequire with the webpack's require context extension.
217interface RequireContext {
218 keys(): string[];
219 (id: string): any;
220 <T>(id: string): T;
221 resolve(id: string): string;
222}
223
224declare var __dirname: string;
225declare var __filename: string;
226
227declare var module: NodeModule;
228// Same as module.exports
229declare var exports: any;
230
231// Global functions
232declare function Deprecated(target: Object, key?: string | symbol, value?: any): void;
233declare function Experimental(target: Object, key?: string | symbol, value?: any): void;
234
235declare interface NativeClassOptions {
236 nativeClassName?: string; // for @JavaProxy and
237 protocols?: any[];
238 interfaces?: any[];
239}
240
241/**
242 * Decorates class that extends a native class(iOS or Android)
243 */
244declare function NativeClass<T extends { new (...args: any[]): {} }>(constructor: T);
245declare function NativeClass<T extends { new (...args: any[]): {} }>(options?: NativeClassOptions);
246
247/**
248 * Decorates class that implements native Java interfaces.
249 * @param interfaces Implemented interfaces.
250 */
251declare function Interfaces(...interfaces): ClassDecorator;
252
253/**
254 * Important: Not applicable to Objective-C classes (iOS platform)
255 * Decorates class that extends native Java class
256 * @param interfaces An array of fully-classified Java interface names that the class must implement.
257 */
258declare function Interfaces(interfaces: any[]): ClassDecorator;
259
260/**
261 * Decorates class that extends native Java class
262 * @param nativeClassName The name of the newly generated class. Must be unique in the application.
263 */
264declare function JavaProxy(nativeClassName: string): ClassDecorator;
265
266/**
267 * Important: Not applicable to Java classes (Android platform)
268 * Decorates a class that implements native Objective-C protocols.
269 * @param protocols An array of fully-classified Objective-C protocol names that the class must implement.
270 */
271declare function ObjCClass(...protocols: any[]): ClassDecorator;
272
273/**
274 * Important: Not applicable to Java methods (Android platform)
275 * Decorates method that it is exposed in Objective-C.
276 * The JS name of the method will be used as the name of the native method
277 * and the return type will be set to `interop.types.void`
278 */
279declare function ObjCMethod(): MethodDecorator;
280
281/**
282 * Important: Not applicable to Java methods (Android platform)
283 * Decorates method that it is exposed in Objective-C.
284 * @param name The name of the method to be exposed.
285 * The native return type will be set to `interop.types.void`.
286 */
287declare function ObjCMethod(name: string): MethodDecorator;
288
289/**
290 * Important: Not applicable to Java methods (Android platform)
291 * Decorates a method to be exposed in Objective-C.
292 * The JS name of the method will be used for the name of the native method.
293 * @param returnType The native type of the result.
294 */
295declare function ObjCMethod(returnType: any): MethodDecorator;
296
297/**
298 * Important: Not applicable to Java methods (Android platform)
299 * Decorates a method to be exposed in Objective-C.
300 * @param name The name of the method to be exposed. Can be different than the JS function name
301 * and can follow Objective-C colon syntax (for example `tableView:cellForRowAtIndexPath:`).
302 * @param returnType The native type of the result.
303 */
304declare function ObjCMethod(name: string, returnType: any): MethodDecorator;
305
306/**
307 * Important: Not applicable to Java classes or methods (Android platform)
308 * This is a shorthand decorator that can be used to decorate either a method or a class
309 * to be exposed to Objective-C.
310 * @param params Parameters to send to the ObjCClass or ObjCMethod decorators.
311 */
312declare function ObjC(...params: any[]): ClassDecorator & MethodDecorator;
313
314/**
315 * Important: Not applicable to Java method parameters (Android platform)
316 * Decorates a parameter in an Objective-C exposed method with its native type.
317 * @param type The native type for the parameter.
318 */
319declare function ObjCParam(type: any): ParameterDecorator;
320
321declare function Log(data: any): void;
322declare function log(data: any): void;
323declare function fail(data: any): void;
324
325/**
326 * Calls a function after a specified delay.
327 * @param callback The function to be called.
328 * @param milliseconds The time to wait before the function is called. Defaults to 0.
329 */
330// declare function setTimeout(callback: Function, milliseconds?: number): number;
331
332/**
333 * Clears the delay set by a call to the setTimeout function.
334 * @param id The identifier returned by the previously called setTimeout() method.
335 */
336// declare function clearTimeout(id: number): void;
337
338/**
339 * Calls a function repeatedly with a delay between each call.
340 * @param callback The function to be called.
341 * @param milliseconds The delay between each function call.
342 */
343// declare function setInterval(callback: Function, milliseconds?: number): number;
344
345/**
346 * Clears repeated function which was set up by calling setInterval().
347 * @param id The identifier returned by the setInterval() method.
348 */
349// declare function clearInterval(id: number): void;
350
351declare function zonedCallback(callback: Function): Function;
352
353declare class WeakRef<T> {
354 constructor(obj: T);
355 get(): T;
356 clear(): void;
357}
358
359/**
360 * Create a Java long from a number
361 */
362declare function long(value: number): any;
363
364/**
365 * Create a Java byte from a number
366 */
367declare function byte(value: number): any;
368
369/**
370 * Create a Java short from a number
371 */
372declare function short(value: number): any;
373
374/**
375 * Create a Java double from a number
376 */
377declare function double(value: number): any;
378
379/**
380 * Create a Java float from a number
381 */
382declare function float(value: number): any;
383
384/**
385 * Create a Java char from a string
386 */
387declare function char(value: string): any;