我有以下的打字稿文件 - >申報VAR得到的ReferenceError:......沒有定義
module someModule {
declare var servicePort: string;
export class someClass{
constructor(){
servicePort = servicePort || ""; //ERROR= 'ReferenceError: servicePort is not defined'
}
也試圖在這裏面「SomeClass的」功能之一 - >
someFunction =() => {
if (servicePort && servicePort != '') { //ERROR - also servicePort is not defined
//do something with servicePort
}
}
如果我在我的JS/HTML文件的某處定義VAR SERVICEPORT它會工作,但不是我的所有網頁包含SERVICEPORT VAR,我想安全得到來自varible值無異常。 我在做什麼錯?
首先,它是「嚴格使用」;'。 – Nonemoticoner
我試過刪除它,仍然行爲相同 –
如果您將此TypeScript代碼編譯爲JavaScript,您將會看到'declare'在實際代碼中沒有效果。 – Nonemoticoner