'Angular Library base class without any decorator but using Angular features

I came across this in the Angular migration guide.

https://angular.io/guide/migration-undecorated-classes

I'm a library author. Should I add the @Directive() decorator to base classes?

As support for selectorless decorators is introduced in Angular version 9, if you want to support Angular version 8 and earlier, you shouldn't add a selectorless @Directive() decorator. You can either add @Directive() with a selector or move the Angular-specific features to affected subclasses.

I then checked our code library to find that there are some base classes that still don't have any decorators but is running in Angular V11. I don't see any compile errors nor linting errors.

There are many such base classes that uses angular features, hostbinding etc but still without a decorator. Is there a linting rule or some way with which we can catch these?



Solution 1:[1]

I later figured out that with Ivy Compiler such classes without decorators are caught at compile time: NG2007: Class is using Angular features but is not decorated. Please add an explicit Angular decorator.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 vp310