microsoft / microsoft/TypeScript
Function apply does not accept `arguments`
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
function arguments apply
🕗 Version & Regression Information
I assume this applies in every version.
⏯ Playground Link
💻 Code
function f() {}
(function () {
f.apply(null, arguments);
}());
🙁 Actual behavior
arguments errors with Argument of type 'IArguments' is not assignable to parameter of type '[]'.(2345)
🙂 Expected behavior
No error.
Additional information about the issue
f.apply(null, arguments) is a universal idiom for decades, albeit one that's fallen out of favor in lieu of f(...arguments) - and when one needs to set the receiver, f.apply(O, arguments) is the only choice.
Somewhat related to #68307; basically, there should probably be an "arraylike" type that all of arrays and arguments and strings and nodelists can assign to.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TypeScript Playground link and reproduce the error in the shown function and apply call. Read the discussion, including related issue #68307, then determine how arguments-like values should be accepted while preserving type checking; done means the example compiles without the TS2345 error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100