-
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
Overload on constants: type checking additional parameters #191
Comments
This behavior is really unfortunate/unexpected. @jonathandturner and I talked about this for a long time trying to figure out what exactly the formal rule is. One complication is that we allow arbitrary intermixing of string constant overloads in any parameter position, so it's hard to write a rule that exactly encompasses what the user intent is with this rule. |
I just got surprised by this, but it turned out okay. Initially I designed an API so clients would say:
And found (as above)
In OO terms: return a "builder object" that accepts the remaining information, or a "fluent interface". (Or in much cooler FP terms: currying.) Of course this is no good if you want to stick rigidly to describing some existing JS API, but you can provide it as a type-checkable alternative for TS clients. This approach has another advantage that also worked well for me: suppose the old
The generic TL;DR: it was a surprise, but turned out not to be a problem in practise. |
With #6278 in place, you can omit the general signature, and the expected checks should take place. also as noted in #6746 (comment), doing so will restrict how the function can be called. |
This is great news. We've had to hack around this for a long time. I hope the fix makes it into a release soon. Thanks. |
Hi, consider this bit of code:
We use it like this:
However, while still specifying "Quux", if we pass any type other than new Bar() for the second argument, the compiler falls back to the non-overloaded method:
I think this is a bit unfortunate. We are missing an opportunity to verify that the additional arguments also match the overloaded signature.
Ideally the following
should generate error TS2082: Supplied parameters do not match any signature of call target
See further discussion on the old codeplex site.
The text was updated successfully, but these errors were encountered: