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
The above definition preserves everything including unrelated properties that do not belong to Array.prototype whilst actual Array.from discards them. (for instance, if input has foo: 'bar', output array will also has foo: 'bar').
By adding "Spread operator" section (as suggested by #27859 (comment) and #27859 (comment)), this issue is no longer within the boundary of lib.d.ts but requires changes from TypeScript engine itself. Should I move the section to a new issue or should I keep it here?
It looks like #36861 handles tuple spread... but only on pure tuple types like [0, 1, 2] and not those intersected with objects like [0, 1, 2] & { foo: 'bar' } in the example. Cross-referencing anyway:
Activity
aleclarson commentedon Feb 28, 2019
Bump. The current behavior doesn't make any sense to me.
Missing search keyword: spread, spreading
jcalz commentedon Mar 6, 2019
I'm not seeing how this proposal addresses
[...tuple]. I only seeArray.from(tuple)discussed. What am I missing?aleclarson commentedon Mar 6, 2019
Joe Calzaretta (@jcalz) I believe the proposed behavior for spreading tuples is:
[...tuple]should returntypeof tupleinstead oftuple[number][].Khải (@KSXGitHub) Can you add this to the OP please?
KSXGitHub commentedon Mar 6, 2019
I will!
No, not
typeof tuple. You did not consider the possibility thattuplemay have non-array properties, for example:KSXGitHub commentedon Mar 6, 2019
By adding "Spread operator" section (as suggested by #27859 (comment) and #27859 (comment)), this issue is no longer within the boundary of
lib.d.tsbut requires changes from TypeScript engine itself. Should I move the section to a new issue or should I keep it here?jcalz commentedon May 1, 2020
It looks like #36861 handles tuple spread... but only on pure tuple types like
[0, 1, 2]and not those intersected with objects like[0, 1, 2] & { foo: 'bar' }in the example. Cross-referencing anyway:Playground link
jakebailey commentedon Jul 9, 2023
Looking at old issues, interestingly as of TS 4.2, the above example is now:
Playground Link
So, it gets the two ends correct.