It appears that the issue at hand is related to WebStorm IDE. I have reported it to WebStorm and you can track the progress here.
Currently, I am working with Angular 2 and TypeScript 2.
I am wondering how to explicitly utilize the location from lib.d.ts types. My IDE, WebStorm 2016.3 EAP, shows it as red:
const hostname = location.hostname;
const hostname = window.location.hostname;
https://i.sstatic.net/fCW3h.png
In my file, I have the following code:
import { Location } from '@angular/common';
constructor(private _location: Location) {}
// note the underline before
// and in other functions, I actually use 'this._location' not just '_location'
Interestingly, the error disappears when I remove
import { Location } from '@angular/common';
.
The error seems to occur because the IDE considers this as a location
from Angular 2.
Refer to the screenshot below to see all functions belonging to Location
in Angular 2.
https://i.sstatic.net/6t8v5.png
One way to address this is by using
const hostname = (location as any).hostname;
, but is there a better approach? Thank you
Below is my tsconfig.json configuration:
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"module": "commonjs",
"removeComments": true,
"sourceMap": true,
"lib": ["es6", "dom"]
},
"include": [
"node_modules/@types/**/*.d.ts",
"src/**/*.ts"
],
"exclude": [
"node_modules",
"!node_modules/@types/**/*.d.ts"
],
"compileOnSave": false,
"buildOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}