UNPKG

17.4 kBTypeScriptView Raw
1// Type definitions for Ember.js 4.0
2// Project: https://emberjs.com/, https://github.com/emberjs/ember
3// Definitions by: Chris Krycho <https://github.com/chriskrycho>
4// James C. Davis <https://github.com/jamescdavis>
5// Peter Wagenet <https://github.com/wagenet>
6// Dan Freeman <https://github.com/dfreeman>
7// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
8// Minimum TypeScript Version: 4.4
9
10// Capitalization is intentional: this makes it much easier to re-export RSVP on
11// the Ember namespace.
12import Rsvp from 'rsvp';
13
14import { TemplateFactory } from 'htmlbars-inline-precompile';
15
16import { Registry as ServiceRegistry } from '@ember/service';
17import { Registry as ControllerRegistry } from '@ember/controller';
18import * as EmberStringNs from '@ember/string';
19import * as EmberTemplateNs from '@ember/template';
20import * as EmberTemplateHandlebarsNs from '@ember/template/-private/handlebars';
21// tslint:disable-next-line:no-duplicate-imports
22import * as EmberServiceNs from '@ember/service';
23import * as EmberPolyfillsNs from '@ember/polyfills';
24import * as EmberUtilsNs from '@ember/utils';
25import * as EmberRunloopNs from '@ember/runloop';
26import * as EmberObjectNs from '@ember/object';
27import * as EmberObjectObserversNs from '@ember/object/observers';
28import * as EmberObjectMixinNs from '@ember/object/mixin';
29import * as EmberObjectProxyNs from '@ember/object/proxy';
30import * as EmberObjectPromiseProxyNs from '@ember/object/promise-proxy-mixin';
31import * as EmberObjectInternalsNs from '@ember/object/internals';
32import * as EmberObjectComputedNs from '@ember/object/computed';
33import * as EmberObjectEventedNs from '@ember/object/evented';
34import * as EmberObjectEventsNs from '@ember/object/events';
35// @ember/debug
36import * as EmberDebugNs from '@ember/debug';
37import _ContainerDebugAdapter from '@ember/debug/container-debug-adapter';
38import EmberDataAdapter from '@ember/debug/data-adapter';
39// @ember/engine
40import * as EmberEngineNs from '@ember/engine';
41import * as EmberEngineInstanceNs from '@ember/engine/instance';
42import _ContainerProxyMixin from '@ember/engine/-private/container-proxy-mixin';
43import _RegistryProxyMixin from '@ember/engine/-private/registry-proxy-mixin';
44import EmberCoreObject from '@ember/object/core';
45import * as EmberApplicationNs from '@ember/application';
46import * as EmberApplicationInstanceNs from '@ember/application/instance';
47import * as EmberApplicationDeprecateNs from '@ember/application/deprecations';
48import * as EmberTestNs from '@ember/test';
49// tslint:disable-next-line:no-duplicate-imports
50import * as EmberControllerNs from '@ember/controller';
51// tslint:disable-next-line:no-duplicate-imports
52import EmberMixin from '@ember/object/mixin';
53import EmberObservable from '@ember/object/observable';
54// @ember/array
55import * as EmberArrayNs from '@ember/array';
56import EmberMutableArray from '@ember/array/mutable';
57import EmberNativeArray from '@ember/array/-private/native-array';
58import EmberArrayProxy from '@ember/array/proxy';
59import EmberEnumerable from '@ember/array/-private/enumerable';
60import EmberMutableEnumerable from '@ember/array/-private/mutable-enumerable';
61import EmberArrayProtoExtensions from '@ember/array/types/prototype-extensions';
62// @ember/error
63import EmberError from '@ember/error';
64
65type EmberArray<T> = EmberArrayNs.default<T>;
66import EmberActionHandler from '@ember/object/-private/action-handler';
67import EmberComponent from '@ember/component';
68import EmberHelper from '@ember/component/helper';
69// @ember/routing
70import EmberRoutingRouter from '@ember/routing/router';
71import EmberRoutingRoute from '@ember/routing/route';
72import EmberRoutingTransition from '@ember/routing/transition';
73import EmberRoutingRouterService from '@ember/routing/router-service';
74import EmberRoutingHashLocation from '@ember/routing/hash-location';
75import EmberRoutingAutoLocation from '@ember/routing/auto-location';
76import EmberRoutingHistoryLocation from '@ember/routing/history-location';
77import EmberRoutingNoneLocation from '@ember/routing/none-location';
78// @ember/application
79import EmberEventDispatcher from '@ember/application/-private/event-dispatcher';
80import EmberRegistry from '@ember/application/-private/registry';
81// @ember/test
82import EmberTestAdapter from '@ember/test/adapter';
83
84export namespace Ember {
85 const A: typeof EmberArrayNs.A;
86 const isArray: typeof EmberArrayNs.isArray;
87 type Enumerable<T> = EmberEnumerable<T>;
88 const Enumerable: typeof EmberEnumerable;
89 class ArrayProxy<T> extends EmberArrayProxy<T> {}
90 type Array<T> = EmberArray<T>;
91 const Array: typeof EmberArrayNs.default;
92 type MutableArray<T> = EmberMutableArray<T>;
93 const MutableArray: typeof EmberMutableArray;
94 type NativeArray<T> = EmberNativeArray<T>;
95 const NativeArray: typeof EmberNativeArray;
96 type MutableEnumerable<T> = EmberMutableEnumerable<T>;
97 const MutableEnumerable: typeof EmberMutableEnumerable;
98 class Router extends EmberRoutingRouter {}
99 class Route extends EmberRoutingRoute {}
100 const ActionHandler: typeof EmberActionHandler;
101 class Controller extends EmberControllerNs.default {}
102 class Component extends EmberComponent {}
103 class Helper extends EmberHelper {}
104
105 class HashLocation extends EmberRoutingHashLocation {}
106 class NoneLocation extends EmberRoutingNoneLocation {}
107 class HistoryLocation extends EmberRoutingHistoryLocation {}
108 const deprecateFunc: typeof EmberApplicationDeprecateNs.deprecateFunc;
109 const deprecate: typeof EmberApplicationDeprecateNs.deprecate;
110 const getOwner: typeof EmberApplicationNs.getOwner;
111 const setOwner: typeof EmberApplicationNs.setOwner;
112 class EventDispatcher extends EmberEventDispatcher {}
113 class Registry extends EmberRegistry {}
114 interface ArrayPrototypeExtensions<T> extends EmberArrayProtoExtensions<T> {}
115
116 /**
117 * Implements some standard methods for comparing objects. Add this mixin to
118 * any class you create that can compare its instances.
119 */
120 interface Comparable {
121 compare(a: unknown, b: unknown): number;
122 }
123 const Comparable: EmberMixin<Comparable>;
124 class ComputedProperty<Get, Set = Get> extends EmberObjectComputedNs.default<Get, Set> {}
125 /**
126 * A container used to instantiate and cache objects.
127 */
128 class Container {
129 /**
130 * Given a fullName, return the corresponding factory. The consumer of the factory
131 * is responsible for the destruction of any factory instances, as there is no
132 * way for the container to ensure instances are destroyed when it itself is
133 * destroyed.
134 */
135 factoryFor(fullName: string, options?: {}): unknown;
136 }
137 class ContainerDebugAdapter extends _ContainerDebugAdapter {}
138
139 // TODO: replace with a proper ES6 reexport once we remove declare module 'ember' {}
140 class Object extends EmberObjectNs.default {}
141 class ObjectProxy extends EmberObjectProxyNs.default {}
142 const Observable: typeof EmberObservable;
143 const PromiseProxyMixin: typeof EmberObjectPromiseProxyNs.default;
144 class CoreObject extends EmberCoreObject {}
145 class DataAdapter extends EmberDataAdapter {}
146 const Debug: {
147 registerDeprecationHandler: typeof EmberDebugNs.registerDeprecationHandler;
148 registerWarnHandler: typeof EmberDebugNs.registerWarnHandler;
149 };
150 class EngineInstance extends EmberEngineInstanceNs.default {}
151 class Engine extends EmberEngineNs.default {}
152
153 /**
154 * A subclass of the JavaScript Error object for use in Ember.
155 */
156 const Error: typeof EmberError;
157
158 const Evented: typeof EmberObjectEventedNs.default;
159
160 class Mixin<T, Base = EmberObjectNs.default> extends EmberMixin<T, Base> {}
161
162 /**
163 * A Namespace is an object usually used to contain other objects or methods
164 * such as an application or framework. Create a namespace anytime you want
165 * to define one of these new containers.
166 */
167 class Namespace extends Object {}
168
169 class Service extends Object {}
170
171 interface ViewTargetActionSupport {
172 target: unknown;
173 actionContext: unknown;
174 }
175 const ViewTargetActionSupport: Mixin<ViewTargetActionSupport>;
176 const ViewUtils: {
177 isSimpleClick(event: Event): boolean;
178 };
179
180 // FYI - RSVP source comes from https://github.com/tildeio/rsvp.js/blob/master/lib/rsvp/promise.js
181 const RSVP: typeof Rsvp;
182 namespace RSVP {
183 type Promise<T> = Rsvp.Promise<T>;
184 }
185 class Application extends EmberApplicationNs.default {}
186 class ApplicationInstance extends EmberApplicationInstanceNs.default {}
187 /**
188 * This is a container for an assortment of testing related functionality
189 */
190 namespace Test {
191 class Adapter extends EmberTestAdapter {}
192 const registerHelper: typeof EmberTestNs.registerHelper;
193 const unregisterHelper: typeof EmberTestNs.unregisterHelper;
194 const registerWaiter: typeof EmberTestNs.registerWaiter;
195 const unregisterWaiter: typeof EmberTestNs.unregisterWaiter;
196 const registerAsyncHelper: typeof EmberTestNs.registerAsyncHelper;
197 /**
198 * Used to register callbacks to be fired whenever `App.injectTestHelpers`
199 * is called.
200 */
201 function onInjectHelpers(callback: (app: Application) => void): void;
202 /**
203 * This returns a thenable tailored for testing. It catches failed
204 * `onSuccess` callbacks and invokes the `Ember.Test.adapter.exception`
205 * callback in the last chained then.
206 */
207 function promise<T>(
208 resolver: (
209 resolve: (value?: T | PromiseLike<T>) => void,
210 reject: (reason?: unknown) => void
211 ) => void,
212 label?: string
213 ): Promise<T>;
214 /**
215 * Replacement for `Ember.RSVP.resolve`
216 * The only difference is this uses
217 * an instance of `Ember.Test.Promise`
218 */
219 function resolve<T>(value?: T | PromiseLike<T>, label?: string): Promise<T>;
220
221 /**
222 * Iterates through each registered test waiter, and invokes
223 * its callback. If any waiter returns false, this method will return
224 * true indicating that the waiters have not settled yet.
225 */
226 function checkWaiters(): boolean;
227 /**
228 * Used to allow ember-testing to communicate with a specific testing
229 * framework.
230 */
231 const adapter: EmberTestAdapter;
232
233 /**
234 * This class implements the methods defined by Ember.Test.Adapter for the
235 * QUnit testing framework.
236 */
237 class QUnitAdapter extends EmberTestAdapter {}
238 class Promise<T> extends Rsvp.Promise<T> {
239 constructor(
240 executor: (
241 resolve: (value?: T | PromiseLike<T>) => void,
242 reject: (reason?: unknown) => void
243 ) => void
244 );
245 }
246 }
247 /**
248 * Namespace for injection helper methods.
249 */
250 namespace inject {
251 /**
252 * Creates a property that lazily looks up another controller in the container.
253 * Can only be used when defining another controller.
254 */
255 function controller(): ComputedProperty<Controller>;
256 function controller<K extends keyof ControllerRegistry>(
257 name: K
258 ): ComputedProperty<ControllerRegistry[K]>;
259 const service: typeof EmberServiceNs.inject;
260 }
261 namespace ENV {
262 const EXTEND_PROTOTYPES: {
263 Array: boolean;
264 Function: boolean;
265 String: boolean;
266 };
267 const LOG_BINDINGS: boolean;
268 const LOG_STACKTRACE_ON_DEPRECATION: boolean;
269 const LOG_VERSION: boolean;
270 const MODEL_FACTORY_INJECTIONS: boolean;
271 const RAISE_ON_DEPRECATION: boolean;
272 }
273 namespace Handlebars {
274 function compile(string: string): (...args: any[]) => any;
275 function compile(environment: any, options?: any, context?: any, asObject?: any): any;
276 function precompile(string: string, options: any): void;
277 class Compiler {}
278 class JavaScriptCompiler {}
279 function registerPartial(name: string, str: any): void;
280 function createFrame(objec: any): any;
281 function Exception(message: string): void;
282 class SafeString extends EmberTemplateHandlebarsNs.SafeString {}
283 function parse(string: string): any;
284 function print(ast: any): void;
285 function log(level: string, str: string): void;
286 function registerHelper(name: string, helper: any): void;
287 }
288 namespace String {
289 const camelize: typeof EmberStringNs.camelize;
290 const capitalize: typeof EmberStringNs.capitalize;
291 const classify: typeof EmberStringNs.classify;
292 const dasherize: typeof EmberStringNs.dasherize;
293 const decamelize: typeof EmberStringNs.decamelize;
294 function fmt(...args: string[]): string;
295 const htmlSafe: typeof EmberTemplateNs.htmlSafe;
296 const isHTMLSafe: typeof EmberTemplateNs.isHTMLSafe;
297 const underscore: typeof EmberStringNs.underscore;
298 const w: typeof EmberStringNs.w;
299 }
300 namespace Template {
301 const htmlSafe: typeof EmberTemplateNs.htmlSafe;
302 const isHTMLSafe: typeof EmberTemplateNs.isHTMLSafe;
303 }
304 const computed: typeof EmberObjectNs.computed & typeof EmberObjectComputedNs;
305
306 // Shenanigans to make `run` both callable and a namespace safely, while not
307 // making the `run.bind` call resolve to `Function.prototype.bind`. (Yes,
308 // insert :upside-down-smiley: here.)
309 // 1. Get the type side of the namespace.
310 type EmberRunloop = typeof EmberRunloopNs;
311 // 2. Use it to get an interface representing the callable side of `run`.
312 type RunFn = EmberRunloop['run'];
313 // type RunFn = Pick<EmberRunloop, 'run'>['run'];
314 // 3. Merge the two together so that the public-facing type of `run` is both
315 // the plucked-off run type *and* the namespace.
316 interface Run extends RunFn, EmberRunloop {}
317 const run: Run;
318
319 const platform: {
320 defineProperty: boolean;
321 hasPropertyAccessors: boolean;
322 };
323
324 /**
325 * `getEngineParent` retrieves an engine instance's parent instance.
326 */
327 function getEngineParent(engine: EngineInstance): EngineInstance;
328
329 const assert: typeof EmberDebugNs.assert;
330 const debug: typeof EmberDebugNs.debug;
331 const defineProperty: typeof EmberObjectNs.defineProperty;
332
333 const runInDebug: typeof EmberDebugNs.runInDebug;
334 const warn: typeof EmberDebugNs.warn;
335 const cacheFor: typeof EmberObjectInternalsNs.cacheFor;
336 const addListener: typeof EmberObjectEventsNs.addListener;
337 const removeListener: typeof EmberObjectEventsNs.removeListener;
338 const sendEvent: typeof EmberObjectEventsNs.sendEvent;
339 const on: typeof EmberObjectEventedNs.on;
340
341 const htmlSafe: typeof EmberTemplateNs.htmlSafe;
342 const isHTMLSafe: typeof EmberTemplateNs.isHTMLSafe;
343
344 const isBlank: typeof EmberUtilsNs.isBlank;
345 const isEmpty: typeof EmberUtilsNs.isEmpty;
346 const isNone: typeof EmberUtilsNs.isNone;
347 const isPresent: typeof EmberUtilsNs.isPresent;
348
349 const observer: typeof EmberObjectNs.observer;
350 const addObserver: typeof EmberObjectObserversNs.addObserver;
351 const removeObserver: typeof EmberObjectObserversNs.removeObserver;
352 const get: typeof EmberObjectNs.get;
353 const notifyPropertyChange: typeof EmberObjectNs.notifyPropertyChange;
354 const getProperties: typeof EmberObjectNs.getProperties;
355 const setProperties: typeof EmberObjectNs.setProperties;
356 const set: typeof EmberObjectNs.set;
357 const trySet: typeof EmberObjectNs.trySet;
358 const compare: typeof EmberUtilsNs.compare;
359 /**
360 * Creates a shallow copy of the passed object. A deep copy of the object is
361 * returned if the optional `deep` argument is `true`.
362 */
363 const isEqual: typeof EmberUtilsNs.isEqual;
364 const typeOf: typeof EmberUtilsNs.typeOf;
365 // TODO: replace with an es6 reexport when declare module 'ember' is removed
366 /**
367 * Copy properties from a source object to a target object.
368 * @deprecated until v5.0. You should replace any calls to `Ember.assign`
369 * with `Object.assign` or use the object spread operator.
370 */
371 const assign: typeof EmberPolyfillsNs.assign;
372 const guidFor: typeof EmberObjectInternalsNs.guidFor;
373
374 /**
375 * A function may be assigned to `Ember.onerror` to be called when Ember
376 * internals encounter an error. This is useful for specialized error handling
377 * and reporting code.
378 */
379 let onerror: ((error: Error) => void) | undefined;
380
381 /**
382 * The semantic version
383 */
384 const VERSION: string;
385 /**
386 * This property indicates whether or not this application is currently in
387 * testing mode. This is set when `setupForTesting` is called on the current
388 * application.
389 */
390 const testing: boolean;
391
392 const expandProperties: typeof EmberObjectComputedNs.expandProperties;
393}
394
395export default Ember;
396
397declare module 'htmlbars-inline-precompile' {
398 interface TemplateFactory {
399 __htmlbars_inline_precompile_template_factory: any;
400 }
401 export default function hbs(tagged: TemplateStringsArray): TemplateFactory;
402}
403
\No newline at end of file