question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type JS's `arguments` object based on function parameters

See original GitHub issue

Search Terms

type “arguments” object parameters

Suggestion

Within a function x, the type of the arguments object should be Parameters<typeof x> & IArguments, with undefined removed from the type of any entries in Parameters<typeof x> if that parameter has a default value.

Use Cases

class A {
   fn(it: number) { return true; }
}

class B extends A {
  fn(it: number) {
    // this shouldn't error, because arguments must be at least length 1.
    // instead we get ERROR: Expected 1 arguments, but got 0 or more.
    return super.fn(...arguments); 
  }
}

Checklist

My suggestion meets these guidelines:

  • [?] This wouldn’t be a breaking change in existing TypeScript/JavaScript code
  • This wouldn’t change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript’s Design Goals.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ElianCordobacommented, Jan 9, 2019

Same problem here, I tried this but it didn’t work either

...
testFn(a, b, c) {
  const args = [...arguments].slice(0, 3);
  testFn(...args);
}
...
1reaction
chrmarticommented, Dec 20, 2018

The strictBindCallApply feature makes the following show an error for passing arguments where an array is expected. That might be fixed by what is being discussed here as well.

function one(a: string, b: number) {

}

function two(a: string, b: number) {
	one.apply(null, arguments);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

The arguments object - JavaScript - MDN Web Docs - Mozilla
arguments is an Array -like object accessible inside functions that contains the values of the arguments passed to that function.
Read more >
Chapter 7. Object arguments: functions working with objects
When you pass an object to a function as an argument, the code in the function body has access to the object's properties....
Read more >
JavaScript Function Parameters
Function parameters are the names listed in the function definition. Function arguments are the real values passed to (and received by) the function....
Read more >
Set type for function parameters? - javascript
You can simply call the functions you want. If the object contains them, they will run, otherwise you will get an error. –...
Read more >
JavaScript Arguments Object Function Tutorial - YouTube
In this exercise we explore the Arguments object in JavaScript. ... All of the functions we write, have an arguments object tied to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found