mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
Add types for Templatizer to Polymer (#27823)
* Add types for Templatizer to Polymer Polymer was missing the typings for Templatizer, the behavior that provides helpers for working with template elements in Polymer components. This adds types for its public interface. * Add tests for new templatizer types * Fix modelForElement type to just be Polymer.Base The closure types here: https://github.com/Polymer/polymer/blob/1.x/src/lib/template/templatizer.html incorrectly suggest that modelForElement returns an `Object<Polymer.Base>`, but in fact it just returns `Polymer.Base`
This commit is contained in:
14
types/polymer/index.d.ts
vendored
14
types/polymer/index.d.ts
vendored
@@ -263,7 +263,7 @@ declare global {
|
||||
setAttribute(name: string, value: any):void;
|
||||
|
||||
removeAttribute(name: string):void;
|
||||
|
||||
|
||||
observeNodes(callback: (info: ObservedNodeInfo) => void): {};
|
||||
|
||||
unobserveNodes(observer: {}): void;
|
||||
@@ -340,6 +340,12 @@ declare global {
|
||||
whenLoaded(cb: Function): void;
|
||||
}
|
||||
|
||||
interface Templatizer {
|
||||
templatize(template: HTMLTemplateElement, mutableData?: boolean): void;
|
||||
stamp(model: {}): Base;
|
||||
modelForElement: (elem: HTMLElement) => Base;
|
||||
}
|
||||
|
||||
interface PolymerStatic {
|
||||
Settings: Settings;
|
||||
|
||||
@@ -351,12 +357,14 @@ declare global {
|
||||
|
||||
Class(prototype: Base | { new (): Base }): CustomElementConstructor;
|
||||
|
||||
RenderStatus: RenderStatus
|
||||
RenderStatus: RenderStatus;
|
||||
|
||||
ArraySplice: ArraySplice;
|
||||
|
||||
/** @deprecated */
|
||||
ImportStatus: ImportStatus
|
||||
ImportStatus: ImportStatus;
|
||||
|
||||
Templatizer: Templatizer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
Polymer({
|
||||
is: "my-element",
|
||||
|
||||
behaviors: [Polymer.Templatizer],
|
||||
|
||||
properties: {
|
||||
prop1: String,
|
||||
prop2: {
|
||||
@@ -24,6 +26,11 @@ Polymer({
|
||||
},
|
||||
|
||||
ready: function () {
|
||||
const template = Polymer.dom(this).querySelector('template');
|
||||
if (template) {
|
||||
this.templatize(template);
|
||||
const instance = this.stamp({item: {}});
|
||||
}
|
||||
this.textContent = 'My element!';
|
||||
this.$.name.textContent = this.name;
|
||||
this.serialize({});
|
||||
|
||||
Reference in New Issue
Block a user