For chunkSize values known at compile-time, we we could return an union of tuples instead of a generic Array<T>. For example, chunk(3) should return Operator<T, [T] | [T, T] | [T, T, T]>.
Unfortunately, it's not possible to mark only the last item of the iterable with a different type, and I don't think TypeScript will add such a feature in the foreseeable future.
For
chunkSize
values known at compile-time, we we could return an union of tuples instead of a genericArray<T>
. For example,chunk(3)
should returnOperator<T, [T] | [T, T] | [T, T, T]>
.Unfortunately, it's not possible to mark only the last item of the iterable with a different type, and I don't think TypeScript will add such a feature in the foreseeable future.