Repository navigation
Description
I'm submitting a ... (check one with "x")
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
The following would fail:
export function getWindow() { return window; }
@NgModule({
declarations: [
AppComponent,
SimpleRouteComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
AppRoutingModule
],
providers: [
{provide: 'window', useFactory: getWindow}
],
bootstrap: [AppComponent]
})
export class AppModule {
constructor(@Inject('window') w: Window) {
console.log(w);
}
}
With error
ERROR in Error encountered resolving symbol values statically. Could not resolve type Window (position 29:36 in the original .ts file), resolving symbol AppModule in /Users/Meligy/Code/github/Meligy/routing-angular-cli/src/app/app.module.ts
Expected behavior
I'd expect the AoT compiler to be able to understand
Minimal reproduction of the problem with instructions
- Create a new app using latest Angular CLI
- Go to
AppModule, modifyprovidersand addconstructoras shown above - Run
npm start -- --aot
What is the motivation / use case for changing the behavior?
I want to be able to test the places where I happen to have to use window. I still want to have type safety for my calls to it.
Please tell us about your environment:
Mac OS latest
Running npm run ng -- version returns:
angular-cli: 1.0.0-beta.26
node: 6.9.1
os: darwin x64
@angular/common: 2.4.4
@angular/compiler: 2.4.4
@angular/core: 2.4.4
@angular/forms: 2.4.4
@angular/http: 2.4.4
@angular/platform-browser: 2.4.4
@angular/platform-browser-dynamic: 2.4.4
@angular/router: 3.4.4
@angular/compiler-cli: 2.4.4
Things to note:
- The type
Windowis declared in default TypeScript libdom. - The libs
["es6", "dom"]are already added by default in my project (default Angular CLI layout) - I also tried to reference the file
node_modules/typescript/lib/lib.dom.d.tsdirectly in several ways, and that didn't seem to help
Please note that the code WORKS JUST FINE when I'm not using AoT.
That's npm start works, and npm start -- --aot fails (npm start here equals ng serve)
- Angular version: 2.0.X
Angular 2.4.4 as shown above.
- Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
Tested in Chrome, but the error comes in Terminal anyway.
- Language: [all | TypeScript X.X | ES6/7 | ES5]
TypeScript 2.0.10
- Node (for AoT issues):
node --version=
node: 6.9.1
Activity
DzmitryShylovich commentedon Jan 21, 2017
Windowis an interface. #12631Meligy commentedon Jan 21, 2017
@DzmitryShylovich That's why I'm using the string token not the type directly:
Note the quotes.
Meligy commentedon Jan 21, 2017
Interesting. Looks like it happens even with strings and tokens.
Meligy commentedon Jan 21, 2017
You are absolutely right. This is a duplicate of #12631.
I can workaround it by doing this funny way:
DzmitryShylovich commentedon Jan 21, 2017
it's not about the token type. it's about the argument type.
Meligy commentedon Jan 21, 2017
Yeah. I get it now. You are absolutely correct.
angular-automatic-lock-bot commentedon Sep 10, 2019
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.