From 572137414c8988d3d80a76b37bff7446ee2a8730 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 19 Dec 2017 16:10:50 -0700 Subject: [PATCH 1/5] Update Ember, Ember Data, Ember QUnit types. --- types/ember-data/index.d.ts | 187 +++++++-------- types/ember-data/test/model.ts | 5 +- types/ember-data/test/store.ts | 29 +-- types/ember-qunit/index.d.ts | 3 +- types/ember/index.d.ts | 405 ++++++++++++++++++++++++++------- types/ember/test/computed.ts | 37 +-- 6 files changed, 464 insertions(+), 202 deletions(-) diff --git a/types/ember-data/index.d.ts b/types/ember-data/index.d.ts index c8cfd8187e..36bda4889c 100644 --- a/types/ember-data/index.d.ts +++ b/types/ember-data/index.d.ts @@ -7,6 +7,7 @@ declare module "ember-data" { import Ember from "ember"; + import RSVP from 'rsvp'; namespace DS { /** * Convert an hash of errors into an array with errors in JSON-API format. @@ -207,7 +208,7 @@ declare module "ember-data" { * subclasses are used to indicate specific error states. The following * subclasses are provided: */ - class AdapterError {} + class AdapterError { } /** * A `DS.InvalidError` is used by an adapter to signal the external API * was unable to process a request because the content was not @@ -217,27 +218,27 @@ declare module "ember-data" { * transition to the `invalid` state and the errors will be set to the * `errors` property on the record. */ - class InvalidError {} + class InvalidError { } /** * A `DS.TimeoutError` is used by an adapter to signal that a request * to the external API has timed out. I.e. no response was received from * the external API within an allowed time period. */ - class TimeoutError {} + class TimeoutError { } /** * A `DS.AbortError` is used by an adapter to signal that a request to * the external API was aborted. For example, this can occur if the user * navigates away from the current page after a request to the external API * has been initiated but before a response has been received. */ - class AbortError {} + class AbortError { } /** * A `DS.UnauthorizedError` equates to a HTTP `401 Unauthorized` response * status. It is used by an adapter to signal that a request to the external * API was rejected because authorization is required and has failed or has not * yet been provided. */ - class UnauthorizedError {} + class UnauthorizedError { } /** * A `DS.ForbiddenError` equates to a HTTP `403 Forbidden` response status. * It is used by an adapter to signal that a request to the external API was @@ -245,13 +246,13 @@ declare module "ember-data" { * provided and is valid, then the authenticated user does not have the * necessary permissions for the request. */ - class ForbiddenError {} + class ForbiddenError { } /** * A `DS.NotFoundError` equates to a HTTP `404 Not Found` response status. * It is used by an adapter to signal that a request to the external API * was rejected because the resource could not be found on the API. */ - class NotFoundError {} + class NotFoundError { } /** * A `DS.ConflictError` equates to a HTTP `409 Conflict` response status. * It is used by an adapter to indicate that the request could not be processed @@ -259,17 +260,17 @@ declare module "ember-data" { * creating a record with a client generated id but that id is already known * to the external API. */ - class ConflictError {} + class ConflictError { } /** * A `DS.ServerError` equates to a HTTP `500 Internal Server Error` response * status. It is used by the adapter to indicate that a request has failed * because of an error in the external API. */ - class ServerError {} + class ServerError { } /** * Holds validation errors for a given record, organized by attribute names. */ - interface Errors extends Ember.Enumerable, Ember.Evented {} + interface Errors extends Ember.Enumerable, Ember.Evented { } class Errors extends Ember.Object { /** * DEPRECATED: @@ -423,7 +424,7 @@ declare module "ember-data" { * Create a JSON representation of the record, using the serialization * strategy of the store's adapter. */ - serialize(options: {}): {}; + serialize(options?: {}): {}; /** * Use [DS.JSONSerializer](DS.JSONSerializer.html) to * get the JSON representation of a record. @@ -472,7 +473,7 @@ declare module "ember-data" { /** * Same as `deleteRecord`, but saves the record immediately. */ - destroyRecord(options: {}): Promise; + destroyRecord(options: {}): RSVP.Promise; /** * Unloads the record from the store. This will cause the record to be destroyed and freed up for garbage collection. */ @@ -491,11 +492,11 @@ declare module "ember-data" { * Save the record and persist any changes to the record to an * external source via the adapter. */ - save(options?: {}): Promise; + save(options?: {}): RSVP.Promise; /** * Reload the record from the adapter. */ - reload(): Promise; + reload(): RSVP.Promise; /** * Get the reference for the specified belongsTo relationship. */ @@ -543,7 +544,7 @@ declare module "ember-data" { */ static relatedTypes: Ember.ComputedProperty< Ember.NativeArray - >; + >; /** * A map whose keys are the relationships of a model and whose values are * relationship descriptors. @@ -612,14 +613,14 @@ declare module "ember-data" { /** * ### State */ - class RootState {} + class RootState { } /** * Represents an ordered list of records whose order and membership is * determined by the adapter. For example, a query sent to the adapter * may trigger a search on the server, whose results would be loaded * into an instance of the `AdapterPopulatedRecordArray`. */ - class AdapterPopulatedRecordArray extends RecordArray {} + class AdapterPopulatedRecordArray extends RecordArray { } /** * Represents a list of records whose membership is determined by the * store. As records are created, loaded, or modified, the store @@ -640,7 +641,7 @@ declare module "ember-data" { * `DS.RecordArray` or its subclasses will be returned by your application's store * in response to queries. */ - interface RecordArray extends Ember.ArrayProxy, Ember.Evented {} + interface RecordArray extends Ember.ArrayProxy, Ember.Evented { } class RecordArray { /** * The flag to signal a `RecordArray` is finished loading data. @@ -698,7 +699,7 @@ declare module "ember-data" { * Data will treat the new data as the conanical value of this * relationship on the backend. */ - push(objectOrPromise: {} | Promise): Promise; + push(objectOrPromise: {} | RSVP.Promise): RSVP.Promise; /** * `value()` synchronously returns the current value of the belongs-to * relationship. Unlike `record.get('relationshipName')`, calling @@ -706,20 +707,20 @@ declare module "ember-data" { * relationship is not yet loaded. If the relationship is not loaded * it will always return `null`. */ - value(objectOrPromise: {} | Promise): Model; + value(objectOrPromise: {} | RSVP.Promise): Model; /** * Loads a record in a belongs to relationship if it is not already * loaded. If the relationship is already loaded this method does not * trigger a new load. */ - load(): Promise; + load(): RSVP.Promise; /** * Triggers a reload of the value in this relationship. If the * remoteType is `"link"` Ember Data will use the relationship link to * reload the relationship. Otherwise it will reload the record by its * id. */ - reload(): Promise; + reload(): RSVP.Promise; } /** * A HasManyReference is a low level API that allows users and addon @@ -750,7 +751,7 @@ declare module "ember-data" { * Data will treat the new data as the canonical value of this * relationship on the backend. */ - push(objectOrPromise: T[] | Promise): ManyArray; + push(objectOrPromise: T[] | RSVP.Promise): ManyArray; /** * `value()` synchronously returns the current value of the has-many * relationship. Unlike `record.get('relationshipName')`, calling @@ -764,11 +765,11 @@ declare module "ember-data" { * relationship is already loaded this method does not trigger a new * load. */ - load(): Promise; + load(): RSVP.Promise; /** * Reloads this has-many relationship. */ - reload(): Promise; + reload(): RSVP.Promise; } /** * An RecordReference is a low level API that allows users and @@ -791,7 +792,7 @@ declare module "ember-data" { * normalized hash of data and the object represented by the reference * will update. */ - push(payload: Promise | {}): PromiseObject & T; + push(payload: RSVP.Promise | {}): PromiseObject & T; /** * If the entity referred to by the reference is already loaded, it is * present as `reference.value`. Otherwise the value returned by this function @@ -813,7 +814,7 @@ declare module "ember-data" { * A `ManyArray` is a `MutableArray` that represents the contents of a has-many * relationship. */ - interface ManyArray extends Ember.MutableArray {} + interface ManyArray extends Ember.MutableArray { } class ManyArray extends Ember.Object.extend( Ember.MutableArray as {}, Ember.Evented @@ -851,8 +852,8 @@ declare module "ember-data" { */ interface PromiseArray extends Ember.ArrayProxy, - Ember.PromiseProxyMixin> {} - class PromiseArray {} + Ember.PromiseProxyMixin> { } + class PromiseArray { } /** * A `PromiseObject` is an object that acts like both an `Ember.Object` * and a promise. When the promise is resolved, then the resulting value @@ -862,8 +863,8 @@ declare module "ember-data" { */ interface PromiseObject extends Ember.ObjectProxy, - Ember.PromiseProxyMixin> {} - class PromiseObject {} + Ember.PromiseProxyMixin> { } + class PromiseObject { } /** * A PromiseManyArray is a PromiseArray that also proxies certain method calls * to the underlying manyArray. @@ -1042,7 +1043,7 @@ declare module "ember-data" { queryRecord( modelName: string, query: any - ): Promise; + ): RSVP.Promise; /** * `findAll` asks the adapter's `findAll` method to find the records for the * given type, and returns a promise which will resolve with all records of @@ -1077,7 +1078,7 @@ declare module "ember-data" { /** * Returns the model class for the particular `modelName`. */ - modelFor(modelName: string): Model; + modelFor(modelName: string): M; /** * Push some data for a given type into the store. */ @@ -1097,13 +1098,13 @@ declare module "ember-data" { * example, `adapterFor('person')` will return an instance of * `App.PersonAdapter`. */ - adapterFor(modelName: string): Adapter; + adapterFor(modelName: string): A; /** * Returns an instance of the serializer for a given type. For * example, `serializerFor('person')` will return an instance of * `App.PersonSerializer`. */ - serializerFor(modelName: string): Serializer; + serializerFor(modelName: string): S; } /** * The `JSONAPIAdapter` is the default adapter used by Ember Data. It @@ -1129,7 +1130,7 @@ declare module "ember-data" { /** * Takes a URL, an HTTP method and a hash of data, and makes an HTTP request. */ - ajax(url: string, type: string, options?: object): Promise; + ajax(url: string, type: string, options?: object): RSVP.Promise; /** * Generate ajax options */ @@ -1172,7 +1173,7 @@ declare module "ember-data" { type: Model, id: string, snapshot: Snapshot - ): Promise; + ): RSVP.Promise; /** * Called by the store in order to fetch a JSON array for all * of the records for a given type. @@ -1182,17 +1183,17 @@ declare module "ember-data" { type: Model, sinceToken: string, snapshotRecordArray: SnapshotRecordArray - ): Promise; + ): RSVP.Promise; /** * Called by the store in order to fetch a JSON array for * the records that match a particular query. */ - query(store: Store, type: Model, query: {}): Promise; + query(store: Store, type: Model, query: {}): RSVP.Promise; /** * Called by the store in order to fetch a JSON object for * the record that matches a particular query. */ - queryRecord(store: Store, type: Model, query: {}): Promise; + queryRecord(store: Store, type: Model, query: {}): RSVP.Promise; /** * Called by the store in order to fetch several records together if `coalesceFindRequests` is true */ @@ -1201,7 +1202,7 @@ declare module "ember-data" { type: Model, ids: any[], snapshots: any[] - ): Promise; + ): RSVP.Promise; /** * Called by the store in order to fetch a JSON array for * the unloaded records in a has-many relationship that were originally @@ -1212,7 +1213,7 @@ declare module "ember-data" { snapshot: Snapshot, url: string, relationship: {} - ): Promise; + ): RSVP.Promise; /** * Called by the store in order to fetch the JSON for the unloaded record in a * belongs-to relationship that was originally specified as a URL (inside of @@ -1222,7 +1223,7 @@ declare module "ember-data" { store: Store, snapshot: Snapshot, url: string - ): Promise; + ): RSVP.Promise; /** * Called by the store when a newly created record is * saved via the `save` method on a model record instance. @@ -1231,7 +1232,7 @@ declare module "ember-data" { store: Store, type: Model, snapshot: Snapshot - ): Promise; + ): RSVP.Promise; /** * Called by the store when an existing record is saved * via the `save` method on a model record instance. @@ -1240,7 +1241,7 @@ declare module "ember-data" { store: Store, type: Model, snapshot: Snapshot - ): Promise; + ): RSVP.Promise; /** * Called by the store when a record is deleted. */ @@ -1248,7 +1249,7 @@ declare module "ember-data" { store: Store, type: Model, snapshot: Snapshot - ): Promise; + ): RSVP.Promise; /** * Organize records into groups, each of which is to be passed to separate * calls to `findMany`. @@ -1816,7 +1817,7 @@ declare module "ember-data" { * used when `boolean` is passed as the type parameter to the * [DS.attr](../../data#method_attr) function. */ - class BooleanTransform extends Transform {} + class BooleanTransform extends Transform { } /** * The `DS.DateTransform` class is used to serialize and deserialize * date attributes on Ember Data record objects. This transform is used @@ -1824,21 +1825,21 @@ declare module "ember-data" { * [DS.attr](../../data#method_attr) function. It uses the [`ISO 8601`](https://en.wikipedia.org/wiki/ISO_8601) * standard. */ - class DateTransform extends Transform {} + class DateTransform extends Transform { } /** * The `DS.NumberTransform` class is used to serialize and deserialize * numeric attributes on Ember Data record objects. This transform is * used when `number` is passed as the type parameter to the * [DS.attr](../../data#method_attr) function. */ - class NumberTransform extends Transform {} + class NumberTransform extends Transform { } /** * The `DS.StringTransform` class is used to serialize and deserialize * string attributes on Ember Data record objects. This transform is * used when `string` is passed as the type parameter to the * [DS.attr](../../data#method_attr) function. */ - class StringTransform extends Transform {} + class StringTransform extends Transform { } /** * The `DS.Transform` class is used to serialize and deserialize model * attributes when they are saved or loaded from an @@ -1885,7 +1886,7 @@ declare module "ember-data" { type: Model, id: string, snapshot: Snapshot - ): Promise; + ): RSVP.Promise; /** * The `findAll()` method is used to retrieve all records for a given type. */ @@ -1894,7 +1895,7 @@ declare module "ember-data" { type: Model, sinceToken: string, snapshotRecordArray: SnapshotRecordArray - ): Promise; + ): RSVP.Promise; /** * This method is called when you call `query` on the store. */ @@ -1903,12 +1904,12 @@ declare module "ember-data" { type: Model, query: {}, recordArray: AdapterPopulatedRecordArray - ): Promise; + ): RSVP.Promise; /** * The `queryRecord()` method is invoked when the store is asked for a single * record through a query object. */ - queryRecord(store: Store, type: Model, query: {}): Promise; + queryRecord(store: Store, type: Model, query: {}): RSVP.Promise; /** * If the globally unique IDs for your records should be generated on the client, * implement the `generateIdForRecord()` method. This method will be invoked @@ -1932,7 +1933,7 @@ declare module "ember-data" { store: Store, type: Model, snapshot: Snapshot - ): Promise; + ): RSVP.Promise; /** * Implement this method in a subclass to handle the updating of * a record. @@ -1941,7 +1942,7 @@ declare module "ember-data" { store: Store, type: Model, snapshot: Snapshot - ): Promise; + ): RSVP.Promise; /** * Implement this method in a subclass to handle the deletion of * a record. @@ -1950,7 +1951,7 @@ declare module "ember-data" { store: Store, type: Model, snapshot: Snapshot - ): Promise; + ): RSVP.Promise; /** * By default the store will try to coalesce all `fetchRecord` calls within the same runloop * into as few requests as possible by calling groupRecordsForFindMany and passing it into a findMany call. @@ -1968,7 +1969,7 @@ declare module "ember-data" { type: Model, ids: any[], snapshots: any[] - ): Promise; + ): RSVP.Promise; /** * Organize records into groups, each of which is to be passed to separate * calls to `findMany`. @@ -2068,63 +2069,63 @@ declare module "ember" { } } declare module 'ember-data/adapter' { - import DS from 'ember-data'; - export default DS.Adapter; + import DS from 'ember-data'; + export default DS.Adapter; } declare module 'ember-data/adapters/errors' { - import DS from 'ember-data'; - const AdapterError: typeof DS.AdapterError; - const InvalidError: typeof DS.InvalidError; - const UnauthorizedError: typeof DS.UnauthorizedError; - const ForbiddenError: typeof DS.ForbiddenError; - const NotFoundError: typeof DS.NotFoundError; - const ConflictError: typeof DS.ConflictError; - const ServerError: typeof DS.ServerError; - const TimeoutError: typeof DS.TimeoutError; - const AbortError: typeof DS.AbortError; - const errorsHashToArray: typeof DS.errorsHashToArray; - const errorsArrayToHash: typeof DS.errorsArrayToHash; + import DS from 'ember-data'; + const AdapterError: typeof DS.AdapterError; + const InvalidError: typeof DS.InvalidError; + const UnauthorizedError: typeof DS.UnauthorizedError; + const ForbiddenError: typeof DS.ForbiddenError; + const NotFoundError: typeof DS.NotFoundError; + const ConflictError: typeof DS.ConflictError; + const ServerError: typeof DS.ServerError; + const TimeoutError: typeof DS.TimeoutError; + const AbortError: typeof DS.AbortError; + const errorsHashToArray: typeof DS.errorsHashToArray; + const errorsArrayToHash: typeof DS.errorsArrayToHash; } declare module 'ember-data/adapters/json-api' { - import DS from 'ember-data'; - export default DS.JSONAPIAdapter; + import DS from 'ember-data'; + export default DS.JSONAPIAdapter; } declare module 'ember-data/adapters/rest' { - import DS from 'ember-data'; - export default DS.RESTAdapter; + import DS from 'ember-data'; + export default DS.RESTAdapter; } declare module 'ember-data/attr' { - import DS from 'ember-data'; - export default DS.attr; + import DS from 'ember-data'; + export default DS.attr; } declare module 'ember-data/model' { - import DS from 'ember-data'; - export default DS.Model; + import DS from 'ember-data'; + export default DS.Model; } declare module 'ember-data/relationships' { - import DS from 'ember-data'; - const hasMany: typeof DS.hasMany; - const belongsTo: typeof DS.belongsTo; + import DS from 'ember-data'; + const hasMany: typeof DS.hasMany; + const belongsTo: typeof DS.belongsTo; } declare module 'ember-data/serializer' { - import DS from 'ember-data'; - export default DS.Serializer; + import DS from 'ember-data'; + export default DS.Serializer; } declare module 'ember-data/serializers/embedded-records-mixin' { - import DS from 'ember-data'; - export default DS.EmbeddedRecordsMixin; + import DS from 'ember-data'; + export default DS.EmbeddedRecordsMixin; } declare module 'ember-data/serializers/json-api' { - import DS from 'ember-data'; - export default DS.JSONAPISerializer; + import DS from 'ember-data'; + export default DS.JSONAPISerializer; } declare module 'ember-data/serializers/json' { - import DS from 'ember-data'; - export default DS.JSONSerializer; + import DS from 'ember-data'; + export default DS.JSONSerializer; } declare module 'ember-data/serializers/rest' { - import DS from 'ember-data'; - export default DS.RESTSerializer; + import DS from 'ember-data'; + export default DS.RESTSerializer; } declare module "ember-data/store" { import DS from "ember-data"; diff --git a/types/ember-data/test/model.ts b/types/ember-data/test/model.ts index b3fa04e086..fb076b5b3b 100644 --- a/types/ember-data/test/model.ts +++ b/types/ember-data/test/model.ts @@ -8,7 +8,7 @@ const Person = DS.Model.extend({ title: DS.attr({ defaultValue: "The default" }), title2: DS.attr({ defaultValue: () => "The default" }), - fullName: Ember.computed('firstName', 'lastName', function() { + fullName: Ember.computed('firstName', 'lastName', function () { return `${this.get('firstName')} ${this.get('lastName')}`; }) }); @@ -27,3 +27,6 @@ assertType(user.get('id')); assertType(user.get('username')); assertType(user.get('verified')); assertType(user.get('createdAt')); + +user.serialize(); +user.serialize({ someOption: 'neat' }); diff --git a/types/ember-data/test/store.ts b/types/ember-data/test/store.ts index f7560a231f..d4e14f67da 100644 --- a/types/ember-data/test/store.ts +++ b/types/ember-data/test/store.ts @@ -5,7 +5,7 @@ import { assertType } from "./lib/assert"; declare const store: DS.Store; class Post extends DS.Model { - title = DS.attr('string'); + title = DS.attr('string'); } let post = store.createRecord('post', { @@ -18,7 +18,7 @@ post.save().then((saved) => { assertType(saved); }); -store.findRecord('post', 1).then(function(post) { +store.findRecord('post', 1).then(function (post) { post.get('title'); // => "Rails is Omakase" post.set('title', 'A new post'); post.save(); // => PATCH to '/posts/1' @@ -28,13 +28,13 @@ class User extends DS.Model { username = DS.attr('string'); } -store.queryRecord('user', {}).then(function(user) { +store.queryRecord('user', {}).then(function (user) { let username = user.get('username'); console.log(`Currently logged in as ${username}`); }); store.findAll('blog-post'); // => GET /blog-posts -store.findAll('author', { reload: true }).then(function(authors) { +store.findAll('author', { reload: true }).then(function (authors) { authors.getEach('id'); // ['first', 'second'] }); store.findAll('post', { @@ -52,25 +52,25 @@ if (store.hasRecordForId('post', 1)) { } class Message extends DS.Model { - hasBeenSeen = DS.attr('boolean'); + hasBeenSeen = DS.attr('boolean'); } const messages = store.peekAll('message'); -messages.forEach(function(message) { +messages.forEach(function (message) { message.set('hasBeenSeen', true); }); messages.save(); const people = store.peekAll('person'); people.get('isUpdating'); // false -people.update().then(function() { +people.update().then(function () { people.get('isUpdating'); // false }); people.get('isUpdating'); // true const MyRoute = Ember.Route.extend({ model(params: any): any { - return this.store.findRecord('post', params.post_id, {include: 'comments,comments.author'}); + return this.store.findRecord('post', params.post_id, { include: 'comments,comments.author' }); } }); @@ -79,16 +79,16 @@ const tom = store.query('user', { filter: { email: 'tomster@example.com' } -}).then(function(users) { +}).then(function (users) { return users.get("firstObject"); }); // GET /users?isAdmin=true const admins = store.query('user', { isAdmin: true }); -admins.then(function() { +admins.then(function () { console.log(admins.get("length")); // 42 }); -admins.update().then(function() { +admins.update().then(function () { admins.get('isUpdating'); // false console.log(admins.get("length")); // 123 }); @@ -115,5 +115,8 @@ store.push({ }] }); -assertType(store.adapterFor('person')); -assertType(store.serializerFor('person')); +class UserAdapter extends DS.Adapter { } +class UserSerializer extends DS.Serializer { } + +assertType(store.adapterFor('user')); +assertType(store.serializerFor('user')); diff --git a/types/ember-qunit/index.d.ts b/types/ember-qunit/index.d.ts index 0edc5c837f..1b18c533a8 100644 --- a/types/ember-qunit/index.d.ts +++ b/types/ember-qunit/index.d.ts @@ -15,6 +15,7 @@ declare module 'ember-qunit' { setup?(assert: Assert): void; teardown?(assert: Assert): void; afterTeardown?(assert: Assert): void; + needs?: string[]; } /** @@ -43,7 +44,7 @@ declare module 'ember-qunit' { */ export function setResolver(resolver: Ember.Resolver): void; - export class QUnitAdapter extends Ember.Test.Adapter {} + export class QUnitAdapter extends Ember.Test.Adapter { } export { module, test, skip, only, todo } from 'qunit'; } diff --git a/types/ember/index.d.ts b/types/ember/index.d.ts index 7839a3021c..37fabd1447 100755 --- a/types/ember/index.d.ts +++ b/types/ember/index.d.ts @@ -23,7 +23,9 @@ declare module 'ember' { /** * Deconstructs computed properties into the types which would be returned by `.get()`. */ - type ComputedProperties = { [K in keyof T]: Ember.ComputedProperty | T[K] }; + type ComputedProperties = { + [K in keyof T]: Ember.ComputedProperty | T[K] + }; /** * Check that any arguments to `create()` match the type's properties. @@ -96,7 +98,9 @@ declare module 'ember' { __ember_run_timer_brand__: any; } - type RunMethod = ((this: Target, ...args: any[]) => Ret) | keyof Target; + type RunMethod = + | ((this: Target, ...args: any[]) => Ret) + | keyof Target; type EmberRunQueues = | 'sync' | 'actions' @@ -107,7 +111,13 @@ declare module 'ember' { type ObserverMethod = | (keyof Target) - | ((this: Target, sender: Sender, key: keyof Sender, value: any, rev: number) => void); + | (( + this: Target, + sender: Sender, + key: keyof Sender, + value: any, + rev: number + ) => void); interface RenderOptions { into?: string; @@ -220,7 +230,10 @@ declare module 'ember' { Unless you have specific needs for CoreView, you will use Ember.Component in your applications. **/ - class CoreView extends Ember.Object.extend(Ember.Evented, Ember.ActionHandler) {} + class CoreView extends Ember.Object.extend( + Ember.Evented, + Ember.ActionHandler + ) {} interface ActionSupport { sendAction(action: string, ...params: any[]): void; } @@ -286,7 +299,10 @@ declare module 'ember' { on(...args: string[]): this; } - interface ArrayPrototypeExtensions extends MutableArray, Observable, Copyable {} + interface ArrayPrototypeExtensions + extends MutableArray, + Observable, + Copyable {} /** * Given a fullName return a factory manager. @@ -330,7 +346,11 @@ declare module 'ember' { /** * Register an option for a particular factory. */ - registerOption(fullName: string, optionName: string, options: {}): any; + registerOption( + fullName: string, + optionName: string, + options: {} + ): any; /** * Return a specific registered option for a particular factory. */ @@ -355,7 +375,11 @@ declare module 'ember' { * Define a dependency injection onto a specific factory or all factories * of a type. */ - inject(factoryNameOrType: string, property: string, injectionName: string): any; + inject( + factoryNameOrType: string, + property: string, + injectionName: string + ): any; } const _RegistryProxyMixin: Mixin<_RegistryProxyMixin>; /** @@ -403,7 +427,11 @@ declare module 'ember' { /** defines an injection or typeInjection **/ - inject(factoryNameOrType: string, property: string, injectionName: string): void; + inject( + factoryNameOrType: string, + property: string, + injectionName: string + ): void; /** This injects the test helpers into the window's scope. If a function of the same name has already been defined it will be cached (so that it can be reset @@ -532,14 +560,22 @@ declare module 'ember' { * invalidate any related properties. Pass the starting index of the change * as well as a delta of the amounts to change. */ - arrayContentWillChange(startIdx: number, removeAmt: number, addAmt: number): this; + arrayContentWillChange( + startIdx: number, + removeAmt: number, + addAmt: number + ): this; /** * If you are implementing an object that supports `Ember.Array`, call this * method just after the array content changes to notify any observers and * invalidate any related properties. Pass the starting index of the change * as well as a delta of the amounts to change. */ - arrayContentDidChange(startIdx: number, removeAmt: number, addAmt: number): this; + arrayContentDidChange( + startIdx: number, + removeAmt: number, + addAmt: number + ): this; /** * Returns a special object that can be used to observe individual properties * on the array. Just get an equivalent property on this object and it will @@ -604,7 +640,11 @@ declare module 'ember' { and actions are targeted at the view object. There is no access to the surrounding context or outer controller; all contextual information is passed in. **/ - class Component extends CoreView.extend(ViewMixin, ActionSupport, ClassNamesSupport) { + class Component extends CoreView.extend( + ViewMixin, + ActionSupport, + ClassNamesSupport + ) { // methods readDOMAttr(name: string): string; // properties @@ -804,10 +844,18 @@ declare module 'ember' { **/ toString(): string; - static create(this: EmberClassConstructor): Fix; + static create( + this: EmberClassConstructor + ): Fix; - static create>( - this: EmberClassConstructor>, + static create< + Instance, + Args, + T1 extends EmberInstanceArguments + >( + this: EmberClassConstructor< + Instance & ComputedProperties + >, arg1: T1 & ThisType> ): Fix; @@ -817,7 +865,9 @@ declare module 'ember' { T1 extends EmberInstanceArguments, T2 extends EmberInstanceArguments >( - this: EmberClassConstructor>, + this: EmberClassConstructor< + Instance & ComputedProperties + >, arg1: T1 & ThisType>, arg2: T2 & ThisType> ): Fix; @@ -829,7 +879,9 @@ declare module 'ember' { T2 extends EmberInstanceArguments, T3 extends EmberInstanceArguments >( - this: EmberClassConstructor>, + this: EmberClassConstructor< + Instance & ComputedProperties + >, arg1: T1 & ThisType>, arg2: T2 & ThisType>, arg3: T3 & ThisType> @@ -839,7 +891,12 @@ declare module 'ember' { this: Statics & EmberClassConstructor ): Objectify & EmberClassConstructor; - static extend( + static extend< + Statics, + Instance extends B1, + T1 extends EmberClassArguments, + B1 + >( this: Statics & EmberClassConstructor, arg1: MixinOrLiteral & ThisType> ): Objectify & EmberClassConstructor; @@ -869,9 +926,12 @@ declare module 'ember' { >( this: Statics & EmberClassConstructor, arg1: MixinOrLiteral & ThisType>, - arg2: MixinOrLiteral & ThisType>, - arg3: MixinOrLiteral & ThisType> - ): Objectify & EmberClassConstructor; + arg2: MixinOrLiteral & + ThisType>, + arg3: MixinOrLiteral & + ThisType> + ): Objectify & + EmberClassConstructor; static extend< Statics, @@ -887,16 +947,25 @@ declare module 'ember' { >( this: Statics & EmberClassConstructor, arg1: MixinOrLiteral & ThisType>, - arg2: MixinOrLiteral & ThisType>, - arg3: MixinOrLiteral & ThisType>, - arg4: MixinOrLiteral & ThisType> - ): Objectify & EmberClassConstructor; + arg2: MixinOrLiteral & + ThisType>, + arg3: MixinOrLiteral & + ThisType>, + arg4: MixinOrLiteral & + ThisType> + ): Objectify & + EmberClassConstructor; static reopen( this: Statics & EmberClassConstructor ): Objectify & EmberClassConstructor; - static reopen( + static reopen< + Statics, + Instance extends B1, + T1 extends EmberClassArguments, + B1 + >( this: Statics & EmberClassConstructor, arg1: MixinOrLiteral & ThisType> ): Objectify & EmberClassConstructor; @@ -926,9 +995,12 @@ declare module 'ember' { >( this: Statics & EmberClassConstructor, arg1: MixinOrLiteral & ThisType>, - arg2: MixinOrLiteral & ThisType>, - arg3: MixinOrLiteral & ThisType> - ): Objectify & EmberClassConstructor; + arg2: MixinOrLiteral & + ThisType>, + arg3: MixinOrLiteral & + ThisType> + ): Objectify & + EmberClassConstructor; static reopenClass(this: Statics): Statics; @@ -948,7 +1020,12 @@ declare module 'ember' { T1 extends EmberClassArguments, T2 extends EmberClassArguments, T3 extends EmberClassArguments - >(this: Statics, arg1: T1, arg2: T2, arg3: T3): Statics & T1 & T2 & T3; + >( + this: Statics, + arg1: T1, + arg2: T2, + arg3: T3 + ): Statics & T1 & T2 & T3; static detect( this: Statics & EmberClassConstructor, @@ -998,7 +1075,10 @@ declare module 'ember' { /** * Fetch the model types and observe them for changes. */ - watchModelTypes(typesAdded: Function, typesUpdated: Function): Function; + watchModelTypes( + typesAdded: Function, + typesUpdated: Function + ): Function; /** * Fetch the records of a given type and observe them for changes. */ @@ -1110,7 +1190,10 @@ declare module 'ember' { * item. This method corresponds to the `forEach()` method defined in * JavaScript 1.6. */ - forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; + forEach( + callbackfn: (value: T, index: number, array: T[]) => void, + thisArg?: any + ): void; /** * Alias for `mapBy` */ @@ -1126,7 +1209,10 @@ declare module 'ember' { * Maps all of the items in the enumeration to another value, returning * a new array. This method corresponds to `map()` defined in JavaScript 1.6. */ - map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; + map( + callbackfn: (value: T, index: number, array: T[]) => U, + thisArg?: any + ): U[]; /** * Similar to map, this specialized function returns the value of the named * property on all items in the enumeration. @@ -1141,12 +1227,18 @@ declare module 'ember' { callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any ): S[]; - filter(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; + filter( + callbackfn: (value: T, index: number, array: T[]) => any, + thisArg?: any + ): T[]; /** * Returns an array with all of the items in the enumeration where the passed * function returns false. This method is the inverse of filter(). */ - reject(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; + reject( + callbackfn: (value: T, index: number, array: T[]) => any, + thisArg?: any + ): T[]; /** * Returns an array with just the items with the matched property. You * can pass an optional second argument with the target value. Otherwise @@ -1192,7 +1284,10 @@ declare module 'ember' { * Returns `true` if the passed function returns true for any item in the * enumeration. */ - any(callback: (value: T, index: number, array: T[]) => boolean, target?: {}): boolean; + any( + callback: (value: T, index: number, array: T[]) => boolean, + target?: {} + ): boolean; /** * Returns `true` if the passed property resolves to the value of the second * argument for any item in the enumerable. This method is often simpler/faster @@ -1204,8 +1299,24 @@ declare module 'ember' { * is a useful way to collect a summary value from an enumeration. This * corresponds to the `reduce()` method defined in JavaScript 1.8. */ - reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; - reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; + reduce( + callbackfn: ( + previousValue: T, + currentValue: T, + currentIndex: number, + array: T[] + ) => T, + initialValue?: T + ): T; + reduce( + callbackfn: ( + previousValue: U, + currentValue: T, + currentIndex: number, + array: T[] + ) => U, + initialValue: U + ): U; /** * Invokes the named method on every object in the receiver that * implements it. This method corresponds to the implementation in @@ -1349,7 +1460,9 @@ declare module 'ember' { * The `helper` method create pure-function helpers without instances. For * example: */ - static helper(helper: (params: any[], hash?: object) => any): Helper; + static helper( + helper: (params: any[], hash?: object) => any + ): Helper; /** * Override this function when writing a class-based helper. */ @@ -1366,7 +1479,12 @@ declare module 'ember' { * for Ember. */ const Instrumentation: { - instrument(name: string, payload: any, callback: Function, binding: any): void; + instrument( + name: string, + payload: any, + callback: Function, + binding: any + ): void; reset(): void; subscribe(pattern: string, object: any): void; unsubscribe(subscriber: any): void; @@ -1479,12 +1597,31 @@ declare module 'ember' { class Mixin { /** * Mixin needs to have *something* on its prototype, otherwise it's treated like an empty interface. + * It cannot be private, sadly. */ - private __ember_mixin__: never; + __ember_mixin__: never; static create( args?: T & ThisType> ): Mixin; + + static create( + arg1: T1 & ThisType>, + arg2: T2 & ThisType> + ): Mixin; + + static create( + arg1: T1 & ThisType>, + arg2: T2 & ThisType>, + arg3: T3 & ThisType> + ): Mixin; + + static create( + arg1: T1 & ThisType>, + arg2: T2 & ThisType>, + arg3: T3 & ThisType>, + arg4: T4 & ThisType> + ): Mixin; } /** * This mixin defines the API for modifying array-like objects. These methods @@ -1591,7 +1728,11 @@ declare module 'ember' { * false, this will be applied automatically. Otherwise you can apply the mixin * at anytime by calling `Ember.NativeArray.apply(Array.prototype)`. */ - interface NativeArray extends GlobalArray, MutableArray, Observable, Copyable { + interface NativeArray + extends GlobalArray, + MutableArray, + Observable, + Copyable { /** * __Required.__ You must implement this method to apply this mixin. */ @@ -1615,8 +1756,24 @@ declare module 'ember' { * is a useful way to collect a summary value from an enumeration. This * corresponds to the `reduce()` method defined in JavaScript 1.8. */ - reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; - reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; + reduce( + callbackfn: ( + previousValue: T, + currentValue: T, + currentIndex: number, + array: T[] + ) => T, + initialValue?: T + ): T; + reduce( + callbackfn: ( + previousValue: U, + currentValue: T, + currentIndex: number, + array: T[] + ) => U, + initialValue: U + ): U; } const NativeArray: Mixin>; /** @@ -1649,12 +1806,18 @@ declare module 'ember' { /** * Retrieves the value of a property from the object. */ - get(this: ComputedProperties, key: K): T[K]; + get( + this: ComputedProperties, + key: K + ): T[K]; /** * To get the values of multiple properties at once, call `getProperties` * with a list of strings or an array: */ - getProperties(this: ComputedProperties, list: K[]): Pick; + getProperties( + this: ComputedProperties, + list: K[] + ): Pick; getProperties( this: ComputedProperties, ...list: K[] @@ -1662,7 +1825,11 @@ declare module 'ember' { /** * Sets the provided key or path to the value. */ - set(this: ComputedProperties, key: K, value: T[K]): T[K]; + set( + this: ComputedProperties, + key: K, + value: T[K] + ): T[K]; /** * Sets a list of properties at once. These properties are set inside * a single `beginPropertyChanges` and `endPropertyChanges` batch, so @@ -1723,7 +1890,10 @@ declare module 'ember' { * without accidentally invoking it if it is intended to be * generated lazily. */ - cacheFor(this: ComputedProperties, key: K): T[K] | undefined; + cacheFor( + this: ComputedProperties, + key: K + ): T[K] | undefined; } const Observable: Mixin; /** @@ -1799,7 +1969,7 @@ declare module 'ember' { logic that can only take place after the model has already resolved. */ - afterModel(resolvedModel: any, transition: Transition): Rsvp.Promise; + afterModel(resolvedModel: any, transition: Transition): any; /** This hook is the first of the route entry validation hooks @@ -1833,7 +2003,9 @@ declare module 'ember' { /** * Disconnects a view that has been rendered into an outlet. */ - disconnectOutlet(options: string | { outlet?: string; parentView?: string }): void; + disconnectOutlet( + options: string | { outlet?: string; parentView?: string } + ): void; /** * A hook you can implement to convert the URL into the model for @@ -1920,7 +2092,11 @@ declare module 'ember' { * A hook you can use to reset controller values either when the model * changes or the route is exiting. */ - resetController(controller: Controller, isExiting: boolean, transition: any): void; + resetController( + controller: Controller, + isExiting: boolean, + transition: any + ): void; /** * Sends an action to the router, which will delegate it to the currently active @@ -1939,7 +2115,7 @@ declare module 'ember' { * This method is called when `transitionTo` is called with a context * in order to populate the URL. */ - serialize(model: {}, params: string[]): string; + serialize(model: {}, params: string[]): string | object; /** * A hook you can use to setup the controller for the current route. @@ -2100,10 +2276,10 @@ declare module 'ember' { mount( name: string, options?: { - as?: string, - path?: string, - resetNamespace?: boolean, - engineInfo?: any + as?: string; + path?: string; + resetNamespace?: boolean; + engineInfo?: any; } ): void; } @@ -2219,7 +2395,9 @@ declare module 'ember' { * Used to register callbacks to be fired whenever `App.injectTestHelpers` * is called. */ - function onInjectHelpers(callback: (app: Application) => void): void; + function onInjectHelpers( + callback: (app: Application) => void + ): void; /** * This returns a thenable tailored for testing. It catches failed * `onSuccess` callbacks and invokes the `Ember.Test.adapter.exception` @@ -2237,7 +2415,10 @@ declare module 'ember' { * The only difference is this uses * an instance of `Ember.Test.Promise` */ - function resolve(value?: T | PromiseLike, label?: string): Ember.Test.Promise; + function resolve( + value?: T | PromiseLike, + label?: string + ): Ember.Test.Promise; function resolve(): Ember.Test.Promise; /** * This allows ember-testing to play nicely with other asynchronous @@ -2336,7 +2517,12 @@ declare module 'ember' { } namespace Handlebars { function compile(string: string): Function; - function compile(environment: any, options?: any, context?: any, asObject?: any): any; + function compile( + environment: any, + options?: any, + context?: any, + asObject?: any + ): any; function precompile(string: string, options: any): void; class Compiler {} class JavaScriptCompiler {} @@ -2368,8 +2554,14 @@ declare module 'ember' { } const computed: { (cb: ComputedPropertyCallback): ComputedProperty; - (k1: string, cb: ComputedPropertyCallback): ComputedProperty; - (k1: string, k2: string, cb: ComputedPropertyCallback): ComputedProperty; + (k1: string, cb: ComputedPropertyCallback): ComputedProperty< + T + >; + ( + k1: string, + k2: string, + cb: ComputedPropertyCallback + ): ComputedProperty; ( k1: string, k2: string, @@ -2442,7 +2634,10 @@ declare module 'ember' { * dependent property against a given RegExp, returning `true` * if the value matches the RegExp and `false` if it does not. */ - match(dependentKey: string, regexp: RegExp): ComputedProperty; + match( + dependentKey: string, + regexp: RegExp + ): ComputedProperty; /** * A computed property that returns true if the provided dependent property * is equal to the given value. @@ -2472,12 +2667,12 @@ declare module 'ember' { * A computed property that performs a logical `and` on the * original values for the provided dependent properties. */ - and(...dependentKeys: string[]): ComputedProperty; + and(...dependentKeys: string[]): ComputedProperty; /** * A computed property which performs a logical `or` on the * original values for the provided dependent properties. */ - or(...dependentKeys: string[]): ComputedProperty; + or(...dependentKeys: string[]): ComputedProperty; /** * Creates a new property that is an alias for another property * on an object. Calls to `get` or `set` this property behave as @@ -2547,7 +2742,10 @@ declare module 'ember' { /** * Returns an array mapped to the specified key. */ - mapBy(dependentKey: string, propertyKey: string): ComputedProperty; + mapBy( + dependentKey: string, + propertyKey: string + ): ComputedProperty; /** * Filters the array by the callback. */ @@ -2572,7 +2770,10 @@ declare module 'ember' { * A computed property which returns a new array with all the unique * elements from an array, with uniqueness determined by specific key. */ - uniqBy(dependentKey: string, propertyKey: string): ComputedProperty; + uniqBy( + dependentKey: string, + propertyKey: string + ): ComputedProperty; /** * A computed property which returns a new array with all the unique * elements from one or more dependent arrays. @@ -2588,7 +2789,10 @@ declare module 'ember' { * properties from the first dependent array that are not in the second * dependent array. */ - setDiff(setAProperty: string, setBProperty: string): ComputedProperty; + setDiff( + setAProperty: string, + setBProperty: string + ): ComputedProperty; /** * A computed property that returns the array of values * for the provided dependent properties. @@ -2617,7 +2821,10 @@ declare module 'ember' { * present it will queue itself to run on the existing run-loops action * queue. */ - join(method: (...args: any[]) => Ret, ...args: any[]): Ret | undefined; + join( + method: (...args: any[]) => Ret, + ...args: any[] + ): Ret | undefined; join( target: Target, method: RunMethod, @@ -2669,7 +2876,11 @@ declare module 'ember' { * of milliseconds. */ later(method: (...args: any[]) => any, wait: number): EmberRunTimer; - later(target: Target, method: RunMethod, wait: number): EmberRunTimer; + later( + target: Target, + method: RunMethod, + wait: number + ): EmberRunTimer; later( target: Target, method: RunMethod, @@ -2725,7 +2936,11 @@ declare module 'ember' { * Schedule a function to run one time during the current RunLoop. This is equivalent * to calling `scheduleOnce` with the "actions" queue. */ - once(target: Target, method: RunMethod, ...args: any[]): EmberRunTimer; + once( + target: Target, + method: RunMethod, + ...args: any[] + ): EmberRunTimer; /** * Schedules a function to run one time in a given queue of the current RunLoop. * Calling this method with the same queue/target/method combination will have @@ -2742,7 +2957,11 @@ declare module 'ember' { * control has been returned to the system. This is equivalent to calling * `run.later` with a wait time of 1ms. */ - next(target: Target, method: RunMethod, ...args: any[]): EmberRunTimer; + next( + target: Target, + method: RunMethod, + ...args: any[] + ): EmberRunTimer; /** * Cancels a scheduled item. Must be a value returned by `run.later()`, * `run.once()`, `run.scheduleOnce()`, `run.next()`, `run.debounce()`, or @@ -2966,12 +3185,20 @@ declare module 'ember' { /** * Display a warning with the provided message. */ - function warn(message: string, test: boolean, options: { id: string }): any; + function warn( + message: string, + test: boolean, + options: { id: string } + ): any; function warn(message: string, options: { id: string }): any; /** * @deprecated Missing deprecation options: https://emberjs.com/deprecations/v2.x/#toc_ember-debug-function-options */ - function warn(message: string, test: boolean, options?: { id?: string }): any; + function warn( + message: string, + test: boolean, + options?: { id?: string } + ): any; /** * @deprecated Missing deprecation options: https://emberjs.com/deprecations/v2.x/#toc_ember-debug-function-options */ @@ -3017,12 +3244,20 @@ declare module 'ember' { * a target is executed on the passed object. If an array of actions * is not passed, the actions stored on the passed object are invoked. */ - function sendEvent(obj: any, eventName: string, params?: any[], actions?: any[]): boolean; + function sendEvent( + obj: any, + eventName: string, + params?: any[], + actions?: any[] + ): boolean; /** * Define a property as a function that should be executed when * a specified event or events are triggered. */ - function on(eventNames: string, func: (...args: any[]) => void): (...args: any[]) => void; + function on( + eventNames: string, + func: (...args: any[]) => void + ): (...args: any[]) => void; /** * To get multiple properties at once, call `Ember.getProperties` * with an object followed by a list of strings or an array: @@ -3066,7 +3301,10 @@ declare module 'ember' { /** * Specify a method that observes property changes. */ - function observer(key1: string, func: (target: any, key: string) => void): void; + function observer( + key1: string, + func: (target: any, key: string) => void + ): void; function observer( key1: string, key2: string, @@ -3118,7 +3356,10 @@ declare module 'ember' { * the function will be invoked. If the property is not defined but the * object implements the `unknownProperty` method then that will be invoked. */ - function get(obj: ComputedProperties, key: K): T[K]; + function get( + obj: ComputedProperties, + key: K + ): T[K]; /** * Retrieves the value of a property from an Object, or a default value in the * case that the property returns `undefined`. @@ -3199,7 +3440,12 @@ declare module 'ember' { */ function assign(target: T, source: U): T & U; function assign(target: T, source1: U, source2: V): T & U & V; - function assign(target: T, source1: U, source2: V, source3: W): T & U & V & W; + function assign( + target: T, + source1: U, + source2: V, + source3: W + ): T & U & V & W; /** * Polyfill for Object.create * @deprecated Use Object.create @@ -3281,7 +3527,10 @@ declare module 'ember' { /** * Expands `pattern`, invoking `callback` for each expansion. */ - function expandProperties(pattern: string, callback: (expanded: string) => void): void; + function expandProperties( + pattern: string, + callback: (expanded: string) => void + ): void; } export default Ember; diff --git a/types/ember/test/computed.ts b/types/ember/test/computed.ts index b9bfe2ada6..7376d14639 100755 --- a/types/ember/test/computed.ts +++ b/types/ember/test/computed.ts @@ -27,13 +27,13 @@ const Person = Ember.Object.extend({ this.set('firstName', first); this.set('lastName', last); return value; - } + }, }), fullNameGetOnly: Ember.computed('fullName', { get() { return this.get('fullName'); - } + }, }), fullNameSetOnly: Ember.computed('firstName', 'lastName', { @@ -42,15 +42,16 @@ const Person = Ember.Object.extend({ this.set('firstName', first); this.set('lastName', last); return value; - } + }, }), combinators: Ember.computed(function() { return this.get('firstName'); - }).property('firstName') - .meta({ foo: 'bar' }) - .volatile() - .readOnly() + }) + .property('firstName') + .meta({ foo: 'bar' }) + .volatile() + .readOnly(), }); const person = Person.create({ @@ -79,10 +80,12 @@ assertType(person.get('fullNameGetOnly')); assertType(person.get('fullNameSetOnly')); assertType(person.get('combinators')); -assertType<{ firstName: string, fullName: string, age: number }>(person.getProperties('firstName', 'fullName', 'age')); +assertType<{ firstName: string; fullName: string; age: number }>( + person.getProperties('firstName', 'fullName', 'age') +); const person2 = Person.create({ - fullName: 'Fred Smith' + fullName: 'Fred Smith', }); assertType(person2.get('firstName')); @@ -90,7 +93,7 @@ assertType(person2.get('fullName')); const person3 = Person.extend({ firstName: 'Fred', - fullName: 'Fred Smith' + fullName: 'Fred Smith', }).create(); assertType(person3.get('firstName')); @@ -98,7 +101,7 @@ assertType(person3.get('fullName')); const person4 = Person.extend({ firstName: Ember.computed(() => 'Fred'), - fullName: Ember.computed(() => 'Fred Smith') + fullName: Ember.computed(() => 'Fred Smith'), }).create(); assertType(person4.get('firstName')); @@ -112,13 +115,13 @@ const objectWithComputedProperties = Ember.Object.extend({ collect: Ember.computed.collect('foo', 'bar', 'baz', 'qux'), deprecatingAlias: Ember.computed.deprecatingAlias('foo', { id: 'hamster.deprecate-banana', - until: '3.0.0' + until: '3.0.0', }), empty: Ember.computed.empty('foo'), equalNumber: Ember.computed.equal('foo', 1), equalString: Ember.computed.equal('foo', 'bar'), equalObject: Ember.computed.equal('foo', {}), - filter: Ember.computed.filter('foo', (item) => item === 'bar'), + filter: Ember.computed.filter('foo', item => item === 'bar'), filterBy1: Ember.computed.filterBy('foo', 'bar'), filterBy2: Ember.computed.filterBy('foo', 'bar', false), gt: Ember.computed.gt('foo', 3), @@ -152,9 +155,11 @@ const objectWithComputedProperties = Ember.Object.extend({ sum: Ember.computed.sum('foo'), union: Ember.computed.union('foo', 'bar', 'baz', 'qux'), uniq: Ember.computed.uniq('foo'), - uniqBy: Ember.computed.uniqBy('foo', 'bar') + uniqBy: Ember.computed.uniqBy('foo', 'bar'), }); const component2 = Component.extend({ - isAnimal: or('isDog', 'isCat') -}); + isAnimal: or('isDog', 'isCat'), +}).create(); + +assertType(component2.get('isAnimal')); From 93bf0e8fc2beeb3f537b31026fbcbb554dcb4e76 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 19 Dec 2017 16:18:58 -0700 Subject: [PATCH 2/5] One more tweak for ember-data; fix parens. --- types/ember-data/index.d.ts | 2 +- types/ember-data/test/model.ts | 2 +- types/ember-data/test/store.ts | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/types/ember-data/index.d.ts b/types/ember-data/index.d.ts index 36bda4889c..c973ebd2ea 100644 --- a/types/ember-data/index.d.ts +++ b/types/ember-data/index.d.ts @@ -424,7 +424,7 @@ declare module "ember-data" { * Create a JSON representation of the record, using the serialization * strategy of the store's adapter. */ - serialize(options?: {}): {}; + serialize(options?: { includeId?: boolean }): {}; /** * Use [DS.JSONSerializer](DS.JSONSerializer.html) to * get the JSON representation of a record. diff --git a/types/ember-data/test/model.ts b/types/ember-data/test/model.ts index fb076b5b3b..1e96d105ed 100644 --- a/types/ember-data/test/model.ts +++ b/types/ember-data/test/model.ts @@ -8,7 +8,7 @@ const Person = DS.Model.extend({ title: DS.attr({ defaultValue: "The default" }), title2: DS.attr({ defaultValue: () => "The default" }), - fullName: Ember.computed('firstName', 'lastName', function () { + fullName: Ember.computed('firstName', 'lastName', function() { return `${this.get('firstName')} ${this.get('lastName')}`; }) }); diff --git a/types/ember-data/test/store.ts b/types/ember-data/test/store.ts index d4e14f67da..d3a564cbf8 100644 --- a/types/ember-data/test/store.ts +++ b/types/ember-data/test/store.ts @@ -18,7 +18,7 @@ post.save().then((saved) => { assertType(saved); }); -store.findRecord('post', 1).then(function (post) { +store.findRecord('post', 1).then(function(post) { post.get('title'); // => "Rails is Omakase" post.set('title', 'A new post'); post.save(); // => PATCH to '/posts/1' @@ -28,13 +28,13 @@ class User extends DS.Model { username = DS.attr('string'); } -store.queryRecord('user', {}).then(function (user) { +store.queryRecord('user', {}).then(function(user) { let username = user.get('username'); console.log(`Currently logged in as ${username}`); }); store.findAll('blog-post'); // => GET /blog-posts -store.findAll('author', { reload: true }).then(function (authors) { +store.findAll('author', { reload: true }).then(function(authors) { authors.getEach('id'); // ['first', 'second'] }); store.findAll('post', { @@ -56,14 +56,14 @@ class Message extends DS.Model { } const messages = store.peekAll('message'); -messages.forEach(function (message) { +messages.forEach(function(message) { message.set('hasBeenSeen', true); }); messages.save(); const people = store.peekAll('person'); people.get('isUpdating'); // false -people.update().then(function () { +people.update().then(function() { people.get('isUpdating'); // false }); people.get('isUpdating'); // true @@ -79,16 +79,16 @@ const tom = store.query('user', { filter: { email: 'tomster@example.com' } -}).then(function (users) { +}).then(function(users) { return users.get("firstObject"); }); // GET /users?isAdmin=true const admins = store.query('user', { isAdmin: true }); -admins.then(function () { +admins.then(function() { console.log(admins.get("length")); // 42 }); -admins.update().then(function () { +admins.update().then(function() { admins.get('isUpdating'); // false console.log(admins.get("length")); // 123 }); From ff7058dcc617182fdfe874920c156a3a8bc70842 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 19 Dec 2017 16:24:18 -0700 Subject: [PATCH 3/5] Fix a test for last added Ember Data fix. --- types/ember-data/test/model.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/ember-data/test/model.ts b/types/ember-data/test/model.ts index 1e96d105ed..70dba1bd7c 100644 --- a/types/ember-data/test/model.ts +++ b/types/ember-data/test/model.ts @@ -29,4 +29,5 @@ assertType(user.get('verified')); assertType(user.get('createdAt')); user.serialize(); -user.serialize({ someOption: 'neat' }); +user.serialize({ includeId: true }); + From f44b484a52200a8e58c05a9247371707fe4da53f Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 19 Dec 2017 16:32:10 -0700 Subject: [PATCH 4/5] Fix white space in Ember Data. --- types/ember-data/test/model.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/types/ember-data/test/model.ts b/types/ember-data/test/model.ts index 70dba1bd7c..a18167dbee 100644 --- a/types/ember-data/test/model.ts +++ b/types/ember-data/test/model.ts @@ -30,4 +30,3 @@ assertType(user.get('createdAt')); user.serialize(); user.serialize({ includeId: true }); - From 99b908fdb88def87f9e292c7953360c92a09b373 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Thu, 28 Dec 2017 15:17:25 -0700 Subject: [PATCH 5/5] Revert Prettier-induced spacing, comma changes. --- types/ember-data/index.d.ts | 116 +++++----- types/ember-data/test/store.ts | 6 +- types/ember-qunit/index.d.ts | 2 +- types/ember/index.d.ts | 377 +++++++-------------------------- types/ember/test/computed.ts | 33 ++- 5 files changed, 150 insertions(+), 384 deletions(-) diff --git a/types/ember-data/index.d.ts b/types/ember-data/index.d.ts index c973ebd2ea..8043ad894e 100644 --- a/types/ember-data/index.d.ts +++ b/types/ember-data/index.d.ts @@ -208,7 +208,7 @@ declare module "ember-data" { * subclasses are used to indicate specific error states. The following * subclasses are provided: */ - class AdapterError { } + class AdapterError {} /** * A `DS.InvalidError` is used by an adapter to signal the external API * was unable to process a request because the content was not @@ -218,27 +218,27 @@ declare module "ember-data" { * transition to the `invalid` state and the errors will be set to the * `errors` property on the record. */ - class InvalidError { } + class InvalidError {} /** * A `DS.TimeoutError` is used by an adapter to signal that a request * to the external API has timed out. I.e. no response was received from * the external API within an allowed time period. */ - class TimeoutError { } + class TimeoutError {} /** * A `DS.AbortError` is used by an adapter to signal that a request to * the external API was aborted. For example, this can occur if the user * navigates away from the current page after a request to the external API * has been initiated but before a response has been received. */ - class AbortError { } + class AbortError {} /** * A `DS.UnauthorizedError` equates to a HTTP `401 Unauthorized` response * status. It is used by an adapter to signal that a request to the external * API was rejected because authorization is required and has failed or has not * yet been provided. */ - class UnauthorizedError { } + class UnauthorizedError {} /** * A `DS.ForbiddenError` equates to a HTTP `403 Forbidden` response status. * It is used by an adapter to signal that a request to the external API was @@ -246,13 +246,13 @@ declare module "ember-data" { * provided and is valid, then the authenticated user does not have the * necessary permissions for the request. */ - class ForbiddenError { } + class ForbiddenError {} /** * A `DS.NotFoundError` equates to a HTTP `404 Not Found` response status. * It is used by an adapter to signal that a request to the external API * was rejected because the resource could not be found on the API. */ - class NotFoundError { } + class NotFoundError {} /** * A `DS.ConflictError` equates to a HTTP `409 Conflict` response status. * It is used by an adapter to indicate that the request could not be processed @@ -260,17 +260,17 @@ declare module "ember-data" { * creating a record with a client generated id but that id is already known * to the external API. */ - class ConflictError { } + class ConflictError {} /** * A `DS.ServerError` equates to a HTTP `500 Internal Server Error` response * status. It is used by the adapter to indicate that a request has failed * because of an error in the external API. */ - class ServerError { } + class ServerError {} /** * Holds validation errors for a given record, organized by attribute names. */ - interface Errors extends Ember.Enumerable, Ember.Evented { } + interface Errors extends Ember.Enumerable, Ember.Evented {} class Errors extends Ember.Object { /** * DEPRECATED: @@ -544,7 +544,7 @@ declare module "ember-data" { */ static relatedTypes: Ember.ComputedProperty< Ember.NativeArray - >; + >; /** * A map whose keys are the relationships of a model and whose values are * relationship descriptors. @@ -613,14 +613,14 @@ declare module "ember-data" { /** * ### State */ - class RootState { } + class RootState {} /** * Represents an ordered list of records whose order and membership is * determined by the adapter. For example, a query sent to the adapter * may trigger a search on the server, whose results would be loaded * into an instance of the `AdapterPopulatedRecordArray`. */ - class AdapterPopulatedRecordArray extends RecordArray { } + class AdapterPopulatedRecordArray extends RecordArray {} /** * Represents a list of records whose membership is determined by the * store. As records are created, loaded, or modified, the store @@ -641,7 +641,7 @@ declare module "ember-data" { * `DS.RecordArray` or its subclasses will be returned by your application's store * in response to queries. */ - interface RecordArray extends Ember.ArrayProxy, Ember.Evented { } + interface RecordArray extends Ember.ArrayProxy, Ember.Evented {} class RecordArray { /** * The flag to signal a `RecordArray` is finished loading data. @@ -814,7 +814,7 @@ declare module "ember-data" { * A `ManyArray` is a `MutableArray` that represents the contents of a has-many * relationship. */ - interface ManyArray extends Ember.MutableArray { } + interface ManyArray extends Ember.MutableArray {} class ManyArray extends Ember.Object.extend( Ember.MutableArray as {}, Ember.Evented @@ -852,8 +852,8 @@ declare module "ember-data" { */ interface PromiseArray extends Ember.ArrayProxy, - Ember.PromiseProxyMixin> { } - class PromiseArray { } + Ember.PromiseProxyMixin> {} + class PromiseArray {} /** * A `PromiseObject` is an object that acts like both an `Ember.Object` * and a promise. When the promise is resolved, then the resulting value @@ -863,8 +863,8 @@ declare module "ember-data" { */ interface PromiseObject extends Ember.ObjectProxy, - Ember.PromiseProxyMixin> { } - class PromiseObject { } + Ember.PromiseProxyMixin> {} + class PromiseObject {} /** * A PromiseManyArray is a PromiseArray that also proxies certain method calls * to the underlying manyArray. @@ -1817,7 +1817,7 @@ declare module "ember-data" { * used when `boolean` is passed as the type parameter to the * [DS.attr](../../data#method_attr) function. */ - class BooleanTransform extends Transform { } + class BooleanTransform extends Transform {} /** * The `DS.DateTransform` class is used to serialize and deserialize * date attributes on Ember Data record objects. This transform is used @@ -1825,21 +1825,21 @@ declare module "ember-data" { * [DS.attr](../../data#method_attr) function. It uses the [`ISO 8601`](https://en.wikipedia.org/wiki/ISO_8601) * standard. */ - class DateTransform extends Transform { } + class DateTransform extends Transform {} /** * The `DS.NumberTransform` class is used to serialize and deserialize * numeric attributes on Ember Data record objects. This transform is * used when `number` is passed as the type parameter to the * [DS.attr](../../data#method_attr) function. */ - class NumberTransform extends Transform { } + class NumberTransform extends Transform {} /** * The `DS.StringTransform` class is used to serialize and deserialize * string attributes on Ember Data record objects. This transform is * used when `string` is passed as the type parameter to the * [DS.attr](../../data#method_attr) function. */ - class StringTransform extends Transform { } + class StringTransform extends Transform {} /** * The `DS.Transform` class is used to serialize and deserialize model * attributes when they are saved or loaded from an @@ -2069,63 +2069,63 @@ declare module "ember" { } } declare module 'ember-data/adapter' { - import DS from 'ember-data'; - export default DS.Adapter; + import DS from 'ember-data'; + export default DS.Adapter; } declare module 'ember-data/adapters/errors' { - import DS from 'ember-data'; - const AdapterError: typeof DS.AdapterError; - const InvalidError: typeof DS.InvalidError; - const UnauthorizedError: typeof DS.UnauthorizedError; - const ForbiddenError: typeof DS.ForbiddenError; - const NotFoundError: typeof DS.NotFoundError; - const ConflictError: typeof DS.ConflictError; - const ServerError: typeof DS.ServerError; - const TimeoutError: typeof DS.TimeoutError; - const AbortError: typeof DS.AbortError; - const errorsHashToArray: typeof DS.errorsHashToArray; - const errorsArrayToHash: typeof DS.errorsArrayToHash; + import DS from 'ember-data'; + const AdapterError: typeof DS.AdapterError; + const InvalidError: typeof DS.InvalidError; + const UnauthorizedError: typeof DS.UnauthorizedError; + const ForbiddenError: typeof DS.ForbiddenError; + const NotFoundError: typeof DS.NotFoundError; + const ConflictError: typeof DS.ConflictError; + const ServerError: typeof DS.ServerError; + const TimeoutError: typeof DS.TimeoutError; + const AbortError: typeof DS.AbortError; + const errorsHashToArray: typeof DS.errorsHashToArray; + const errorsArrayToHash: typeof DS.errorsArrayToHash; } declare module 'ember-data/adapters/json-api' { - import DS from 'ember-data'; - export default DS.JSONAPIAdapter; + import DS from 'ember-data'; + export default DS.JSONAPIAdapter; } declare module 'ember-data/adapters/rest' { - import DS from 'ember-data'; - export default DS.RESTAdapter; + import DS from 'ember-data'; + export default DS.RESTAdapter; } declare module 'ember-data/attr' { - import DS from 'ember-data'; - export default DS.attr; + import DS from 'ember-data'; + export default DS.attr; } declare module 'ember-data/model' { - import DS from 'ember-data'; - export default DS.Model; + import DS from 'ember-data'; + export default DS.Model; } declare module 'ember-data/relationships' { - import DS from 'ember-data'; - const hasMany: typeof DS.hasMany; - const belongsTo: typeof DS.belongsTo; + import DS from 'ember-data'; + const hasMany: typeof DS.hasMany; + const belongsTo: typeof DS.belongsTo; } declare module 'ember-data/serializer' { - import DS from 'ember-data'; - export default DS.Serializer; + import DS from 'ember-data'; + export default DS.Serializer; } declare module 'ember-data/serializers/embedded-records-mixin' { - import DS from 'ember-data'; - export default DS.EmbeddedRecordsMixin; + import DS from 'ember-data'; + export default DS.EmbeddedRecordsMixin; } declare module 'ember-data/serializers/json-api' { - import DS from 'ember-data'; - export default DS.JSONAPISerializer; + import DS from 'ember-data'; + export default DS.JSONAPISerializer; } declare module 'ember-data/serializers/json' { - import DS from 'ember-data'; - export default DS.JSONSerializer; + import DS from 'ember-data'; + export default DS.JSONSerializer; } declare module 'ember-data/serializers/rest' { - import DS from 'ember-data'; - export default DS.RESTSerializer; + import DS from 'ember-data'; + export default DS.RESTSerializer; } declare module "ember-data/store" { import DS from "ember-data"; diff --git a/types/ember-data/test/store.ts b/types/ember-data/test/store.ts index d3a564cbf8..46b0987981 100644 --- a/types/ember-data/test/store.ts +++ b/types/ember-data/test/store.ts @@ -5,7 +5,7 @@ import { assertType } from "./lib/assert"; declare const store: DS.Store; class Post extends DS.Model { - title = DS.attr('string'); + title = DS.attr('string'); } let post = store.createRecord('post', { @@ -52,7 +52,7 @@ if (store.hasRecordForId('post', 1)) { } class Message extends DS.Model { - hasBeenSeen = DS.attr('boolean'); + hasBeenSeen = DS.attr('boolean'); } const messages = store.peekAll('message'); @@ -70,7 +70,7 @@ people.get('isUpdating'); // true const MyRoute = Ember.Route.extend({ model(params: any): any { - return this.store.findRecord('post', params.post_id, { include: 'comments,comments.author' }); + return this.store.findRecord('post', params.post_id, {include: 'comments,comments.author'}); } }); diff --git a/types/ember-qunit/index.d.ts b/types/ember-qunit/index.d.ts index 1b18c533a8..b6b6038758 100644 --- a/types/ember-qunit/index.d.ts +++ b/types/ember-qunit/index.d.ts @@ -44,7 +44,7 @@ declare module 'ember-qunit' { */ export function setResolver(resolver: Ember.Resolver): void; - export class QUnitAdapter extends Ember.Test.Adapter { } + export class QUnitAdapter extends Ember.Test.Adapter {} export { module, test, skip, only, todo } from 'qunit'; } diff --git a/types/ember/index.d.ts b/types/ember/index.d.ts index 37fabd1447..7039669b39 100755 --- a/types/ember/index.d.ts +++ b/types/ember/index.d.ts @@ -23,9 +23,7 @@ declare module 'ember' { /** * Deconstructs computed properties into the types which would be returned by `.get()`. */ - type ComputedProperties = { - [K in keyof T]: Ember.ComputedProperty | T[K] - }; + type ComputedProperties = { [K in keyof T]: Ember.ComputedProperty | T[K] }; /** * Check that any arguments to `create()` match the type's properties. @@ -98,9 +96,7 @@ declare module 'ember' { __ember_run_timer_brand__: any; } - type RunMethod = - | ((this: Target, ...args: any[]) => Ret) - | keyof Target; + type RunMethod = ((this: Target, ...args: any[]) => Ret) | keyof Target; type EmberRunQueues = | 'sync' | 'actions' @@ -111,13 +107,7 @@ declare module 'ember' { type ObserverMethod = | (keyof Target) - | (( - this: Target, - sender: Sender, - key: keyof Sender, - value: any, - rev: number - ) => void); + | ((this: Target, sender: Sender, key: keyof Sender, value: any, rev: number) => void); interface RenderOptions { into?: string; @@ -230,10 +220,7 @@ declare module 'ember' { Unless you have specific needs for CoreView, you will use Ember.Component in your applications. **/ - class CoreView extends Ember.Object.extend( - Ember.Evented, - Ember.ActionHandler - ) {} + class CoreView extends Ember.Object.extend(Ember.Evented, Ember.ActionHandler) {} interface ActionSupport { sendAction(action: string, ...params: any[]): void; } @@ -299,10 +286,7 @@ declare module 'ember' { on(...args: string[]): this; } - interface ArrayPrototypeExtensions - extends MutableArray, - Observable, - Copyable {} + interface ArrayPrototypeExtensions extends MutableArray, Observable, Copyable {} /** * Given a fullName return a factory manager. @@ -346,11 +330,7 @@ declare module 'ember' { /** * Register an option for a particular factory. */ - registerOption( - fullName: string, - optionName: string, - options: {} - ): any; + registerOption(fullName: string, optionName: string, options: {}): any; /** * Return a specific registered option for a particular factory. */ @@ -375,11 +355,7 @@ declare module 'ember' { * Define a dependency injection onto a specific factory or all factories * of a type. */ - inject( - factoryNameOrType: string, - property: string, - injectionName: string - ): any; + inject(factoryNameOrType: string, property: string, injectionName: string): any; } const _RegistryProxyMixin: Mixin<_RegistryProxyMixin>; /** @@ -427,11 +403,7 @@ declare module 'ember' { /** defines an injection or typeInjection **/ - inject( - factoryNameOrType: string, - property: string, - injectionName: string - ): void; + inject(factoryNameOrType: string, property: string, injectionName: string): void; /** This injects the test helpers into the window's scope. If a function of the same name has already been defined it will be cached (so that it can be reset @@ -560,22 +532,14 @@ declare module 'ember' { * invalidate any related properties. Pass the starting index of the change * as well as a delta of the amounts to change. */ - arrayContentWillChange( - startIdx: number, - removeAmt: number, - addAmt: number - ): this; + arrayContentWillChange(startIdx: number, removeAmt: number, addAmt: number): this; /** * If you are implementing an object that supports `Ember.Array`, call this * method just after the array content changes to notify any observers and * invalidate any related properties. Pass the starting index of the change * as well as a delta of the amounts to change. */ - arrayContentDidChange( - startIdx: number, - removeAmt: number, - addAmt: number - ): this; + arrayContentDidChange(startIdx: number, removeAmt: number, addAmt: number): this; /** * Returns a special object that can be used to observe individual properties * on the array. Just get an equivalent property on this object and it will @@ -640,11 +604,7 @@ declare module 'ember' { and actions are targeted at the view object. There is no access to the surrounding context or outer controller; all contextual information is passed in. **/ - class Component extends CoreView.extend( - ViewMixin, - ActionSupport, - ClassNamesSupport - ) { + class Component extends CoreView.extend(ViewMixin, ActionSupport, ClassNamesSupport) { // methods readDOMAttr(name: string): string; // properties @@ -844,18 +804,10 @@ declare module 'ember' { **/ toString(): string; - static create( - this: EmberClassConstructor - ): Fix; + static create(this: EmberClassConstructor): Fix; - static create< - Instance, - Args, - T1 extends EmberInstanceArguments - >( - this: EmberClassConstructor< - Instance & ComputedProperties - >, + static create>( + this: EmberClassConstructor>, arg1: T1 & ThisType> ): Fix; @@ -865,9 +817,7 @@ declare module 'ember' { T1 extends EmberInstanceArguments, T2 extends EmberInstanceArguments >( - this: EmberClassConstructor< - Instance & ComputedProperties - >, + this: EmberClassConstructor>, arg1: T1 & ThisType>, arg2: T2 & ThisType> ): Fix; @@ -879,9 +829,7 @@ declare module 'ember' { T2 extends EmberInstanceArguments, T3 extends EmberInstanceArguments >( - this: EmberClassConstructor< - Instance & ComputedProperties - >, + this: EmberClassConstructor>, arg1: T1 & ThisType>, arg2: T2 & ThisType>, arg3: T3 & ThisType> @@ -891,12 +839,7 @@ declare module 'ember' { this: Statics & EmberClassConstructor ): Objectify & EmberClassConstructor; - static extend< - Statics, - Instance extends B1, - T1 extends EmberClassArguments, - B1 - >( + static extend( this: Statics & EmberClassConstructor, arg1: MixinOrLiteral & ThisType> ): Objectify & EmberClassConstructor; @@ -926,12 +869,9 @@ declare module 'ember' { >( this: Statics & EmberClassConstructor, arg1: MixinOrLiteral & ThisType>, - arg2: MixinOrLiteral & - ThisType>, - arg3: MixinOrLiteral & - ThisType> - ): Objectify & - EmberClassConstructor; + arg2: MixinOrLiteral & ThisType>, + arg3: MixinOrLiteral & ThisType> + ): Objectify & EmberClassConstructor; static extend< Statics, @@ -947,25 +887,16 @@ declare module 'ember' { >( this: Statics & EmberClassConstructor, arg1: MixinOrLiteral & ThisType>, - arg2: MixinOrLiteral & - ThisType>, - arg3: MixinOrLiteral & - ThisType>, - arg4: MixinOrLiteral & - ThisType> - ): Objectify & - EmberClassConstructor; + arg2: MixinOrLiteral & ThisType>, + arg3: MixinOrLiteral & ThisType>, + arg4: MixinOrLiteral & ThisType> + ): Objectify & EmberClassConstructor; static reopen( this: Statics & EmberClassConstructor ): Objectify & EmberClassConstructor; - static reopen< - Statics, - Instance extends B1, - T1 extends EmberClassArguments, - B1 - >( + static reopen( this: Statics & EmberClassConstructor, arg1: MixinOrLiteral & ThisType> ): Objectify & EmberClassConstructor; @@ -995,12 +926,9 @@ declare module 'ember' { >( this: Statics & EmberClassConstructor, arg1: MixinOrLiteral & ThisType>, - arg2: MixinOrLiteral & - ThisType>, - arg3: MixinOrLiteral & - ThisType> - ): Objectify & - EmberClassConstructor; + arg2: MixinOrLiteral & ThisType>, + arg3: MixinOrLiteral & ThisType> + ): Objectify & EmberClassConstructor; static reopenClass(this: Statics): Statics; @@ -1020,12 +948,7 @@ declare module 'ember' { T1 extends EmberClassArguments, T2 extends EmberClassArguments, T3 extends EmberClassArguments - >( - this: Statics, - arg1: T1, - arg2: T2, - arg3: T3 - ): Statics & T1 & T2 & T3; + >(this: Statics, arg1: T1, arg2: T2, arg3: T3): Statics & T1 & T2 & T3; static detect( this: Statics & EmberClassConstructor, @@ -1075,10 +998,7 @@ declare module 'ember' { /** * Fetch the model types and observe them for changes. */ - watchModelTypes( - typesAdded: Function, - typesUpdated: Function - ): Function; + watchModelTypes(typesAdded: Function, typesUpdated: Function): Function; /** * Fetch the records of a given type and observe them for changes. */ @@ -1190,10 +1110,7 @@ declare module 'ember' { * item. This method corresponds to the `forEach()` method defined in * JavaScript 1.6. */ - forEach( - callbackfn: (value: T, index: number, array: T[]) => void, - thisArg?: any - ): void; + forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; /** * Alias for `mapBy` */ @@ -1209,10 +1126,7 @@ declare module 'ember' { * Maps all of the items in the enumeration to another value, returning * a new array. This method corresponds to `map()` defined in JavaScript 1.6. */ - map( - callbackfn: (value: T, index: number, array: T[]) => U, - thisArg?: any - ): U[]; + map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; /** * Similar to map, this specialized function returns the value of the named * property on all items in the enumeration. @@ -1227,18 +1141,12 @@ declare module 'ember' { callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any ): S[]; - filter( - callbackfn: (value: T, index: number, array: T[]) => any, - thisArg?: any - ): T[]; + filter(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; /** * Returns an array with all of the items in the enumeration where the passed * function returns false. This method is the inverse of filter(). */ - reject( - callbackfn: (value: T, index: number, array: T[]) => any, - thisArg?: any - ): T[]; + reject(callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; /** * Returns an array with just the items with the matched property. You * can pass an optional second argument with the target value. Otherwise @@ -1284,10 +1192,7 @@ declare module 'ember' { * Returns `true` if the passed function returns true for any item in the * enumeration. */ - any( - callback: (value: T, index: number, array: T[]) => boolean, - target?: {} - ): boolean; + any(callback: (value: T, index: number, array: T[]) => boolean, target?: {}): boolean; /** * Returns `true` if the passed property resolves to the value of the second * argument for any item in the enumerable. This method is often simpler/faster @@ -1299,24 +1204,8 @@ declare module 'ember' { * is a useful way to collect a summary value from an enumeration. This * corresponds to the `reduce()` method defined in JavaScript 1.8. */ - reduce( - callbackfn: ( - previousValue: T, - currentValue: T, - currentIndex: number, - array: T[] - ) => T, - initialValue?: T - ): T; - reduce( - callbackfn: ( - previousValue: U, - currentValue: T, - currentIndex: number, - array: T[] - ) => U, - initialValue: U - ): U; + reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; + reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; /** * Invokes the named method on every object in the receiver that * implements it. This method corresponds to the implementation in @@ -1460,9 +1349,7 @@ declare module 'ember' { * The `helper` method create pure-function helpers without instances. For * example: */ - static helper( - helper: (params: any[], hash?: object) => any - ): Helper; + static helper(helper: (params: any[], hash?: object) => any): Helper; /** * Override this function when writing a class-based helper. */ @@ -1479,12 +1366,7 @@ declare module 'ember' { * for Ember. */ const Instrumentation: { - instrument( - name: string, - payload: any, - callback: Function, - binding: any - ): void; + instrument(name: string, payload: any, callback: Function, binding: any): void; reset(): void; subscribe(pattern: string, object: any): void; unsubscribe(subscriber: any): void; @@ -1728,11 +1610,7 @@ declare module 'ember' { * false, this will be applied automatically. Otherwise you can apply the mixin * at anytime by calling `Ember.NativeArray.apply(Array.prototype)`. */ - interface NativeArray - extends GlobalArray, - MutableArray, - Observable, - Copyable { + interface NativeArray extends GlobalArray, MutableArray, Observable, Copyable { /** * __Required.__ You must implement this method to apply this mixin. */ @@ -1756,24 +1634,8 @@ declare module 'ember' { * is a useful way to collect a summary value from an enumeration. This * corresponds to the `reduce()` method defined in JavaScript 1.8. */ - reduce( - callbackfn: ( - previousValue: T, - currentValue: T, - currentIndex: number, - array: T[] - ) => T, - initialValue?: T - ): T; - reduce( - callbackfn: ( - previousValue: U, - currentValue: T, - currentIndex: number, - array: T[] - ) => U, - initialValue: U - ): U; + reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T; + reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; } const NativeArray: Mixin>; /** @@ -1806,18 +1668,12 @@ declare module 'ember' { /** * Retrieves the value of a property from the object. */ - get( - this: ComputedProperties, - key: K - ): T[K]; + get(this: ComputedProperties, key: K): T[K]; /** * To get the values of multiple properties at once, call `getProperties` * with a list of strings or an array: */ - getProperties( - this: ComputedProperties, - list: K[] - ): Pick; + getProperties(this: ComputedProperties, list: K[]): Pick; getProperties( this: ComputedProperties, ...list: K[] @@ -1825,11 +1681,7 @@ declare module 'ember' { /** * Sets the provided key or path to the value. */ - set( - this: ComputedProperties, - key: K, - value: T[K] - ): T[K]; + set(this: ComputedProperties, key: K, value: T[K]): T[K]; /** * Sets a list of properties at once. These properties are set inside * a single `beginPropertyChanges` and `endPropertyChanges` batch, so @@ -1890,10 +1742,7 @@ declare module 'ember' { * without accidentally invoking it if it is intended to be * generated lazily. */ - cacheFor( - this: ComputedProperties, - key: K - ): T[K] | undefined; + cacheFor(this: ComputedProperties, key: K): T[K] | undefined; } const Observable: Mixin; /** @@ -2003,9 +1852,7 @@ declare module 'ember' { /** * Disconnects a view that has been rendered into an outlet. */ - disconnectOutlet( - options: string | { outlet?: string; parentView?: string } - ): void; + disconnectOutlet(options: string | { outlet?: string; parentView?: string }): void; /** * A hook you can implement to convert the URL into the model for @@ -2092,11 +1939,7 @@ declare module 'ember' { * A hook you can use to reset controller values either when the model * changes or the route is exiting. */ - resetController( - controller: Controller, - isExiting: boolean, - transition: any - ): void; + resetController(controller: Controller, isExiting: boolean, transition: any): void; /** * Sends an action to the router, which will delegate it to the currently active @@ -2276,10 +2119,10 @@ declare module 'ember' { mount( name: string, options?: { - as?: string; - path?: string; - resetNamespace?: boolean; - engineInfo?: any; + as?: string, + path?: string, + resetNamespace?: boolean, + engineInfo?: any } ): void; } @@ -2395,9 +2238,7 @@ declare module 'ember' { * Used to register callbacks to be fired whenever `App.injectTestHelpers` * is called. */ - function onInjectHelpers( - callback: (app: Application) => void - ): void; + function onInjectHelpers(callback: (app: Application) => void): void; /** * This returns a thenable tailored for testing. It catches failed * `onSuccess` callbacks and invokes the `Ember.Test.adapter.exception` @@ -2415,11 +2256,7 @@ declare module 'ember' { * The only difference is this uses * an instance of `Ember.Test.Promise` */ - function resolve( - value?: T | PromiseLike, - label?: string - ): Ember.Test.Promise; - function resolve(): Ember.Test.Promise; + function resolve(value?: T | PromiseLike, label?: string): Ember.Test.Promise; /** * This allows ember-testing to play nicely with other asynchronous * events, such as an application that is waiting for a CSS3 @@ -2517,12 +2354,7 @@ declare module 'ember' { } namespace Handlebars { function compile(string: string): Function; - function compile( - environment: any, - options?: any, - context?: any, - asObject?: any - ): any; + function compile(environment: any, options?: any, context?: any, asObject?: any): any; function precompile(string: string, options: any): void; class Compiler {} class JavaScriptCompiler {} @@ -2554,14 +2386,8 @@ declare module 'ember' { } const computed: { (cb: ComputedPropertyCallback): ComputedProperty; - (k1: string, cb: ComputedPropertyCallback): ComputedProperty< - T - >; - ( - k1: string, - k2: string, - cb: ComputedPropertyCallback - ): ComputedProperty; + (k1: string, cb: ComputedPropertyCallback): ComputedProperty; + (k1: string, k2: string, cb: ComputedPropertyCallback): ComputedProperty; ( k1: string, k2: string, @@ -2634,10 +2460,7 @@ declare module 'ember' { * dependent property against a given RegExp, returning `true` * if the value matches the RegExp and `false` if it does not. */ - match( - dependentKey: string, - regexp: RegExp - ): ComputedProperty; + match(dependentKey: string, regexp: RegExp): ComputedProperty; /** * A computed property that returns true if the provided dependent property * is equal to the given value. @@ -2742,10 +2565,7 @@ declare module 'ember' { /** * Returns an array mapped to the specified key. */ - mapBy( - dependentKey: string, - propertyKey: string - ): ComputedProperty; + mapBy(dependentKey: string, propertyKey: string): ComputedProperty; /** * Filters the array by the callback. */ @@ -2770,10 +2590,7 @@ declare module 'ember' { * A computed property which returns a new array with all the unique * elements from an array, with uniqueness determined by specific key. */ - uniqBy( - dependentKey: string, - propertyKey: string - ): ComputedProperty; + uniqBy(dependentKey: string, propertyKey: string): ComputedProperty; /** * A computed property which returns a new array with all the unique * elements from one or more dependent arrays. @@ -2789,10 +2606,7 @@ declare module 'ember' { * properties from the first dependent array that are not in the second * dependent array. */ - setDiff( - setAProperty: string, - setBProperty: string - ): ComputedProperty; + setDiff(setAProperty: string, setBProperty: string): ComputedProperty; /** * A computed property that returns the array of values * for the provided dependent properties. @@ -2821,10 +2635,7 @@ declare module 'ember' { * present it will queue itself to run on the existing run-loops action * queue. */ - join( - method: (...args: any[]) => Ret, - ...args: any[] - ): Ret | undefined; + join(method: (...args: any[]) => Ret, ...args: any[]): Ret | undefined; join( target: Target, method: RunMethod, @@ -2876,11 +2687,7 @@ declare module 'ember' { * of milliseconds. */ later(method: (...args: any[]) => any, wait: number): EmberRunTimer; - later( - target: Target, - method: RunMethod, - wait: number - ): EmberRunTimer; + later(target: Target, method: RunMethod, wait: number): EmberRunTimer; later( target: Target, method: RunMethod, @@ -2936,11 +2743,7 @@ declare module 'ember' { * Schedule a function to run one time during the current RunLoop. This is equivalent * to calling `scheduleOnce` with the "actions" queue. */ - once( - target: Target, - method: RunMethod, - ...args: any[] - ): EmberRunTimer; + once(target: Target, method: RunMethod, ...args: any[]): EmberRunTimer; /** * Schedules a function to run one time in a given queue of the current RunLoop. * Calling this method with the same queue/target/method combination will have @@ -2957,11 +2760,7 @@ declare module 'ember' { * control has been returned to the system. This is equivalent to calling * `run.later` with a wait time of 1ms. */ - next( - target: Target, - method: RunMethod, - ...args: any[] - ): EmberRunTimer; + next(target: Target, method: RunMethod, ...args: any[]): EmberRunTimer; /** * Cancels a scheduled item. Must be a value returned by `run.later()`, * `run.once()`, `run.scheduleOnce()`, `run.next()`, `run.debounce()`, or @@ -3185,20 +2984,12 @@ declare module 'ember' { /** * Display a warning with the provided message. */ - function warn( - message: string, - test: boolean, - options: { id: string } - ): any; + function warn(message: string, test: boolean, options: { id: string }): any; function warn(message: string, options: { id: string }): any; /** * @deprecated Missing deprecation options: https://emberjs.com/deprecations/v2.x/#toc_ember-debug-function-options */ - function warn( - message: string, - test: boolean, - options?: { id?: string } - ): any; + function warn(message: string, test: boolean, options?: { id?: string }): any; /** * @deprecated Missing deprecation options: https://emberjs.com/deprecations/v2.x/#toc_ember-debug-function-options */ @@ -3244,20 +3035,12 @@ declare module 'ember' { * a target is executed on the passed object. If an array of actions * is not passed, the actions stored on the passed object are invoked. */ - function sendEvent( - obj: any, - eventName: string, - params?: any[], - actions?: any[] - ): boolean; + function sendEvent(obj: any, eventName: string, params?: any[], actions?: any[]): boolean; /** * Define a property as a function that should be executed when * a specified event or events are triggered. */ - function on( - eventNames: string, - func: (...args: any[]) => void - ): (...args: any[]) => void; + function on(eventNames: string, func: (...args: any[]) => void): (...args: any[]) => void; /** * To get multiple properties at once, call `Ember.getProperties` * with an object followed by a list of strings or an array: @@ -3301,10 +3084,7 @@ declare module 'ember' { /** * Specify a method that observes property changes. */ - function observer( - key1: string, - func: (target: any, key: string) => void - ): void; + function observer(key1: string, func: (target: any, key: string) => void): void; function observer( key1: string, key2: string, @@ -3356,10 +3136,7 @@ declare module 'ember' { * the function will be invoked. If the property is not defined but the * object implements the `unknownProperty` method then that will be invoked. */ - function get( - obj: ComputedProperties, - key: K - ): T[K]; + function get(obj: ComputedProperties, key: K): T[K]; /** * Retrieves the value of a property from an Object, or a default value in the * case that the property returns `undefined`. @@ -3440,12 +3217,7 @@ declare module 'ember' { */ function assign(target: T, source: U): T & U; function assign(target: T, source1: U, source2: V): T & U & V; - function assign( - target: T, - source1: U, - source2: V, - source3: W - ): T & U & V & W; + function assign(target: T, source1: U, source2: V, source3: W): T & U & V & W; /** * Polyfill for Object.create * @deprecated Use Object.create @@ -3527,10 +3299,7 @@ declare module 'ember' { /** * Expands `pattern`, invoking `callback` for each expansion. */ - function expandProperties( - pattern: string, - callback: (expanded: string) => void - ): void; + function expandProperties(pattern: string, callback: (expanded: string) => void): void; } export default Ember; diff --git a/types/ember/test/computed.ts b/types/ember/test/computed.ts index 7376d14639..c812ef62b3 100755 --- a/types/ember/test/computed.ts +++ b/types/ember/test/computed.ts @@ -27,13 +27,13 @@ const Person = Ember.Object.extend({ this.set('firstName', first); this.set('lastName', last); return value; - }, + } }), fullNameGetOnly: Ember.computed('fullName', { get() { return this.get('fullName'); - }, + } }), fullNameSetOnly: Ember.computed('firstName', 'lastName', { @@ -42,16 +42,15 @@ const Person = Ember.Object.extend({ this.set('firstName', first); this.set('lastName', last); return value; - }, + } }), combinators: Ember.computed(function() { return this.get('firstName'); - }) - .property('firstName') - .meta({ foo: 'bar' }) - .volatile() - .readOnly(), + }).property('firstName') + .meta({ foo: 'bar' }) + .volatile() + .readOnly() }); const person = Person.create({ @@ -80,12 +79,10 @@ assertType(person.get('fullNameGetOnly')); assertType(person.get('fullNameSetOnly')); assertType(person.get('combinators')); -assertType<{ firstName: string; fullName: string; age: number }>( - person.getProperties('firstName', 'fullName', 'age') -); +assertType<{ firstName: string, fullName: string, age: number }>(person.getProperties('firstName', 'fullName', 'age')); const person2 = Person.create({ - fullName: 'Fred Smith', + fullName: 'Fred Smith' }); assertType(person2.get('firstName')); @@ -93,7 +90,7 @@ assertType(person2.get('fullName')); const person3 = Person.extend({ firstName: 'Fred', - fullName: 'Fred Smith', + fullName: 'Fred Smith' }).create(); assertType(person3.get('firstName')); @@ -101,7 +98,7 @@ assertType(person3.get('fullName')); const person4 = Person.extend({ firstName: Ember.computed(() => 'Fred'), - fullName: Ember.computed(() => 'Fred Smith'), + fullName: Ember.computed(() => 'Fred Smith') }).create(); assertType(person4.get('firstName')); @@ -115,13 +112,13 @@ const objectWithComputedProperties = Ember.Object.extend({ collect: Ember.computed.collect('foo', 'bar', 'baz', 'qux'), deprecatingAlias: Ember.computed.deprecatingAlias('foo', { id: 'hamster.deprecate-banana', - until: '3.0.0', + until: '3.0.0' }), empty: Ember.computed.empty('foo'), equalNumber: Ember.computed.equal('foo', 1), equalString: Ember.computed.equal('foo', 'bar'), equalObject: Ember.computed.equal('foo', {}), - filter: Ember.computed.filter('foo', item => item === 'bar'), + filter: Ember.computed.filter('foo', (item) => item === 'bar'), filterBy1: Ember.computed.filterBy('foo', 'bar'), filterBy2: Ember.computed.filterBy('foo', 'bar', false), gt: Ember.computed.gt('foo', 3), @@ -155,11 +152,11 @@ const objectWithComputedProperties = Ember.Object.extend({ sum: Ember.computed.sum('foo'), union: Ember.computed.union('foo', 'bar', 'baz', 'qux'), uniq: Ember.computed.uniq('foo'), - uniqBy: Ember.computed.uniqBy('foo', 'bar'), + uniqBy: Ember.computed.uniqBy('foo', 'bar') }); const component2 = Component.extend({ - isAnimal: or('isDog', 'isCat'), + isAnimal: or('isDog', 'isCat') }).create(); assertType(component2.get('isAnimal'));