Skip to content

Restore HTMLDocument constructor #1116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6044,6 +6044,12 @@ interface HTMLDocument extends Document {
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}

/** @deprecated */
declare var HTMLDocument: {
prototype: HTMLDocument;
new(): HTMLDocument;
};

interface HTMLElementEventMap extends ElementEventMap, DocumentAndElementEventHandlersEventMap, GlobalEventHandlersEventMap {
}

Expand Down Expand Up @@ -16000,7 +16006,6 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler

/** A window containing a DOM document; the document property points to the DOM document loaded in that window. */
interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandlers, WindowEventHandlers, WindowLocalStorage, WindowOrWorkerGlobalScope, WindowSessionStorage {
HTMLDocument: Document;
/** @deprecated This is a legacy alias of `navigator`. */
readonly clientInformation: Navigator;
/** Returns true if the window has been closed, false otherwise. */
Expand Down Expand Up @@ -17035,7 +17040,6 @@ declare var Image: {
declare var Option: {
new(text?: string, value?: string, defaultSelected?: boolean, selected?: boolean): HTMLOptionElement;
};
declare var HTMLDocument: Document;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, I’m guessing this was an incorrect attempt at back compat, right? So until now the HTMLDocument global value appeared to actually be an instance of an HTMLDocument?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite, the general pattern for a lot of DOM types is a var with an interface - as that's globally extendable and generally represents the runtimey flexiness of JS. This still represented the 'classlike' ness if you will, kind surprised that we didn't get a constructor though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s not what this says though... this var doesn’t have a constructor-ish type like the one added back by the PR, it has an instance-ish type. There’s no class-likeness here, which is why ant-design had an error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, this really should be declare var HTMLDocument: typeof Document; and then things should be okay.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I’d be ok with that approach, but personally don’t see a strong reason to remove HTMLDocument (or even to mark it deprecated)—I must be missing the original context.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTMLDocument is not defined as a separate interface anymore by the HTML spec and served as a legacy alias of Document. But since both Firefox and Chrome haven't implemented things as the spec says, maybe this also make sense as-is.

/** @deprecated This is a legacy alias of `navigator`. */
declare var clientInformation: Navigator;
/** Returns true if the window has been closed, false otherwise. */
Expand Down
9 changes: 0 additions & 9 deletions inputfiles/addedTypes.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@
"HTMLDocument": {
"name": "HTMLDocument",
"extends": "Document",
"noInterfaceObject": true,
"deprecated": "use Document",
"exposed": "Window"
},
Expand Down Expand Up @@ -366,14 +365,6 @@
}
}
},
"properties": {
"property": {
"HTMLDocument": {
"name": "HTMLDocument",
"type": "Document"
}
}
},
"overrideIndexSignatures": [
"[index: number]: Window"
],
Expand Down