2
我有一些JavaScript代碼正在嘗試轉換爲Typescript。如何在TypeScript中導入JavaScript模塊
假設typescript是JavaScript的超集,除了下面有編譯器錯誤。假設我沒有進口劫庫爲打字稿,我將如何轉換下面的代碼:
(function(ko, viewModels){
viewModels.MyViewModel = function(){
//stuff in here
}
}(ko, window.viewModels = window.viewModels || {}));
爲參考,這是我嘗試在打字稿
module viewModels {
export class PartDetailsViewModel {
public bar: string;
constructor(){
this.bar = ko.foo(); //<-- compiler error, "ko" does not exist in current scope
}
}
}
}
更好地指出這個KO聲明(因爲它比你指出的要點更詳細一點):https://github.com/sv01a/TypeScript-Knockoutjs –
更完整:https://github.com/borisyankov/DefinitelyTyped/blob/master/Definitions/knockout-2.2.d.ts –