microsoft / microsoft/TypeScript

Function apply does not accept `arguments`

Open
#57,164 13 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
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

https://tsplay.dev/N9231m

💻 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.