-
Notifications
You must be signed in to change notification settings - Fork 12.8k
strictFunctionTypes disallows overloads of static methods using namespaces #18945
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
In I think this behavior is pretty reasonable and it isn't clear what a better rule would be. Is there an actual real world scenario that was broken by this? Any reason the functions couldn't just be declared as static members? |
That error message says Actual cases are here: https://github.com/falsandtru/spica/blob/master/index.d.ts I got errors with |
Namespaced functions are useful for declaration of semantics they don't depend its context. For example, static methods could throw an error because of missing As another actual case, Another point, this problem is a breaking change under the |
It's important to understand that the pattern you're using isn't type safe: let x: typeof C = D;
x.s(new C()); // D.s expects a D but here we're passing a C We are knowingly permitting this unsafe pattern for members declared as methods, but I would hate to further extend it to some functions. The whole point of
Yes, but that's to be expected with
Not sure I understand what you mean by this. |
I got the following correct error with your code. So it is type safe.
It is the answer for your question My proposal is, like class methods, excluding Or disabling checks of overloaded methods with functions in namespaces. Those functions are defined as functions, not static methods. |
The pattern of overriding a static method with one that takes a parameter of a more specific type isn't type safe. That's why we're reporting an error in |
See also #4628 - there have been past discussions about whether or not to enforce the static-side assignability of derived classes. |
@ahejlsberg I agree your basics of type system. But I believe you don't need to check those functions as overloaded methods (compiler regards them as static methods, don't you?) because they are not written by (static) class method syntax... @RyanCavanaugh That issue targets static methods, but I'm saying about functions. Static methods have no problem in this case. My proposals is Don't include any functions in the static-side of classes, or completely behave as static methods. Compiler regards some functions as static methods, but compiler doesn't apply some checks of static methods to them. It is unfair. Thanks. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
cc @ahejlsberg
TypeScript Version: master
Code
Expected behavior:
no error
Actual behavior:
The text was updated successfully, but these errors were encountered: