public drawTextTest(p1: number, p2: number, p3: number):void {
console.log(p1, p2, p3);
}
let array = [2, 2, 5];
this.drawTextTest( ... array );
我在编辑器中遇到这个错误
[ts] Expected # arguments, but got a minimum of 0.
为什么在使用扩展运算符传递参数时 TypeScript 会报错?
当我实际运行代码时没有错误,传播运算符只是让我将数组用作函数的参数,但在 VSCode 中它向我显示错误,就好像我不能。
最佳答案
类型展开运算符仅在所有参数都标记为可选时才有效
public drawTextTest(p1?: number, p2?: number, p3?: number):void {
参见 https://github.com/Microsoft/TypeScript/issues/4130#issuecomment-303486552
关于使用 Spread 运算符时出现 TypeScript 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45225128/