TypeScript 0.9.5 – … args:任何[]死在水中? (看Q.d.ts)

我希望其中一个TypeScript能够在这里投入.我是Definitely Typed贡献者之一,我一直在努力修复与
Q.d.ts相关的破坏测试.

q-tests.ts中的以下测试在TS 0.9.5之前工作:

var eventualAdd = Q.promised((a: number, b: number) => a + b);

承诺的方法定义如下所示:

export function promised<T>(callback: (...args: any[]) => T): (...args: any[]) => Promise<T>;

但现在我们在0.9.5这个测试没有编译并失败并出现此错误:

error TS2082: Supplied parameters do not match any signature of call target:
Call signatures of types '(a: number, b: number) => number' and '(...args: any[]) => {}' are incompatible:
Call signature expects 0 or fewer parameters.
error TS2087: Could not select overload for 'call' expression.

我已经尝试调整测试以获得更多洞察力 – 例如通过指定类似的输入:

var eventualAdd = Q.promised<number>((a: number, b: number) => a + b);

但我没有得到更多的信息 – 它以类似的方式失败:

error TS2082: Supplied parameters do not match any signature of call target:
Call signatures of types '(a: number, b: number) => number' and '(...args: any[]) => number' are incompatible:
Call signature expects 0 or fewer parameters.
error TS2087: Could not select overload for 'call' expression.

谁能提供任何见解?我没有看到描述输入方式的任何问题.它看起来正确但它不起作用.我似乎记得在TS 0.9.5中,任何现在默认都被视为{}?这会打击…… args:任何[]回调签名出水吗?我希望不是!

最佳答案 感谢IgorBek在这里回答:
https://github.com/borisyankov/DefinitelyTyped/pull/1467

我引用:

“我将参数重写为可选参数…. args:any []表示函数需要0个或更多参数.所以即使没有参数也应该工作.(a:number,b:number)=>数字不可转换为因为它需要2个参数.所以当你写(一个?:数字,b?:数字)=>数字时,该函数需要0,1或2个参数(或更多,如果我们将rest参数视为未使用).“

Ryan Cavanaugh是正确的,这是重复的.我希望TypeScript按照建议进行调整,因此将非可选参数指定为可选参数不再是解决方案.这种感觉更像是一种解决方法,而不是合法的代码.

点赞