我正在使用Atom作爲我的文本編輯器在Typescript中構建項目。我安裝了atom-typescript,它會自動將我的代碼編譯爲JavaScript。Typescript包含擴展方法
我在試圖做的是定義一個新的類型字符串擴展方法,以確定它是否爲空或空白。我有一個導出單個函數的主文件,並嘗試驗證它是否正常工作。我遇到的問題是,摩卡拋出一個錯誤類型:String.isNullOrEmpty is not a function
這裏是我的stringExtensions.ts
:
interface StringConstructor {
isNullOrEmpty(str: string): boolean;
}
String.isNullOrEmpty = function(str: string): boolean{
return (!str || 0 === str.length);
}
在我main.ts
我有以下代碼:
///<reference path="extensions/stringExtensions.ts"/>
export function checkForUpdate(){
if(String.isNullOrEmpty(location)){
/* Do Stuff */
}
在main.spec.ts
import {checkForUpdate} from "../lib/update"
describe("test",()=>{
if("should do something",()=>{
checkForUpdate();
})
})
如果我將我的代碼從擴展文件複製到主文件中,那麼一切工作都正常,所以我知道這是一個參考問題。 Atom-typescript沒有發現任何錯誤,它能夠很好地找到代碼,並且一切都看起來不錯。
我需要做些什麼修改才能使參考正常工作。我正在查看已編譯的JavaScript代碼,並且沒有來自我的引用命令的導入指令。應該有嗎?