-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When body function use "arguments" object, should there be an error (using "noUnusedParameter" is true) #9792
Comments
I would argue this is a bit unusual and the author should write something like this to make their intent clear: function fn(arg1, arg2): void;
function fn() {
// do something with 'arguments' here
} |
... though I guess this doesn't handle the case where you want to use |
You've got to declare formal parameters if you want the function to have a specific arity (eg Doesn't #9458 solve this? i.e., declare it like |
Also, I don't think the mere presence of |
Shouldn’t rest parameters eliminate the need for |
rest parameters will add a for loop and a copy operation to your output. if you are using |
As noted by @RyanCavanaugh and @yortus, you have two options, either remove the arguments and use an overload, or rename them to start with |
@mhegazy or both! The overload supplies pretty param names for intellisense, and the implementation maintains the correct arity (ie function fn(arg1, arg2): void; // pretty param names for intellisense
function fn(_1, _2) { // formal params to preserve function arity
// do something with 'arguments' here
}``` |
Sure, that would work as well. |
TypeScript : 2.0.0
While trying to apply "noUnusedParameter" option in TypeScript code base, I ran into situation when one use Function.apply and pass in "arguments" object. Our compiler will then issue an error that the containing function's parameter is unused, should we still give an error in this case or by seeing "arguments" object use in function body we should not give an error
The text was updated successfully, but these errors were encountered: