Есть ли способ заставить потребителя использовать весь итератор? ">const [first] = tuple // throws "Need to use both"
const [first, second] = tuple // works
< /code>
Я надеялся что-то вроде: < /p>
*[Symbol.iterator]() {
const tuple = this.error
? ([null, this.error] as const)
: ([this.value, null] as const);
yield tuple[0];
return {
done: true,
value: (() => {
throw new Error("Must destructure both values from tuple");
})(),
};
}
< /code>
будет работать, но не так. Это вообще возможно? Я не могу придумать твердого пути, но мне бы понравилась помощь от большого мозга.
Подробнее здесь: https://stackoverflow.com/questions/794 ... e-iterator