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
{{ message }}
Repository navigation
Using "arguments" keyword with Function.prototype.apply causes TS2345 #36470
When apply synthesizes its argument type, it produces a tuple type like [any?, ...args: any[]]. Tuple types imply that they are actually implemented as Arrays (e.g. you can use non-mutating methods like slice), but this isn't strictly necessary for call/apply - they can work on ArrayLikes, which make sense because arguments is only array-like (it's not really an array). So the more accurate type would be something like ArrayLikeify<[any?, ...args: any[]]> where ArrayLikeify would somehow just move over the non-array bits, but we're not super equipped to do this right now.
Activity
RyanCavanaugh commentedon Jan 29, 2020
When
applysynthesizes its argument type, it produces a tuple type like[any?, ...args: any[]]. Tuple types imply that they are actually implemented asArrays (e.g. you can use non-mutating methods likeslice), but this isn't strictly necessary forcall/apply- they can work onArrayLikes, which make sense becauseargumentsis only array-like (it's not really an array). So the more accurate type would be something likeArrayLikeify<[any?, ...args: any[]]>whereArrayLikeifywould somehow just move over the non-array bits, but we're not super equipped to do this right now.dead-claudia commentedon Apr 6, 2020
I have a local workaround for this:
Obviously unsafe and I'm not sure if it's ideal for everyone, but it works well enough for me.
zengyuanqiu commentedon May 4, 2023
MDN
The apply() method calls the specified function with a given this value, and arguments provided as an array (or an array-like object)
zengyuanqiu commentedon May 4, 2023
MDN
The apply() method calls the specified function with a given this value, and arguments provided as an array (or an array-like object)