mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-06 20:46:50 +08:00
ember-data: fix error when using async/await
This commit is contained in:
4
types/ember-data/index.d.ts
vendored
4
types/ember-data/index.d.ts
vendored
@@ -854,7 +854,7 @@ declare module "ember-data" {
|
||||
*/
|
||||
interface PromiseArray<T>
|
||||
extends Ember.ArrayProxy<T>,
|
||||
Ember.PromiseProxyMixin<PromiseArray<T>> {}
|
||||
Ember.PromiseProxyMixin<Ember.ArrayProxy<T>> {}
|
||||
class PromiseArray<T> {}
|
||||
/**
|
||||
* A `PromiseObject` is an object that acts like both an `Ember.Object`
|
||||
@@ -865,7 +865,7 @@ declare module "ember-data" {
|
||||
*/
|
||||
interface PromiseObject<T>
|
||||
extends Ember.ObjectProxy,
|
||||
Ember.PromiseProxyMixin<T & PromiseObject<T>> {}
|
||||
Ember.PromiseProxyMixin<T & Ember.ObjectProxy> {}
|
||||
class PromiseObject<T> {}
|
||||
/**
|
||||
* A PromiseManyArray is a PromiseArray that also proxies certain method calls
|
||||
|
||||
@@ -4,8 +4,10 @@ import { assertType } from "./lib/assert";
|
||||
|
||||
declare const store: DS.Store;
|
||||
|
||||
class Comment extends DS.Model {}
|
||||
class Post extends DS.Model {
|
||||
title = DS.attr('string');
|
||||
comments = DS.hasMany<Comment>('comment');
|
||||
}
|
||||
|
||||
let post = store.createRecord<Post>('post', {
|
||||
@@ -74,6 +76,34 @@ const MyRoute = Ember.Route.extend({
|
||||
}
|
||||
});
|
||||
|
||||
const MyRouteAsync = Ember.Route.extend({
|
||||
async beforeModel(): Promise<Ember.Array<DS.Model>> {
|
||||
const store = Ember.get(this, 'store');
|
||||
return await store.findAll('someStoreRecord');
|
||||
},
|
||||
async model(): Promise<DS.Model> {
|
||||
const store = this.get('store');
|
||||
return await store.findRecord('someStoreRecord', 1);
|
||||
},
|
||||
async afterModel(): Promise<Ember.Array<Comment>> {
|
||||
const post = await this.get('store').findRecord<Post>('post', 1);
|
||||
return await post.get('comments');
|
||||
}
|
||||
});
|
||||
|
||||
class MyRouteAsyncES6 extends Ember.Route {
|
||||
async beforeModel(): Promise<Ember.Array<DS.Model>> {
|
||||
return await this.store.findAll('someStoreRecord');
|
||||
}
|
||||
async model(): Promise<DS.Model> {
|
||||
return await this.store.findRecord('someStoreRecord', 1);
|
||||
}
|
||||
async afterModel(): Promise<Ember.Array<Comment>> {
|
||||
const post = await this.store.findRecord<Post>('post', 1);
|
||||
return await post.get('comments');
|
||||
}
|
||||
}
|
||||
|
||||
// GET to /users?filter[email]=tomster@example.com
|
||||
const tom = store.query('user', {
|
||||
filter: {
|
||||
|
||||
Reference in New Issue
Block a user