02:05
<Jack Works>
The sad part, you have to do this even if you're using typescript
02:09
<Jessidhia>
it’d be weird if typescript could magically implement overloads for you
02:09
<Jessidhia>
would likely end up with C++ name mangling and having to annotate functions meant to interop with regular JavaScript as “extern”
15:45
<TabAtkins>
That example just shows ordinary end-of-signature optionality, doesn't it? you could just write it as function foo(index, name=index) today, if i'm reading correctly
15:50
<jschoi>
That example just shows ordinary end-of-signature optionality, doesn't it? you could just write it as function foo(index, name=index) today, if i'm reading correctly
Note that the example sets name to index if name is undefined. So it’s not similar to function foo(index, name=index); it’s basically function foo(«optional index», name).
15:51
<TabAtkins>
??? You just explained what my code did, then gave an example that didn't match.
15:55
<ljharb>
TabAtkins: except that defaulting only works on undefined, and "the arg isn't passed" is usually pivoting on more than that
15:55
<joepie91 🏳️‍🌈>
jschoi: can brief feedback be provided here or should it be on that issue specifically?
15:55
<ljharb>
like, "is this arg a function? it's a callback, else it's an options bag"
15:57
<TabAtkins>
ljharb: yeah i get the case they're talking about, but the code example given was literally checking the final argument for === undefined, and defaulting it to a preceding argument, which is just a manual implementation of normal argument defaulting
15:57
<TabAtkins>
joepie91 🏳️‍🌈: on the issue, please
15:57
<Jessidhia>
my specific reaction was to typescript overloads; if you just do trailing optional arguments then you don’t need overloads; typescript overloads do a whole lot more than awkwardly expressing optionality
15:57
<joepie91 🏳️‍🌈>
alright :)
15:58
joepie91 🏳️‍🌈
notes that a far more common case of prefix optionality is based on runtime type-checking of the first arguments rather than existence of the last ones
15:58
<joepie91 🏳️‍🌈>
(source: N=1, all the various code I've seen pass by as a professional dependency auditor)
15:59
<joepie91 🏳️‍🌈>
so eg. if the first argument is a number then that implies that the first argument was left out and the second should be moved to the first, but if the first argument is a string then a second argument will be expected, that sort of thing
16:33
<TabAtkins>
Yeah, I've seen that before (and written it - canonical example is a range() function, where the arglists are either (end) (implied start of 0) or (start, end)).
16:55
<jschoi>
ljharb: yeah i get the case they're talking about, but the code example given was literally checking the final argument for === undefined, and defaulting it to a preceding argument, which is just a manual implementation of normal argument defaulting
Oh wait, I misread your example, oops. Need coffee.