question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Class requires Angular annotation even when abstract.

See original GitHub issue

Angular 10.0.0 build yields

NG2007: Class is using Angular features but is not decorated while class is marked as abstract.

export abstract class B {}

@Injectable({...})
export class A extends B {}

CLI should be able to compile, as did earlier versions.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:13
  • Comments:38 (15 by maintainers)

github_iconTop GitHub Comments

22reactions
Christopherjlcommented, Sep 28, 2020

In my opinion Component, Directive and Injectable does not make any sense on an abstract class. Clearly this error is a false positive and adding Directive may be a workaround.

16reactions
nartccommented, Jun 27, 2020

@JoostK Using abstract classes which are meant to be extended only. The following example worked in Angular 9

export abstract class Destroyable implements OnDestroy {
  protected $destroyed = new Subject();

  ngOnDestroy() {
    this.$destroyed.next();
    this.$destroyed.complete();
  }
}

// SomeComponent
@Component({...})
export class SomeComponent extends Destroyable implements OnInit {
   ngOnInit() {
      someObservable.pipe(takeUntil(this.$destroyed)).subscribe(...)
   }
}

I think abstract classes should be excluded from the list of required annotations since it’s never meant (or be able to) to be instantiated anyway.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Missing @Directive()/@Component() decorator migration
This migration adds an empty @Directive() decorator to undecorated base classes that: Use Angular features; Are extended by directives or components.
Read more >
angular - Angular4 Components inheritance with abstract class
There's no need to add @Component() annotations to abstract classes or register them to any module. It could be that there's something wrong ......
Read more >
Using Abstract Classes As Dependency-Injection Tokens With ...
Ben Nadel looks at how to use an abstract class as a Dependency-Injection (DI) token in Angular 9.1.9. He uses a technique that...
Read more >
Angular Dependency Injection: Complete Guide
So what exactly is dependency injection? When you are developing a smaller part of your system, like a module or a class, you...
Read more >
How to Share Lifecycle Methods Between Components in ...
Sharing code between components in Angular is TOUGH. ... the problem of having to mark a component class as abstract because even without...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found