You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Its not really a Design proposal, it's more a question why TypeScript doesn't have it.
In Java it's common to write more than one version of a function to support many different argument constellations. For example a vector could be constucted with a start and endpoint or just the start point or just the coordinates of those points and so on.
Here is an example:
So if you want to write the constructor implementation you have to make a single constructor and check which parameters have been provided and this can get very confusing if you don't just have two or three parameters, but more like in this example. Writing implementations for each constructor would be way more readable, so why doesn't typescript support this, since it's a not very far fetched feature?
The text was updated successfully, but these errors were encountered:
It's not clear the extent to which people will accept runtime introspection to dispatch overloads. People often have differing opinions on what sort of check is appropriate in different places. Is it complete structural compatibility? Should instanceof be used?
See #3442 for an issue which proposed this. The TL;DR is given by @mhegazy in that we don't do any sort of type-driven code generation. Ideally this could be a custom transformation in the future.
Thanks @DanielRosenwasser. If I get the mentioned issue right, it totally would be possible, but would break typescript's design goals so it won't be implemented.
I'm sad, since I share the opinion of @jhchen or @AlicanC@ToastHawaii.
Its not really a Design proposal, it's more a question why TypeScript doesn't have it.
In Java it's common to write more than one version of a function to support many different argument constellations. For example a vector could be constucted with a start and endpoint or just the start point or just the coordinates of those points and so on.
Here is an example:
So if you want to write the constructor implementation you have to make a single constructor and check which parameters have been provided and this can get very confusing if you don't just have two or three parameters, but more like in this example. Writing implementations for each constructor would be way more readable, so why doesn't typescript support this, since it's a not very far fetched feature?
The text was updated successfully, but these errors were encountered: