使用 TypeScript 的 DefinitelyTyped d.ts 文件和 AMD 模块
我正在通过 nuget 从 https://github.com/borisyankov/DefinitelyTyped 导入我大部分的 DefinitelyTyped 模块。
我在想是否有我遗漏的东西,因为我发现它们都缺少对AMD的支持。
在大多数模块中,我都是自己添加的:
declare module "toastr" {
export = Toastr;
}
declare module "knockout.validation" {
export = KnockoutValidationStatic;
}
declare module "knockoutmapping" {
export = KnockoutMapping;
}
declare module "jquery" {
export = $;
}
在做这个时,我可以做以下事情:
import $ = require('jquery');
import toastr = require('toastr');
并且它正确地生成了我的 AMD 模块。
define(["require", "exports", 'toastr'], function(require, exports, __toastr__) {
}
我在想是否有其他方法可以做到这一点,因为我发现大多数库的 d.ts 中没有定义 amd 导出。
答案#1
有些定义确实有这一部分,例如 Underscore。许多定义没有这一部分的原因是,导入的名称取决于你如何配置 requirejs 以及在配置中选择的短路径名称。