|
|
|
|
|
by dartos
628 days ago
|
|
> Not true. In TypeScript… Not talking about typescript. Typescript wasn’t nearly as wide spread or as complete back then anyway. Facebook was still on flow. > they operate on kv-pairs in form of 2-element arrays. So… Not tuples… > So your assertion that tuples are something alien to JS ecosystem isn't accurate simply because of that. My words were “almost nothing else.” I’m sure someone somewhere uses the idea of tuples in their js code (implemented as arrays, ofc) but it’s extremely far from the norm. Also none of that refutes my point that it’s poor api design. Thanks for being pedantic tho. |
|
TS is just encoding JS semantics into a type system.
A function returning a fixed-size array in JS is effectively returning, semantically, a tuple. They're just not a different type unlike in other languages (for different reasons).
JS arrays are not even arrays since they (1) are not contiguous and (2) do not require items to be of the same size (typed arrays are actual arrays though) except by their backing implementation (which uses js vals, but that's a property of the implementation, not the language). They're sparse vectors. But nobody cares about that technical distinction and we still call fixed-size arrays tuples and variable-size arrays arrays. You can even attach properties to them because arrays are not vectors, they are objects. Or can be, for that matter. The backing implementations are complex and very dynamic.
JS was intentionally made this simple so it could have emergent semantics. Scheme-ish.
> Typescript wasn’t nearly as wide spread or as complete back then anyway. Facebook was still on flow.
It was when they introduced hooks.