Spread Syntax And Typescript — Supplied Parameters Do Not Match?
Looking at this simple code from MDN : function myFunction(x, y, z):void { } var args = [0, 1, 2]; myFunction(...args); — I get an error : Even If I'm being super clear : fun
Solution 1:
As far as TypeScript is concerned, you're passing an array to a function that takes three arguments. Thus the signature mismatch error.
Let me be clear here: What you have is absolutely valid ES2015 JavaScript. It's just not valid TypeScript.
(<any>myFunction)
casts myFunction
as, well, "anything", so TypeScript doesn't look at the function definition. (<any>)(myFunction(...args));
would tell the compiler the result of calling myFunction
is any
.
Post a Comment for "Spread Syntax And Typescript — Supplied Parameters Do Not Match?"