UNPKG

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