Open mhofman opened 4 months ago
Is there any other language precedent for extractor overloading?
So far as I'm aware, only in typed languages. C#'s Deconstruct
can use differing arity of the outputs to call a different overload of Deconstruct
, but that requires a static type system.
The only way overloading would be possible would be for us to provide additional context to the extractor about how it is being used such as the shape of any nested destructuring. That would require additional allocations for every extractor invocation when the large majority won't need them.
Overloading in JS is often a footgun. I would rather not carry that over to extractors.
One argument for the extractor proposal is that it mirrors RHS construction / method application on the LHS of assignments. However I believe this is only true for simple cases.
In particular, functions and constructors can have overloads. Extractors as currently proposed do not have any mechanism for overloaded extraction. One simple opportunity for overloading may be on the arity of the extraction. Anything more advanced would require the extractor to be able to get information on the extraction usage, which would like entail some way of expressing the expected types of extracted values. Is there any other language precedent for extractor overloading?