-
Notifications
You must be signed in to change notification settings - Fork 12.8k
ShadowRoot interface and attachShadow function are missing from type definitions #10401
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
Comments
The Shadow DOM is still not implemented in many browsers. Interfaces are open ended, so these can be declared yourself. |
@Fairmill here's what I ended up using in my project: (based on https://www.w3.org/TR/shadow-dom/) // shadow-dom.d.ts
declare global {
type ShadowRootMode = "open" | "closed";
interface ShadowRootInit {
mode: ShadowRootMode;
delegatesFocus?: boolean;
}
interface CaretPosition {
offsetNode: Node;
offset: number;
getClientRect(): ClientRect;
}
interface DocumentOrShadowRoot {
getSelection(): Selection | null;
elementFromPoint(x: number, y: number): Element | null;
elementsFromPoint(x: number, y: number): NodeListOf<Element>;
caretPositionFromPoint(x: number, y: number): CaretPosition | null;
activeElement: Element | null;
styleSheets: StyleSheetList;
}
interface ShadowRoot extends DocumentFragment, DocumentOrShadowRoot {
host: HTMLElement;
mode: ShadowRootMode;
}
interface Document extends DocumentOrShadowRoot {}
interface AssignedNodesOptions {
flatten: boolean = false;
}
interface HTMLSlotElement extends HTMLElement {
name: string;
assignedNodes(options?: AssignedNodesOptions): NodeList;
}
interface Element {
attachShadow(shadowRootInitDict: ShadowRootInit): ShadowRoot;
assignedSlot: HTMLSlotElement | null;
slot: string;
shadowRoot: ShadowRoot | null;
}
}
export { } |
Could this be revisited? V1 seems a lot better on caniuse - http://caniuse.com/#feat=shadowdomv1 |
Please consider reopening this issue -- ShadowDOM V1 support is now imminent in FireFox and has already landed in Chrome and Safari: |
I agree. This issue is at a point where it should be revisited soon. |
@klebba I am not part of the TypeScript team. |
And the issue is still open. |
This should be fixed in |
@mhegazy : It looks like When I write ... let h = this.getRootNode().host; ... I get a TS2339 compiler error: "Property 'host' not available for type 'Node'." |
me too, the version of ts is typescript@3.4.5. Property 'createShadowRoot' does not exist on type 'HTMLElement'。how to solve it? |
In the meantime I got a great explanation why this doesn't work the way we all expect: MDN already updated their docs to clarify the situation. |
Until TypeScript corrects their lib, we'll have to declare global {
interface Node {
getRootNode(options?: GetRootNodeOptions): Node|ShadowRoot;
}
} |
Actually, |
TypeScript Version: 1.8.0 / nightly (2.0.0-dev.201xxxxx)
Code
Expected behavior:
ShadowRoot is recognized as a valid type, and the HTMLElement's attachShadow function is recognized as per the DOM standard.
Actual behavior:
Neither ShadorRoot nor the attachShadow functions are recognized.
The text was updated successfully, but these errors were encountered: