-
Notifications
You must be signed in to change notification settings - Fork 421
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
Restore HTMLDocument constructor #1116
Conversation
Detected in microsoft/TypeScript#45540, where it breaks ant-design. `x instanceof HTMLDocument` no longer works. This is likely worth fixing before the release of 4.4.
Thanks for the PR! This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged. |
@saschanaz You are probably interested in this too. |
Perhaps a good chance to add a small test here: https://github.com/microsoft/TypeScript-DOM-lib-generator/tree/main/unittests/files |
@@ -17035,7 +17040,6 @@ declare var Image: { | |||
declare var Option: { | |||
new(text?: string, value?: string, defaultSelected?: boolean, selected?: boolean): HTMLOptionElement; | |||
}; | |||
declare var HTMLDocument: Document; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Green if it gets a test 👍🏻
Co-authored-by: Kagami Sascha Rosylight <saschanaz@outlook.com>
LGTM |
Sorry @saschanaz, you don't have access to merge: /unittests/files/htmldocument.ts. |
@orta could you add the directory to CODEOWNERS 👀 |
I can |
Detected in microsoft/TypeScript#45540, where it breaks ant-design.
x instanceof HTMLDocument
no longer works.This is likely worth fixing before the release of 4.4.
Fixes #1115