3 ms·
No, because JS concat is an in place operation, Typescript models it as Array<T>.concat() (intentionally leaves it "narrow") rather than Array<T>.concat<U exten
by WorldMaker 8y ago
No, because JS concat is an in place operation, Typescript models it as Array<T>.concat() (intentionally leaves it "narrow") rather than Array<T>.concat<U extends T>(). In this case it is the input type that potentially would need to change so that the left hand side was Array<Leaf | Aggregator>.
Or as others point out, array spread does widen unlike concat (because it isn't an in-place operation).
- WorldMaker 8y agoApparently concat does not operate in place, my mistake. I've been coding in TS for so long I assumed its definition was correct. https://news.ycombinator.com/item?id=18907771 https://news.ycombinator.com/item?id=18907771 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...