Type JS's `arguments` object based on function parameters
See original GitHub issueSearch 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:
- Created 5 years ago
- Reactions:4
- Comments:8 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Same problem here, I tried this but it didn’t work either
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.