-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Implement New Optional Type Checking Flag "veryStrictArity" #54449
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
Comments
this issue should be fixed by PR #54441 |
it is also connected with #46881 |
This would break totally reasonable code like |
What problem are you actually trying to solve? Your use case doesn't describe why this should be an error. Providing a function that takes fewer arguments is not an error, it doesn't lack type safety. If a method can fulfill its purpose with fewer arguments, then that's perfectly fine. |
@MartinJohns |
If that's your answer, then you need to remove the last check from the viability checklist. This is an explicit non-goal of TypeScript:
Your argument that the class "is broken" also doesn't make sense. It's not broken, it works fine, just without the unnecessary argument. Trying to treat TypeScript exactly like other languages is a recipe for disaster and bad code. |
Indeed it will break compilation of lot of code that why bu default is disabled for example when I turn it in on TypeScript repo there are Found 1293 errors in 46 files. Errors Files |
|
@MartinJohns |
If the author introduces breaking changes like this, then you're screwed no matter what. Even when the amount of arguments stays the same the arguments can have vastly different meanings. So what's next? The names of the arguments have to match? IMO this is an obscure corner case. Honestly, your suggestion makes more sense as a linter rule, but not as part of the type system. |
We don't think this is a good idea, even as an option. This has been discussed to death in dozens of other threads and we don't need another iteration of that discussion here. #17868 (comment), #21868, etc etc. |
Suggestion
π Search Terms
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
Add an optional type checking flag
veryStrictArity
to enforce stricter checking of the arity of methods.π Motivating Example
π» Use Cases
Consider a case where a method defined in a class doesn't strictly adhere to the parameter count defined in its interface:
Despite the veryStrictArity flag being enabled, the makeSound method in class Dog would not raise an error because the sound parameter is optional in the abstract method declaration.
The proposed veryStrictArity flag could help in enforcing the presence of callback parameters, that is currently not possible in Typescript.
The text was updated successfully, but these errors were encountered: