ember-can icon indicating copy to clipboard operation
ember-can copied to clipboard

Errors when attempting to create a native class extending from Ability

Open mpminardi opened this issue 3 years ago • 2 comments

Hi there! I've run into a few cases where I receive the following error while attempting to upgrade to using native classes that extend from Ability:

global failure: Error: You defined the class ExampleAbility that extends from Ember.Object using native class syntax, but you didn't mark it with the @classic decorator. All user classes that extend from this class must be marked as @classic, since they use classic features. If you want to remove the @classic decorator, you must remove the base class. For components, you can do this by converting to Glimmer components. For plain classes that extend from EmberObject, you can convert them into plain native classes that do not extend from EmberObject. If this class is a base class provided by the framework that you should be allowed to remove @classic from, please open an issue on the classic decorators repo: https://github.com/emberjs/ember-classic-decorator

One scenario I've been able to track down that has seemed to cause this is:

  1. Having a native class A that extends from Ability
  2. Having a component B that uses a can helper for A in its handlebars
  3. Having a component C that wraps component B (think of something like C being a dropdown and B being an item for example)
  4. Having a tracked property within component C

Removing the @tracked annotation from the property from component C in that scenario will allow for extending from Ability with no issues. I can work on trying to get a minimal reproducer if that is helpful here.

I've noticed that https://github.com/minutebase/ember-can/pull/151 removes the dependency on EmberObject from Ability which I imagine should resolve this issue without requiring the @classic decorator. Is this pull request still being actively worked on? Would be great to be able to use native class syntax without requiring the decorator.

Thanks in advance for the help. Let me know if I can provide any further information!

mpminardi avatar Sep 09 '22 16:09 mpminardi

Hi Mario :) Yes, this PR should solve it, but I am not sure when I will have time to finish it. It was just a vision.

For know I would recommend to use classic decorator to solve this warning.

Exelord avatar Sep 11 '22 11:09 Exelord

Gotcha, thank you for the confirmation Maciej! Will use the decorator in that case.

mpminardi avatar Sep 12 '22 02:09 mpminardi