有一种方法导入或注释打字稿模块,使得产生AMD-兼容模块?:自动将AMD代码包含在Typescript AMD模块中?
tsc --module AMD example.ts
当我试图包括包括参考外部AMD模块将自动被包括作为依赖性* .d.ts文件和导出声明语句:
///<reference path='./lib/knockout-2.2.d.ts' />
export declare var $;
export declare var _;
export module example {
export class Example {
// whatever
}
}
但是生成的模块不包括这些:
define(["require", "exports"], function(require, exports) {
(function (example) {
var Example = (function() {
function Example() { }
return Example;
})();
example.Example = Example;
})(exports.example || (exports.example = {}));
var example = exports.example;
})
真的想避免在这里创建“假”模块。
这似乎是一个很好的解决方案和使用是允许直接导入AMD模块:
var $ = import('jquery'); // This is a requirejs/AMD module, not a typescript file.
,但我不知道这是怎么可行。
编辑:
而且我也试过这种方法这里所说:Import TypeScript module using only ambient definition for use in amd
import knockout = module("./lib/knockout-2.2.d.ts");
...
但获得这些编译器错误:
example.ts(1,32): The name '"./lib/knockout-2.2.d.ts"' does not exist in the current scope
example.ts(1,32): A module cannot be aliased to a non-module type
你找到一个很好的解决方案? –
不 - 在我的情况下,我开始意识到将我的Typescript应用程序连接到单个文件('tsc -out')会更容易,而不必担心AMD,因为不会懒惰加载任何内容。 – 7zark7
我刚刚找到/// - 但是可以在我回家时先测试它。 –