2016-08-29 2 views
1

이 문제점은 IDE WebStorm과 관련되어 있습니다. 나는 WebStorm에보고했다. 그리고 트랙 here.명시 적으로 lib.d.ts 유형을 사용하는 방법은 무엇입니까?

어떻게 명시 적으로 lib.d.ts 유형과 위치를 사용하는 타이프 라이터 2.

와 각도 2를 사용하고? 지금은 2016.3 EAP를 내 IDE의 WebStorm에서 빨간색 표시하기 때문에 :

const hostname = location.hostname; 
const hostname = window.location.hostname; 

enter image description here


내 파일이 있습니다

import { Location } from '@angular/common'; 

constructor(private _location: Location) {} 
// note there is an underline before 
// and when I use in other functions, I actually use 'this._location' not just '_location' 

내가 발견 import { Location } from '@angular/common';의를 제거한 후 오류는 사라질 것입니다.


는 그리고이 오류는 IDE가이에서 location이라고 생각하는 것이 있기 때문에 보여줍니다 이유를 추측 각도 2.

당신은이 각도에서 Location에 속하는 모든 기능 아래의 스크린 샷에서 볼 수

.

enter image description here


방법은 const hostname = (location as any).hostname;을 사용 하나,하지만 더 좋은 방법이 있니? 감사합니다

tsconfig.json 도움이된다면 : @ NitzanTomer의 도움을

{ 
    "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 
    } 
} 
+0

:에서 [ "ES6", "DOM"]'라인을' tsconfig.json'? –

+0

@NitzanTomer 여전히 동일 –

+0

[각 위치] (https://github.com/angular/angular/blob/master/modules/%40angular/common/src/location/ts/L47) 사이에 혼동이 있어야합니다.) 및 [builtin Location] (https://developer.mozilla.org/en-US/docs/Web/API/Location)을 참조하십시오. 이유는 확실하지 않습니다. 인텔리 센스 오류입니까 아니면 컴파일이 실패합니까? 실행 해 보셨습니까? 런타임에도 오류가 발생합니까? –

답변

1

감사합니다.

이 문제는 WebStorm과 관련이있는 것처럼 보입니다.

난 당신이 여기에 문제를 추적 할 수 WebStorm에보고 :

당신은` "lib 디렉토리"를 제거하면 어떻게됩니까

https://youtrack.jetbrains.com/issue/WEB-23021