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 –