UNPKG

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