What is the best practice of setting the attribute types within DS.Model?


#1

Say I have a DS.Model class. Is it best practice to specify the attribute type or would it be better for Ember to determine what the type is?

e.g.

export default DS.Model.extend({
  myAttr: DS.attr('string')
});

vs

export default DS.Model.extend({
  myAttr: DS.attr()
});

Thanks.


#2

No reply? :cry:

I’m genuinely interested in the answer.


#3

DS.attr type is used to validate incoming data. You can leave it unspecified if you are unsure what type of data will be stored in the attribute.

Ember will throw error if you’ll try to store a string in DS.attr(‘number’).