jeudi 15 mars 2018

What is the proper way to write a computed property using TypeScript and Ember?

I have a relatively small Ember/TypeScript app that I have been working on for about six months. I used to define computed properties as follows:

   @computed('styleNamespace', 'status')
   statusClass(componentClassName: string, status: string): string {
     return `${componentClassName}--${status}`
   }

But I have never been able to get this to pass TypeScript checking properly. After reviewing Chris Krycho's Emberconf training materials, it seems that the "proper" way to do this is as follows:

   @computed('styleNamespace', 'status')
   get statusClass(this: CertificateCard): string {
     return `${this.get('styleNamespace')}--${this.get('status')}`
   }

Is this correct? I seem to be missing something, though because I am still getting errors like this:

Error: Assertion Failed: Attempted to apply @computed to statusClass,
but it is not a native accessor function. 
Try converting it to `get statusClass()`




Aucun commentaire:

Enregistrer un commentaire