我最近更新了TypeScript 0.9.5,它现在在编译期间抛出新的错误。TypeScript中的RequireJS模块声明
我使用RequireJS定义了AMD模块,如HERE所述。
define('myModule', [
'angular',
'config'
], function (angular, config) {
'use strict';
...
});
为RequireJS打字稿定义文件具有RequireDefine
定义如下:
/**
* Define a module with a name and dependencies.
* @param name The name of the module.
* @param deps List of dependencies module IDs.
* @param ready Callback function when the dependencies are loaded.
* callback deps module dependencies
* callback return module definition
**/
(name: string, deps: string[], ready: (...deps: any[]) => any): void;
不过,我发现了以下错误:
error TS2082: Build: Supplied parameters do not match any signature of call target:
error TS2087: Build: Could not select overload for 'call' expression.
智能感知错误状态:
呼叫签名的类型'( angular:any,config:any)=> any'和'(... deps:any [])=> any'不兼容。
定义文件不正确?我在哪里出错的回调参数?
更多信息:
更改声明如下现在编译。
define('myModule', [
'angular',
'config'
], function (...args:any[]) {
'use strict';
...
});
但是移动到单个参数对象肯定是向后迈出的一步?这是定义文件还是TypeScript编译器的限制?
感谢您的解释,更加清晰了。但是我不确定你的建议修复是否可以真正应用于RequireJS定义文件。对一个方法所需的参数数量施加上限是可以接受的(如果你有> x你做错了什么)。考虑到模块化现在受到鼓励,限制模块可能需要的“依赖性”数量可能会更难以证明。 –
@BrettPostin你是对的,你真正想说的是,第一个传递的数组需要和函数获得约束的可变参数的长度相同。这是这里的实际限制,你不能用TypeScript(还)来表达。尽管如此,C#在1到31个参数中使用了“Func”和“Action”已经有相当长的一段时间了,它们都被广泛使用,并且投诉级别非常低。你实际上是否有任何超过31个约束的模块?就像我说的 - 我同意这是有问题的,但它也是非常实用的。 –
这对我们来说不会有问题,但由于定义文件是社区驱动的项目,因此RequireJS世界中的某个人可能会!我将把它作为[GitHub](https://github.com/borisyankov/DefinitelyTyped/tree/master/requirejs)上的问题提交。 –