You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Search Terms: spread length check, "bug got 0 or more"
Code
letcanvasCtx: CanvasRenderingContext2D;// Expected 4 arguments, but got 0 or more.canvasCtx.fillRect(...[0,0,100,100]);// does not throw any errorconst[x,y,w,h]=[0,0,100,100];canvasCtx.fillRect(x,y,w,h);
Expected behavior:
Being able to call a function by spreading an array, where the size of the array matches the number of requested arguments.
Actual behavior:
Typescript considers the spread to have "0 or more" elements, when it has a fixed number
In your example, since there is no indication you want a tuple type, the inferred type for the array literal is number[]. This in turn leads to the "got 0 or more" error.
TypeScript Version: 3.1.x (and below)
Search Terms: spread length check, "bug got 0 or more"
Code
Expected behavior:
Being able to call a function by spreading an array, where the size of the array matches the number of requested arguments.
Actual behavior:
Typescript considers the spread to have "0 or more" elements, when it has a fixed number
Playground Link: http://www.typescriptlang.org/play/index.html#src=let%20canvasCtx%3A%20CanvasRenderingContext2D%3B%0D%0A%2F%2F%20does%20not%20work%0D%0AcanvasCtx.fillRect(...%5B0%2C%200%2C%20100%2C%20100%5D)%3B%0D%0A%0D%0A%2F%2F%20works%0D%0Aconst%20%5Bx%2C%20y%2C%20w%2C%20h%5D%20%3D%20%5B0%2C%200%2C%20100%2C%20100%5D%3B%0D%0AcanvasCtx.fillRect(x%2C%20y%2C%20w%2C%20h)%3B%0D%0A
Related Issues: #4130 [closed]
The text was updated successfully, but these errors were encountered: