![](/img/trans.png)
[英](Typescript) Property 'window' does not exist on type 'Global'
[英]Typescript error: Property '_myApiUrl' does not exist on type 'Window'
我是打字稿的新手,遇到了問題。 我在 Typescript (.ts) 文件中有這個方法:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
providers: [Service1, Service2]
})
export class AppComponent implements OnInit, OnDestroy {
// more code here
myMethod() {
this.isLoading = true;
const serverPath = 'http://myApiUrl';
// more code here
}
// more code here
}
我已經用一個變量window._myApiUrl
替換了http://myApiUrl
window._myApiUrl
並且我得到了錯誤:
Property '_myApiUrl' does not exist on type 'Window'
myMethod() {
this.isLoading = true;
const serverPath = window._myApiUrl;
// more code here
}
為什么會發生這種情況? 我該如何解決這個問題?
打字稿不知道變量存在。 你可以聲明它:
declare global {
interface Window {
_myApiUrl: string;
}
}
export class...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.