【发布时间】:2012-11-29 19:26:10
【问题描述】:
有没有办法导入或注释 Typescript 模块,以便在生成 AMD 兼容模块时自动将外部 AMD 模块作为依赖项包含在内?:
tsc --module AMD example.ts
我尝试同时包含引用 *.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 会更容易,因为它不会延迟加载任何东西。跨度> -
我刚刚找到了 ///
- 但我回家后可以先测试一下。 -
不知道这个谢谢
-
但我无法 100% 解决它,它增加了对依赖项的敲除,而不是对函数参数。
标签: requirejs typescript