Merge pull request #24217 from mfeckie/update-changed-attributes

Add typing for .changedAttributes()
This commit is contained in:
Arthur Ozga
2018-03-15 12:32:49 -07:00
committed by GitHub
2 changed files with 9 additions and 2 deletions
+4 -1
View File
@@ -23,6 +23,9 @@ declare module 'ember-data' {
type AttributesFor<Model> = keyof Model; // TODO: filter to attr properties only (TS 2.8)
type RelationshipsFor<Model> = keyof Model; // TODO: filter to hasMany/belongsTo properties only (TS 2.8)
export interface ChangedAttributes {
[key: string]: [any, any] | undefined;
}
interface AttributeMeta<Model extends DS.Model> {
type: keyof TransformRegistry;
options: object;
@@ -500,7 +503,7 @@ declare module 'ember-data' {
* Returns an object, whose keys are changed properties, and value is
* an [oldProp, newProp] array.
*/
changedAttributes(): {};
changedAttributes(): ChangedAttributes;
/**
* If the model `hasDirtyAttributes` this function will discard any unsaved
* changes. If the model `isNew` it will be removed from the store.
+5 -1
View File
@@ -1,5 +1,5 @@
import Ember from 'ember';
import DS from 'ember-data';
import DS, { ChangedAttributes } from 'ember-data';
import { assertType } from "./lib/assert";
const Person = DS.Model.extend({
@@ -30,3 +30,7 @@ assertType<Date>(user.get('createdAt'));
user.serialize();
user.serialize({ includeId: true });
user.serialize({ includeId: true });
const attributes = user.changedAttributes();
assertType<ChangedAttributes>(attributes);