From d6d3c822785fd7dd2e5dd270cbb244847b1dbee5 Mon Sep 17 00:00:00 2001 From: Achim Weimert Date: Fri, 14 Sep 2018 10:55:34 +0100 Subject: [PATCH 1/3] Improve typings for legacy elements https://github.com/Polymer/polymer/issues/5350 --- interfaces.d.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/interfaces.d.ts b/interfaces.d.ts index 9ff30e0ac7..4fdbeb40b1 100644 --- a/interfaces.d.ts +++ b/interfaces.d.ts @@ -26,9 +26,21 @@ export interface PolymerInit { extends?: string; properties?: PolymerElementProperties; observers?: string[]; - template?: HTMLTemplateElement|string; + _template?: HTMLTemplateElement; hostAttributes?: {[key: string]: any}; listeners?: {[key: string]: string}; + behaviors?: PolymerInit | PolymerInit[]; + + // Lifecycle methods + registered?(): void; + created?(): void; + attached?(): void; + detached?(): void; + ready?(): void; + attributeChanged?(name: string, old?: string, value?: string); + + // Allow any other user-defined properties + [others: string]: any; } // Types from "externs/polymer-internal-shared-types.js" From bf02bd32da30de21549cea82bcde62d1aeecd57b Mon Sep 17 00:00:00 2001 From: Achim Weimert Date: Fri, 14 Sep 2018 11:17:30 +0100 Subject: [PATCH 2/3] Add specific type for behaviors --- interfaces.d.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/interfaces.d.ts b/interfaces.d.ts index 4fdbeb40b1..41579bdb33 100644 --- a/interfaces.d.ts +++ b/interfaces.d.ts @@ -29,7 +29,7 @@ export interface PolymerInit { _template?: HTMLTemplateElement; hostAttributes?: {[key: string]: any}; listeners?: {[key: string]: string}; - behaviors?: PolymerInit | PolymerInit[]; + behaviors?: BehaviorInit | BehaviorInit[]; // Lifecycle methods registered?(): void; @@ -43,6 +43,11 @@ export interface PolymerInit { [others: string]: any; } +export type BehaviorInit = Pick< + PolymerInit, + Exclude +>; + // Types from "externs/polymer-internal-shared-types.js" export interface StampedTemplate extends DocumentFragment { From 239e99a59a8cecfc76342cac0780a5de63688d4d Mon Sep 17 00:00:00 2001 From: Achim Weimert Date: Fri, 14 Sep 2018 13:34:33 +0100 Subject: [PATCH 3/3] Add missing return type to attributeChanged --- interfaces.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces.d.ts b/interfaces.d.ts index 41579bdb33..79fb54cde4 100644 --- a/interfaces.d.ts +++ b/interfaces.d.ts @@ -37,7 +37,7 @@ export interface PolymerInit { attached?(): void; detached?(): void; ready?(): void; - attributeChanged?(name: string, old?: string, value?: string); + attributeChanged?(name: string, old?: string, value?: string): void; // Allow any other user-defined properties [others: string]: any;