mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 15:00:26 +00:00
[polymer] Expose polymer.PolymerElement type in Polymer 1.x typings. (#31407)
* [polymer] Expose polymer.PolymerElement type in Polymer 1.x typings.
This is a type that represents a Polymer element after its class has been constructed by the Polymer() function.
Previously people would construct such a type by doing:
```typescript
interface MyElement extends HTMLElement, polymer.Base {}
```
But after TypeScript 3.0, the type of `HTMLElement#toggleAttribute` is different than the type of `polymer.Base#toggleAttribute`, which makes it an error to declare the MyElement type as above.
Unfortunately, we can't change the type of toggleElement on polymer.Base, so instead we introduce a new type polymer.PolymerElement that already extends `HTMLElement`.
So after this change, a Polymer 1.0 user can write their type as:
```typescript
interface MyElement extends polymer.PolymerElement {}
```
* Fix a couple of small issues.
This commit is contained in:
committed by
Nathan Shively-Sanders
parent
99458d49bf
commit
4b658ce8a6
Vendored
+20
-10
@@ -20,19 +20,17 @@ declare global {
|
||||
observer?: string;
|
||||
}
|
||||
|
||||
interface Base {
|
||||
/** Need to allow all properties for callback methods. */
|
||||
[prop: string]: any;
|
||||
|
||||
interface CommonBase {
|
||||
/* polymer-micro */
|
||||
|
||||
// Attributes
|
||||
|
||||
hostAttributes?: {[name:string]:any};
|
||||
hostAttributes?: {[name: string]: any};
|
||||
|
||||
reflectPropertiesToAttribute?(name: string): void;
|
||||
|
||||
serializeValueToAttribute?(value: any, attribute: string, node?: Element): void;
|
||||
serializeValueToAttribute?
|
||||
(value: any, attribute: string, node?: Element): void;
|
||||
|
||||
deserialize?(value: string, type: NumberConstructor): number;
|
||||
deserialize?(value: string, type: BooleanConstructor): boolean;
|
||||
@@ -120,7 +118,8 @@ declare global {
|
||||
|
||||
notifyPath?(path: string, value: any, fromAbove: any): void;
|
||||
|
||||
set?<Value>(path: string|(string|number)[], value: Value, root?: Object): void;
|
||||
set?<Value>(path: string|(string|number)[], value: Value, root?: Object):
|
||||
void;
|
||||
|
||||
get?(path: string|(string|number)[], root?: Object): any;
|
||||
|
||||
@@ -139,7 +138,8 @@ declare global {
|
||||
|
||||
unshift?(path: string, ...item: any[]): number;
|
||||
|
||||
notifySplices?(path: string, splices: ReadonlyArray<polymer.PolymerSplice>): void;
|
||||
notifySplices?
|
||||
(path: string, splices: ReadonlyArray<polymer.PolymerSplice>): void;
|
||||
|
||||
// ResolveUrl
|
||||
|
||||
@@ -155,8 +155,6 @@ declare global {
|
||||
|
||||
toggleClass?(name: string, bool?: boolean, node?: HTMLElement): void;
|
||||
|
||||
toggleAttribute?(name: string, bool?: boolean, node?: HTMLElement): void;
|
||||
|
||||
classFollows?(name: string, toElement: HTMLElement, fromElement: HTMLElement): void;
|
||||
|
||||
attributeFollows?(name: string, toElement: HTMLElement, fromElement: HTMLElement): void;
|
||||
@@ -220,7 +218,19 @@ declare global {
|
||||
detached?(): void;
|
||||
|
||||
attributeChanged?(name: string, oldValue: any, newValue: any): void;
|
||||
}
|
||||
|
||||
// This is the type of a Polymer element after it has gone through the
|
||||
// Polymer() function.
|
||||
interface PolymerElement extends CommonBase, HTMLElement {}
|
||||
|
||||
interface Base extends CommonBase {
|
||||
/** Need to allow all properties for callback methods. */
|
||||
[prop: string]: any;
|
||||
|
||||
// Has to live on Base because it is incompatible with
|
||||
// HTMLElement#toggleAttribute
|
||||
toggleAttribute?(name: string, bool?: boolean, node?: HTMLElement): void;
|
||||
}
|
||||
|
||||
interface DomApiStatic {
|
||||
|
||||
@@ -51,14 +51,14 @@ Polymer({
|
||||
}
|
||||
});
|
||||
|
||||
var MyElement = Polymer.Class(<polymer.Base>{
|
||||
var MyElement = Polymer.Class({
|
||||
is: 'my-element',
|
||||
|
||||
created: function () {
|
||||
this.textContent = 'My element!';
|
||||
}
|
||||
|
||||
});
|
||||
} as polymer.Base);
|
||||
|
||||
document.registerElement('my-element', MyElement);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user