cloudflare / workers-types

TypeScript type definitions for authoring Cloudflare Workers.
BSD 3-Clause "New" or "Revised" License
359 stars 89 forks source link

Add Symbol.iterator to WebScoketPair #325

Closed arv closed 1 year ago

arv commented 1 year ago

I haven't look at the implementation but the following monkey patch:

WebSocketPair.prototype[Symbol.iterator] = function* () {
  yield this[0];
  yield this[1];
};

allows the more ergonomic usage of desctructuring:

const [client, server] = new WebSocketPair();
mrbbot commented 1 year ago

Hey! 👋 We've had a feature request for this before (https://github.com/cloudflare/workers-types/issues/147), but I don't think we're going to implement it. As you point out, you can monkey patch this in user-land if you'd like it. 🙂