Skip to content

Commit

Permalink
Consistently use Promise<void> instead of Promise<undefined>
Browse files Browse the repository at this point in the history
lib.dom.d.ts ubiquitously uses Promise<void> for promises not resolving
to undefined. It has done this for a long time.

When the generator was written, there were 0 or 1 (I can't quite tell)
places where this type of promise occured outside of a function return
value. However, Web Streams are now widely supported, and they have
properties that are promises that resolve to no value. These are
currently typed as Promise<undefined>. This commit changes them to be
typed as Promise<void>, to align with the rest of lib.dom.d.ts.

There are 5 readonly properties that are impacted by this change.
  • Loading branch information
lucacasonato committed Jul 19, 2023
1 parent 13115c8 commit a6be967
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
6 changes: 3 additions & 3 deletions baselines/audioworklet.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ declare var ReadableStreamDefaultReader: {

interface ReadableStreamGenericReader {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/closed) */
readonly closed: Promise<undefined>;
readonly closed: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/cancel) */
cancel(reason?: any): Promise<void>;
}
Expand Down Expand Up @@ -1121,11 +1121,11 @@ declare var WritableStreamDefaultController: {
*/
interface WritableStreamDefaultWriter<W = any> {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/closed) */
readonly closed: Promise<undefined>;
readonly closed: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/desiredSize) */
readonly desiredSize: number | null;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/ready) */
readonly ready: Promise<undefined>;
readonly ready: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/abort) */
abort(reason?: any): Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/close) */
Expand Down
8 changes: 4 additions & 4 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18564,7 +18564,7 @@ declare var ReadableStreamDefaultReader: {

interface ReadableStreamGenericReader {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/closed) */
readonly closed: Promise<undefined>;
readonly closed: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/cancel) */
cancel(reason?: any): Promise<void>;
}
Expand Down Expand Up @@ -25448,7 +25448,7 @@ interface WebTransport {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebTransport/incomingUnidirectionalStreams) */
readonly incomingUnidirectionalStreams: ReadableStream;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebTransport/ready) */
readonly ready: Promise<undefined>;
readonly ready: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebTransport/close) */
close(closeInfo?: WebTransportCloseInfo): void;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebTransport/createBidirectionalStream) */
Expand Down Expand Up @@ -26055,11 +26055,11 @@ declare var WritableStreamDefaultController: {
*/
interface WritableStreamDefaultWriter<W = any> {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/closed) */
readonly closed: Promise<undefined>;
readonly closed: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/desiredSize) */
readonly desiredSize: number | null;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/ready) */
readonly ready: Promise<undefined>;
readonly ready: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/abort) */
abort(reason?: any): Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/close) */
Expand Down
12 changes: 6 additions & 6 deletions baselines/serviceworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ interface ExtendableMessageEventInit extends ExtendableEventInit {

interface FetchEventInit extends ExtendableEventInit {
clientId?: string;
handled?: Promise<undefined>;
handled?: Promise<void>;
preloadResponse?: Promise<any>;
replacesClientId?: string;
request: Request;
Expand Down Expand Up @@ -2475,7 +2475,7 @@ interface FetchEvent extends ExtendableEvent {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FetchEvent/clientId) */
readonly clientId: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FetchEvent/handled) */
readonly handled: Promise<undefined>;
readonly handled: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FetchEvent/preloadResponse) */
readonly preloadResponse: Promise<any>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FetchEvent/request) */
Expand Down Expand Up @@ -4576,7 +4576,7 @@ declare var ReadableStreamDefaultReader: {

interface ReadableStreamGenericReader {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/closed) */
readonly closed: Promise<undefined>;
readonly closed: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/cancel) */
cancel(reason?: any): Promise<void>;
}
Expand Down Expand Up @@ -7793,7 +7793,7 @@ interface WebTransport {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebTransport/incomingUnidirectionalStreams) */
readonly incomingUnidirectionalStreams: ReadableStream;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebTransport/ready) */
readonly ready: Promise<undefined>;
readonly ready: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebTransport/close) */
close(closeInfo?: WebTransportCloseInfo): void;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebTransport/createBidirectionalStream) */
Expand Down Expand Up @@ -8087,11 +8087,11 @@ declare var WritableStreamDefaultController: {
*/
interface WritableStreamDefaultWriter<W = any> {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/closed) */
readonly closed: Promise<undefined>;
readonly closed: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/desiredSize) */
readonly desiredSize: number | null;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/ready) */
readonly ready: Promise<undefined>;
readonly ready: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/abort) */
abort(reason?: any): Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/close) */
Expand Down
8 changes: 4 additions & 4 deletions baselines/sharedworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4410,7 +4410,7 @@ declare var ReadableStreamDefaultReader: {

interface ReadableStreamGenericReader {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/closed) */
readonly closed: Promise<undefined>;
readonly closed: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/cancel) */
cancel(reason?: any): Promise<void>;
}
Expand Down Expand Up @@ -7608,7 +7608,7 @@ interface WebTransport {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebTransport/incomingUnidirectionalStreams) */
readonly incomingUnidirectionalStreams: ReadableStream;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebTransport/ready) */
readonly ready: Promise<undefined>;
readonly ready: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebTransport/close) */
close(closeInfo?: WebTransportCloseInfo): void;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebTransport/createBidirectionalStream) */
Expand Down Expand Up @@ -7920,11 +7920,11 @@ declare var WritableStreamDefaultController: {
*/
interface WritableStreamDefaultWriter<W = any> {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/closed) */
readonly closed: Promise<undefined>;
readonly closed: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/desiredSize) */
readonly desiredSize: number | null;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/ready) */
readonly ready: Promise<undefined>;
readonly ready: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/abort) */
abort(reason?: any): Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/close) */
Expand Down
12 changes: 6 additions & 6 deletions baselines/webworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ interface ExtendableMessageEventInit extends ExtendableEventInit {

interface FetchEventInit extends ExtendableEventInit {
clientId?: string;
handled?: Promise<undefined>;
handled?: Promise<void>;
preloadResponse?: Promise<any>;
replacesClientId?: string;
request: Request;
Expand Down Expand Up @@ -2675,7 +2675,7 @@ interface FetchEvent extends ExtendableEvent {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FetchEvent/clientId) */
readonly clientId: string;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FetchEvent/handled) */
readonly handled: Promise<undefined>;
readonly handled: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FetchEvent/preloadResponse) */
readonly preloadResponse: Promise<any>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FetchEvent/request) */
Expand Down Expand Up @@ -4851,7 +4851,7 @@ declare var ReadableStreamDefaultReader: {

interface ReadableStreamGenericReader {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/closed) */
readonly closed: Promise<undefined>;
readonly closed: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/cancel) */
cancel(reason?: any): Promise<void>;
}
Expand Down Expand Up @@ -8232,7 +8232,7 @@ interface WebTransport {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebTransport/incomingUnidirectionalStreams) */
readonly incomingUnidirectionalStreams: ReadableStream;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebTransport/ready) */
readonly ready: Promise<undefined>;
readonly ready: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebTransport/close) */
close(closeInfo?: WebTransportCloseInfo): void;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebTransport/createBidirectionalStream) */
Expand Down Expand Up @@ -8565,11 +8565,11 @@ declare var WritableStreamDefaultController: {
*/
interface WritableStreamDefaultWriter<W = any> {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/closed) */
readonly closed: Promise<undefined>;
readonly closed: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/desiredSize) */
readonly desiredSize: number | null;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/ready) */
readonly ready: Promise<undefined>;
readonly ready: Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/abort) */
abort(reason?: any): Promise<void>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/close) */
Expand Down
8 changes: 4 additions & 4 deletions src/build/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ export function emitWebIdl(
}
if (!obj.type)
throw new Error("Missing 'type' field in " + JSON.stringify(obj));
const type = convertDomTypeToTsTypeWorker(obj);
let type = convertDomTypeToTsTypeWorker(obj);
if (type === "Promise<undefined>") {
type = "Promise<void>";
}
return obj.nullable ? makeNullable(type) : type;
}

Expand All @@ -356,9 +359,6 @@ export function emitWebIdl(
if (type === "undefined") {
return "void";
}
if (type === "Promise<undefined>") {
return "Promise<void>";
}
if (type === "undefined | PromiseLike<undefined>") {
return "void | PromiseLike<void>";
}
Expand Down

0 comments on commit a6be967

Please sign in to comment.