UNPKG

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