-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Feature request - Make a parameter required for callback function #20274
Comments
have no parameters is semantically equivalent to having a parameter and ignoring its value at runtime. the later is not an indication of invalid code, and so is the earlier. a canonical example here is |
Totally disagree on this one.
it does not look like this:
if you don't pass the first argument, you are f*cked, because a it is VERY important to tell the user that the first argument is required. Omitting an argument is a failure at runtime!! So with that said, I need to tell my users that this ok run(function(t){
}); but that this is not ok: run(function(){
}); how do I do that? |
run(function(t){
// forget to use t
}); and run(function(){
}); are identification.. so you can tell them to make sure to use the argument in the docs i guess.. |
It would be more helpful if you post a snippet displaying the issue. The way I see it, the only code that needs such behaviour are functions that inspect |
@gcnew if you use
you are going to get a TypeError because you failed to pass it a function same with my code (I just improved the example) if you fail to pass @mhegazy yes I suppose a linting tool / rule could be used to enforce that the parameter is there. I am not sure how to classify this and it's a bit confusing tho. |
Ultimately this is the difference between arguments and parameters? // here are arguments
t.foo(a,b,c); // a,b,c are arguments
// here are parameters
t.foo = function(a,b,c){ // a, b, c are parameters
}; at least that's the nomenclature that I currently adhere to lol so I want to make parameters to be forced to be in place what I want is useful for APIs, not for library code the user is essentially implementing foo, but I need to tell them that foo needs to take at least one parameter |
It's in the FAQ and this has been covered many many times before. See #17868 for a recent recitation of this debate. |
@RyanCavanaugh re: https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-functions-with-fewer-parameters-assignable-to-functions-that-take-more-parameters I'd like see some option we can use to make functions with fewer parameters not assignable to functions that take more parameters is that possible? A flag in tsconfig.json? dunno |
This video shows the problem:
https://www.useloom.com/share/1a0f1e84083049ff8f745a3a1f17ac03
basically I have this
the "plain" function satisfies the typings, but I want to make the parameter required, not optional. I can't really explain but it should be clear from the (rambling) video. Thanks.
The text was updated successfully, but these errors were encountered: