TypeScript error when using the Spread operator?

后端 未结 3 1460
眼角桃花
眼角桃花 2020-12-11 00:35

Whenever I use the spread operator such as below

public drawTextTest(p1: number, p2: number, p3: number):void {
    console.log(p1, p2, p3);
}
let array = [         


        
3条回答
  •  长情又很酷
    2020-12-11 01:02

    Newer versions of TypeScript should be figuring this out through flow analysis but you should be able to get the code working by manually typing the array to the following way to ensure the min length:

    function drawTextTest(p1: number, p2: number, p3: number):void {
        console.log(p1, p2, p3);
    }
    let array: [number, number, number] = [2, 2, 5];
    this.drawTextTest( ... array );
    

提交回复
热议问题