ng-packagr: False Positive: 'QueryList' is imported from external module '@angular/core' but never used
Type of Issue
[ X] Bug Report
Description
A warning is logged during build time if a component uses ‘@ContentChildren’ or ‘@ViewChildren’ annotation with QueryList type.
'QueryList' is imported from external module '@angular/core' but never used
How To Reproduce
Create a new component, which has this property:
@ContentChildren(MyOptionComponent)
options: QueryList<MyOptionComponent>;
Expected Behaviour
No Warning should be logged, since QueryList is being used for type safety here.
Version Information
$ node_modules/.bin/ng-packagr --version
ng-packagr: 2.2.0
@angular/compiler: 5.2.3
@angular/compiler-cli: 5.2.3
rollup: 0.55.5
tsickle: 0.26.0
typescript: 2.5.3
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 53
- Comments: 30 (5 by maintainers)
any progress here?
Hi! This issue will gone if you will use
import typefrom Typescript 3.8For example:
It works nice for ng-packagr@10.0.0
Also happens with TemplateRef, I’m using it as a type:
@ViewChild('my-template') myTemplate: TemplateRef<any>And when compiling it says:
'TemplateRef' is imported from external module '@angular/core' but never usedI know this won’t cause a problem, that’s why i said in the title it is a false positive 😁
To all those commenting specific cases:
This will happen with any Class you import then use only as a type definition.
As already linked above this is a duplicate of: angular/angular#21280
Just ignore this warning, that is the best solution 😃
Sorry, i cannot share ny project files.
This issue is easily reproducible, just use the @ContentChildren with QueryList type.
This warning went away when I switched to Ivy builds and disabled
emitDecoratorMetadatafor libraries:tsconfig.js:
Admittedly this isn’t (yet) a viable workaround if you’re publishing libraries that need to be used by non-Ivy projects.
Same thing happens to me. I am using TemplateRef to reference to a modal
I get similar problem like this when using
ElementRef.I tried using
tslint:disableand that did not help.This warning message logged 2x to console is
'ElementRef' is imported from external module '@angular/core' but never used. See full console output from build:Here is my component that makes compile warning.
The
gmapElement: ElementRefis just a reference to a div in the html markup who looks like this<div class="map" #gmap></div>Clearly
ElementRefis used, it is the type of a class member. And the class member is used in the lineconst map = new google.maps.Map(this.gmapElement.nativeElement, mapProp);so there is no reason compiler should warn about this. Even more baffling the tslint flag is ignored.Incidentally, warnings disappeared when I upgraded to Angular 10 (along with all other JS deps).
I was going to implement @Semigradsky solution when I noticed that Angular 10 was just released. So I started by upgrading everything. And without any change in my own code, warnings disappeared. I did not investigate further to find out exactly which package upgrade solved this, but if you are in a position to upgrade Angular, you might want to try that first.
@PowerKiKi You are correct, I was not able to reproduce this with latest Angular either. Closing this issue, thanks!