Compiler does not complain undecorated class using angular features

🐞 bug report

Affected Package

Not sure maybe @angular/compiler

Is this a regression?

Angular 9.1 did not enforce this, although its deprecated as far as i know

Description

We use lot of inheritance based components, most base class uses angular features such as `@ViewChild`, in Angular 9 it works fine without adding any decorators to base class, as i understand from Angular 10 onwards, it enforces to have decorator on any class using Angular features, if not it will throw error during compilation:

error NG2007: Class is using Angular features but is not decorated. Please add an explicit Angular decorator

What’s weird is, we updated our project from Angular 9 to Angular 10, it did not complain about it when buildlng, even the base classes does not have any decorator. And migration did not add any decorate as well. Angular features such as @ViewChild still works in some base classes (well, long story short some class does not evaluate @ViewChild, thats reason we update to 10, anyway very long story.)

🔬 Minimal Reproduction

Cannot reproduce on new project, only happens to the project im working on.

🔥 Exception or Error

It supposes to throw error
error NG2007: Class is using Angular features but is not decorated. Please add an explicit Angular decorator, however it DID NOT.

🌍 Your Environment

Angular Version:




Angular CLI: 10.2.1
Node: 10.15.2
OS: win32 x64

Angular: 10.2.4
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1002.1
@angular-devkit/build-angular   0.1002.1
@angular-devkit/core            10.2.1
@angular-devkit/schematics      10.2.1
@angular/cdk                    10.2.7
@angular/cli                    10.2.1
@angular/material               10.2.7
@schematics/angular             10.2.1
@schematics/update              0.1002.1
rxjs                            6.5.5
typescript                      4.0.5

Anything else relevant?
The reason we upgrade to Angular 10 is because this issue

1 possible answer(s) on “Compiler does not complain undecorated class using angular features

  1. That’s a great question. It used to be not so easy but recent improvements to VS Code actually make it much easier, I have found.

    • If you can open your project in VS Code, then navigate to the file above (at node_modules/@angular/compiler-cli/src/ngtsc/annotations/src/directive.ts) and add a breakpoint at line 81.
    • Then in the TERMINAL view of VS Code select the drop-down and click on Create JavaScript Debug Terminal.
    • Finally in this terminal simply run the ng build command.
    • The debugger should attach automatically and then stop on the breakpoint eventually.