diff --git a/types/ember-data/index.d.ts b/types/ember-data/index.d.ts index 6d83c72fd2..19362131a7 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. @@ -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?: { includeId?: boolean }): {}; /** * 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. */ @@ -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 @@ -851,7 +852,7 @@ declare module "ember-data" { */ interface PromiseArray extends Ember.ArrayProxy, - Ember.PromiseProxyMixin> {} + Ember.PromiseProxyMixin> {} class PromiseArray {} /** * A `PromiseObject` is an object that acts like both an `Ember.Object` @@ -862,7 +863,7 @@ declare module "ember-data" { */ interface PromiseObject extends Ember.ObjectProxy, - Ember.PromiseProxyMixin> {} + Ember.PromiseProxyMixin> {} class PromiseObject {} /** * A PromiseManyArray is a PromiseArray that also proxies certain method calls @@ -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`. @@ -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`. diff --git a/types/ember-data/test/model.ts b/types/ember-data/test/model.ts index b3fa04e086..a18167dbee 100644 --- a/types/ember-data/test/model.ts +++ b/types/ember-data/test/model.ts @@ -27,3 +27,6 @@ assertType(user.get('id')); assertType(user.get('username')); assertType(user.get('verified')); assertType(user.get('createdAt')); + +user.serialize(); +user.serialize({ includeId: true }); diff --git a/types/ember-data/test/store.ts b/types/ember-data/test/store.ts index f7560a231f..46b0987981 100644 --- a/types/ember-data/test/store.ts +++ b/types/ember-data/test/store.ts @@ -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 2dfa6eaf86..a669b977e1 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[]; } /** diff --git a/types/ember/index.d.ts b/types/ember/index.d.ts index 7839a3021c..7039669b39 100755 --- a/types/ember/index.d.ts +++ b/types/ember/index.d.ts @@ -1479,12 +1479,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 @@ -1799,7 +1818,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 @@ -1939,7 +1958,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. @@ -2238,7 +2257,6 @@ declare module 'ember' { * an instance of `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 * events, such as an application that is waiting for a CSS3 @@ -2472,12 +2490,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 diff --git a/types/ember/test/computed.ts b/types/ember/test/computed.ts index b9bfe2ada6..c812ef62b3 100755 --- a/types/ember/test/computed.ts +++ b/types/ember/test/computed.ts @@ -157,4 +157,6 @@ const objectWithComputedProperties = Ember.Object.extend({ const component2 = Component.extend({ isAnimal: or('isDog', 'isCat') -}); +}).create(); + +assertType(component2.get('isAnimal'));