You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AoT error with @Inject and global interface type #15640
[x] bug report => search github for a similar issue or PR before submitting
Current behavior
Looks like the issue with interfaces from #12631 is still present. Ngc doesn't throw for user defined interfaces, but still throws for global interfaces from typescript such as Window or Navigator
Minimal reproduction of the problem with instructions
Failed on type {"filePath":"D:/Workspace/angular-/src/app/app.module.ts","name":"App","members":[]} with error Error: Error encountered resolving symbol values statically. Could not resolv
e type Window (position 14:36 in the original .ts file), resolving symbol App
Reacted by Fabian Wiles, Alex Malkevich, Chris Brown, Kiback Lee, Bobby Earl, Tyler Davis, alexander taylor, Yuta Moriyama, Suguru Inatomi, Yurii Zhoholiev and 38 more
Reacted by Yuta Moriyama, Marcel Tinner, Robin Bomkamp, Leonardo Chaia and Klemen Oslaj
I'm trying to inject a native class AudioNode, it's not an interface, it's a class and it is provided by parent component, but AOT compilation fails with Can't resolve all parameters :(
I found, that this bug happens, when I have argument type with dots.
So when I give to parameter type like "LocationService" - it works, while ng.ILocationService with AOT produces this error.
Here is workaround.
I created file "AngularAOTWorkarounds.ts" with next content:
export type IRouteService = ng.route.IRouteService;
Then I just import that name alias where I need:
import {IRouteService} from "./AngularAOTWorkarounds"
@StNekroman That looks like a separate issue, which I believe is still an issue in Ivy. Could you open a new issue with a reproduction, preferably with a Github repo?
Regarding the reported issue, I attempted to reproduce in Angular 9.0 and I'm unable to: this works in both ViewEngine and Ivy.
@JoostK I'm still experiencing this error on ng build library --prod
------------------------------------------------------------------------------
Building entry point 'library'
------------------------------------------------------------------------------
Compiling TypeScript sources through ngc
ERROR: C:/Projects/shared-mc-theme/projects/library/src/lib/theme.service.ts:8:1: Error encountered in metadata generated for exported symbol 'ThemeService':
C:/Projects/shared-mc-theme/projects/library/src/lib/theme.service.ts:20:45: Metadata collected contains an error that will be reported at runtime: Could not resolve type HTMLDocument.
{"__symbolic":"error","message":"Could not resolve type","line":19,"character":44,"context":{"typeName":"HTMLDocument"}}
...
The relevant code:
import { DOCUMENT } from "@angular/common";
import { Inject, Injectable, Renderer2, RendererFactory2 } from "@angular/core";
import { Observable, of } from "rxjs";
@Injectable({
providedIn: "root",
})
export class ThemeService {
private renderer: Renderer2;
constructor(
rendererFactory: RendererFactory2,
// Dependency-inject the HTML <document> element
@Inject(DOCUMENT) private document: HTMLDocument,
) {
this.renderer = rendererFactory.createRenderer(null, null);
}
...
}
Activity
Change Document type to any until fix angular/angular#15640
fix(visibility): Document type to any until angular/angular#15640 fix.
mtinner commentedon Nov 30, 2017
Working solution for AoT at least with v5
RobinBomkampDv commentedon Oct 11, 2018
Having the same issue here.
I'm injecting Window and Document with it's interfaces as injection token.
@mtinner 's solution is working for me.
But I think it is not the right way to do so.
Is there a way to use interfaces together with @Inject and aot compile?
waterplea commentedon Jan 22, 2020
I'm trying to inject a native class
AudioNode, it's not an interface, it's a class and it is provided by parent component, but AOT compilation fails withCan't resolve all parameters:(StNekroman commentedon Mar 11, 2020
I have this:
Leads to error:
Pointing on constructor argument $routeParams: ng.route.IRouteParamsService
StNekroman commentedon Mar 11, 2020
I found, that this bug happens, when I have argument type with dots.
So when I give to parameter type like "LocationService" - it works, while ng.ILocationService with AOT produces this error.
Here is workaround.
I created file "AngularAOTWorkarounds.ts" with next content:
export type IRouteService = ng.route.IRouteService;
Then I just import that name alias where I need:
import {IRouteService} from "./AngularAOTWorkarounds"
so code will be:
But I'm afraid, that I will need to do that for all interface names with dot in my 100500 files =(
JoostK commentedon Mar 15, 2020
@StNekroman That looks like a separate issue, which I believe is still an issue in Ivy. Could you open a new issue with a reproduction, preferably with a Github repo?
Regarding the reported issue, I attempted to reproduce in Angular 9.0 and I'm unable to: this works in both ViewEngine and Ivy.
dougrday commentedon Apr 3, 2020
@JoostK I'm still experiencing this error on
ng build library --prodThe relevant code:
The current versions I'm using:
robbiemu commentedon Apr 30, 2020
Im getting the same as well with ivy (9.1.1) and --prod: on
constructor (@Inject(WINDOW) private window: Window) {angular-automatic-lock-bot commentedon May 31, 2020
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.