From f2a11bab3bc599d5113bafb61913c36bc2fc666f Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Mon, 30 Mar 2015 12:43:32 -0400 Subject: [PATCH] Add webcomponents.js 0.6.0 typings --- webcomponents.js/webcomponents.js-tests.ts | 39 ++++++++++++++++++ webcomponents.js/webcomponents.js.d.ts | 48 ++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 webcomponents.js/webcomponents.js-tests.ts create mode 100644 webcomponents.js/webcomponents.js.d.ts diff --git a/webcomponents.js/webcomponents.js-tests.ts b/webcomponents.js/webcomponents.js-tests.ts new file mode 100644 index 0000000000..316f9dd8e5 --- /dev/null +++ b/webcomponents.js/webcomponents.js-tests.ts @@ -0,0 +1,39 @@ +/// + +/* + * Custom Elements + */ +var fooProto = Object.create(HTMLElement.prototype, { + createdCallback() { + // `this` should be the created element + this.getElementsByTagName("a"); + } +}); + +document.registerElement("x-foo", { + prototype: fooProto +}); + +window.CustomElements.hasNative; +window.CustomElements.flags; +window.CustomElements.ready; +window.CustomElements.useNative; + +/* + * HTMLImports + */ + +window.HTMLImports.isIE; +window.HTMLImports.rootDocument.querySelectorAll("div"); +window.HTMLImports.useNative; +window.HTMLImports.whenReady(() => { + return window.HTMLImports.ready === true; +}); + +document.querySelectorAll(`link[type=${window.HTMLImports.IMPORT_LINK_TYPE}`); + +/* + * Web Components + */ +window.WebComponents.flags; + diff --git a/webcomponents.js/webcomponents.js.d.ts b/webcomponents.js/webcomponents.js.d.ts new file mode 100644 index 0000000000..43e85373fc --- /dev/null +++ b/webcomponents.js/webcomponents.js.d.ts @@ -0,0 +1,48 @@ +// Type definitions for webcomponents.js 0.6.0 +// Project: https://github.com/webcomponents/webcomponentsjs +// Definitions by: Adi Dahiya +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module webcomponents { + + export interface CustomElementInit { + prototype: HTMLElement; + extends?: string; + } + + export interface CustomElementsPolyfill { + hasNative: boolean; + flags: any; + ready: boolean; + useNative: boolean; + } + + export interface HTMLImportsPolyfill { + IMPORT_LINK_TYPE: string; + isIE: boolean; + flags: any; + ready: boolean; + rootDocument: Document; + useNative: boolean; + whenReady(callback: () => void): void; + } + + export interface Polyfill { + flags: any; + } + +} + +declare module "webcomponents.js" { + export = webcomponents; +} + +interface Document { + registerElement(name: string, prototype: webcomponents.CustomElementInit): void; +} + +interface Window { + CustomElements: webcomponents.CustomElementsPolyfill; + HTMLImports: webcomponents.HTMLImportsPolyfill; + WebComponents: webcomponents.Polyfill; +}