Skip to content
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

Merged
merged 3 commits into from
Aug 23, 2021
Merged

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Aug 23, 2021

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

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.
@github-actions
Copy link
Contributor

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.

@sandersn
Copy link
Member Author

@saschanaz You are probably interested in this too.

@saschanaz
Copy link
Contributor

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;
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.

Copy link
Contributor

@orta orta left a 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>
@saschanaz
Copy link
Contributor

LGTM

@github-actions
Copy link
Contributor

Sorry @saschanaz, you don't have access to merge: /unittests/files/htmldocument.ts.

@saschanaz
Copy link
Contributor

Sorry @saschanaz, you don't have access to merge: /unittests/files/htmldocument.ts.

@orta could you add the directory to CODEOWNERS 👀

@orta
Copy link
Contributor

orta commented Aug 23, 2021

I can

@orta orta merged commit 4f4bb4a into main Aug 23, 2021
@sandersn sandersn deleted the restore-HTMLDocument-constructor branch August 23, 2021 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add HTMLDocument constructor back
4 participants