Been meaning to write this for a while, but take this as very WIP and ad-hoc. So with function overloading is generator overloading. In most cases Object.entries, Object.keys, and Object.values are no longer needed with this support.
A basic iterable:
var o = {};
o[Symbol.iterator] = function* ()
{
yield* [1, 2, 3];
};
[...o]; // [1, 2, 3]
Overloaded example:
var o = {};
o[Symbol.iterator] =
[
function* ():int32
{
yield* [1, 2, 3];
},
function* ():[int32, int32]
{
yield* [[0, 1], [1, 2], [2, 3]];
}
];
[...o:int32]; // [1, 2, 3] Explicit selection of the generator return signature
for (const a:int32 of o) {} // Type is optional in this case
[...o:[int32, int32]]; // [[0, 1], [1, 2], [2, 3]]
for (const [a:int32, b:int32] of o) {} // Type is optional in this case
Been meaning to write this for a while, but take this as very WIP and ad-hoc. So with function overloading is generator overloading. In most cases Object.entries, Object.keys, and Object.values are no longer needed with this support.
A basic iterable:
Overloaded example: