Skip to content

ShadowRoot should be a class, not an interface #27929

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

Closed
justinfagnani opened this issue Oct 16, 2018 · 4 comments
Closed

ShadowRoot should be a class, not an interface #27929

justinfagnani opened this issue Oct 16, 2018 · 4 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this

Comments

@justinfagnani
Copy link

TypeScript Version: 3.2.0-dev.201xxxxx

Search Terms: ShadowRoot

Code

const f = (o) => o instanceof ShadowRoot;

Expected behavior:
No errors

Actual behavior:
Error: 'ShadowRoot' only refers to a type, but is being used as a value here.

Playground Link: http://www.typescriptlang.org/play/#src=const%20f%20%3D%20(o)%20%3D%3E%20o%20instanceof%20ShadowRoot%3B

Related Issues: #10401

@weswigham weswigham added the Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript label Oct 16, 2018
@weswigham
Copy link
Member

PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

@weswigham weswigham added Help Wanted You can do this Bug A bug in TypeScript labels Oct 16, 2018
@weswigham
Copy link
Member

Note that the constructor needs to be private, since even though ShadowRoot can be instanceof'd and exists in value space, it cannot be constructed.

@justinfagnani
Copy link
Author

Note that the constructor needs to be private, since even though ShadowRoot can be instanceof'd and exists in value space, it cannot be constructed.

Isn't this the same as Element, HTMLElement, Attr, etc.? Those don't seem to have private constructors:

declare var HTMLElement: {
    prototype: HTMLElement;
    new(): HTMLElement;
};

Also, I don't understand why these are interfaces and not classes.

@RyanCavanaugh
Copy link
Member

Historically it was not possible to augment an existing class declaration with a subsequent interface declaration, so we wrote them as decomposed var/interface pairs so they could be subject to declaration merging so that people could write .d.ts compat files for experimental DOM features.

It was also historically not possible to have private constructors. You can only instanceof something that has a construct signature, so the new()s are there to allow for instanceof checks. Now that inheriting from elements is possible, making the DOM element constructors protected might make some sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants