Skip to content

Commit 1eb9af8

Browse files
committed
Fix type declarations inadvertedtly referencing Polymer.Element.
Polymer defines its own `Element` class, shadowing the standard global `Element` class. This means that references to `Element` within the `Polymer` namespace inadvertently reference `Polymer.Element`. Here we define an alias of the global `Element`, so that we can reference it from declarations within the `Polymer` namespace. See microsoft/TypeScript#983 for general discussion of this shadowing problem in TypeScript. Fixes #5074
1 parent 86399df commit 1eb9af8

10 files changed

+37
-24
lines changed

gen-tsd.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
]
1818
},
1919
"renameTypes": {
20-
"Polymer_PropertyEffects": "Polymer.PropertyEffects"
20+
"Polymer_PropertyEffects": "Polymer.PropertyEffects",
21+
"Element": "_Element"
2122
}
2223
}

types/extra-types.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,15 @@ interface IdleDeadline {
133133
didTimeout: boolean;
134134
timeRemaining(): number;
135135
}
136+
137+
/**
138+
* Polymer defines its own `Element` class, shadowing the standard global
139+
* `Element` class. This means that references to `Element` within the `Polymer`
140+
* namespace inadvertently reference `Polymer.Element`. Here we define an alias
141+
* of the global `Element`, so that we can reference it from declarations within
142+
* the `Polymer` namespace.
143+
*
144+
* See https://github.com/Microsoft/TypeScript/issues/983 for general discussion
145+
* of this shadowing problem in TypeScript.
146+
*/
147+
type _Element = Element;

types/lib/elements/dom-module.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ declare namespace Polymer {
4444
* @returns Returns the element which matches `selector` in the
4545
* module registered at the specified `id`.
4646
*/
47-
static import(id: string, selector?: string): Element|null;
47+
static import(id: string, selector?: string): _Element|null;
4848

4949
/**
5050
* @param name Name of attribute.

types/lib/legacy/legacy-element-mixin.d.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ declare namespace Polymer {
187187
* @param attribute Attribute name to serialize to.
188188
* @param node Element to set attribute to.
189189
*/
190-
serializeValueToAttribute(value: any, attribute: string, node: Element|null): void;
190+
serializeValueToAttribute(value: any, attribute: string, node: _Element|null): void;
191191

192192
/**
193193
* Copies own properties (including accessor descriptors) from a source
@@ -258,7 +258,7 @@ declare namespace Polymer {
258258
* @param eventName Name of event to listen for.
259259
* @param methodName Name of handler method on `this` to call.
260260
*/
261-
listen(node: Element|null, eventName: string, methodName: string): void;
261+
listen(node: _Element|null, eventName: string, methodName: string): void;
262262

263263
/**
264264
* Convenience method to remove an event listener from a given element,
@@ -269,7 +269,7 @@ declare namespace Polymer {
269269
* @param methodName Name of handler method on `this` to not call
270270
* anymore.
271271
*/
272-
unlisten(node: Element|null, eventName: string, methodName: string): void;
272+
unlisten(node: _Element|null, eventName: string, methodName: string): void;
273273

274274
/**
275275
* Override scrolling behavior to all direction, one direction, or none.
@@ -285,7 +285,7 @@ declare namespace Polymer {
285285
* @param node Element to apply scroll direction setting.
286286
* Defaults to `this`.
287287
*/
288-
setScrollDirection(direction?: string, node?: Element|null): void;
288+
setScrollDirection(direction?: string, node?: _Element|null): void;
289289

290290
/**
291291
* Convenience method to run `querySelector` on this local DOM scope.
@@ -295,7 +295,7 @@ declare namespace Polymer {
295295
* @param slctr Selector to run on this local DOM scope
296296
* @returns Element found by the selector, or null if not found.
297297
*/
298-
$$(slctr: string): Element|null;
298+
$$(slctr: string): _Element|null;
299299

300300
/**
301301
* Force this element to distribute its children to its local dom.
@@ -405,7 +405,7 @@ declare namespace Polymer {
405405
* @param node The element to be checked.
406406
* @returns true if node is in this element's local DOM tree.
407407
*/
408-
isLocalDescendant(node: Element): boolean;
408+
isLocalDescendant(node: _Element): boolean;
409409

410410
/**
411411
* No-op for backwards compatibility. This should now be handled by
@@ -503,7 +503,7 @@ declare namespace Polymer {
503503
* instance.
504504
* @returns Newly created and configured element.
505505
*/
506-
create(tag: string, props?: object|null): Element;
506+
create(tag: string, props?: object|null): _Element;
507507

508508
/**
509509
* Convenience method for importing an HTML document imperatively.
@@ -532,7 +532,7 @@ declare namespace Polymer {
532532
* @param node Element to test the selector against.
533533
* @returns Whether the element matches the selector.
534534
*/
535-
elementMatches(selector: string, node?: Element): boolean;
535+
elementMatches(selector: string, node?: _Element): boolean;
536536

537537
/**
538538
* Toggles an HTML attribute on or off.
@@ -542,7 +542,7 @@ declare namespace Polymer {
542542
* When unspecified, the state of the attribute will be reversed.
543543
* @param node Node to target. Defaults to `this`.
544544
*/
545-
toggleAttribute(name: string, bool?: boolean, node?: Element|null): void;
545+
toggleAttribute(name: string, bool?: boolean, node?: _Element|null): void;
546546

547547
/**
548548
* Toggles a CSS class on or off.
@@ -552,7 +552,7 @@ declare namespace Polymer {
552552
* When unspecified, the state of the class will be reversed.
553553
* @param node Node to target. Defaults to `this`.
554554
*/
555-
toggleClass(name: string, bool?: boolean, node?: Element|null): void;
555+
toggleClass(name: string, bool?: boolean, node?: _Element|null): void;
556556

557557
/**
558558
* Cross-platform helper for setting an element's CSS `transform` property.
@@ -561,7 +561,7 @@ declare namespace Polymer {
561561
* @param node Element to apply the transform to.
562562
* Defaults to `this`
563563
*/
564-
transform(transformText: string, node?: Element|null): void;
564+
transform(transformText: string, node?: _Element|null): void;
565565

566566
/**
567567
* Cross-platform helper for setting an element's CSS `translate3d`
@@ -573,7 +573,7 @@ declare namespace Polymer {
573573
* @param node Element to apply the transform to.
574574
* Defaults to `this`.
575575
*/
576-
translate3d(x: number, y: number, z: number, node?: Element|null): void;
576+
translate3d(x: number, y: number, z: number, node?: _Element|null): void;
577577

578578
/**
579579
* Removes an item from an array, if it exists.

types/lib/legacy/polymer.dom.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ declare namespace Polymer {
5555
* of this element changes
5656
* @returns Observer instance
5757
*/
58-
observeNodes(callback: (p0: Element, p1: {target: Element, addedNodes: Element[], removedNodes: Element[]}) => void): Polymer.FlattenedNodesObserver;
58+
observeNodes(callback: (p0: _Element, p1: {target: _Element, addedNodes: _Element[], removedNodes: _Element[]}) => void): Polymer.FlattenedNodesObserver;
5959

6060
/**
6161
* Disconnects an observer previously created via `observeNodes`
@@ -137,8 +137,8 @@ declare namespace Polymer {
137137
replaceChild(oldChild: Node, newChild: Node): Node;
138138
setAttribute(name: string, value: string): void;
139139
removeAttribute(name: string): void;
140-
querySelector(selector: string): Element|null;
141-
querySelectorAll(selector: string): NodeListOf<Element>;
140+
querySelector(selector: string): _Element|null;
141+
querySelectorAll(selector: string): NodeListOf<_Element>;
142142
}
143143

144144

types/lib/mixins/element-mixin.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ declare namespace Polymer {
138138
rootPath: string;
139139
importPath: string;
140140
root: StampedTemplate|HTMLElement|ShadowRoot|null;
141-
$: {[key: string]: Element};
141+
$: {[key: string]: _Element};
142142

143143
/**
144144
* Stamps the element template.

types/lib/mixins/properties-changed.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ declare namespace Polymer {
257257
* @param value Value to serialize.
258258
* @param attribute Attribute name to serialize to.
259259
*/
260-
_valueToNodeAttribute(node: Element|null, value: any, attribute: string): void;
260+
_valueToNodeAttribute(node: _Element|null, value: any, attribute: string): void;
261261

262262
/**
263263
* Converts a typed JavaScript value to a string.

types/lib/mixins/property-effects.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ declare namespace Polymer {
9696
* @returns `true` if the visited node added node-specific
9797
* metadata to `nodeInfo`
9898
*/
99-
_parseTemplateNodeAttribute(node: Element|null, templateInfo: TemplateInfo|null, nodeInfo: NodeInfo|null, name: string, value: string): boolean;
99+
_parseTemplateNodeAttribute(node: _Element|null, templateInfo: TemplateInfo|null, nodeInfo: NodeInfo|null, name: string, value: string): boolean;
100100

101101
/**
102102
* Ensures an accessor exists for the specified property, and adds

types/lib/mixins/template-stamp.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ declare namespace Polymer {
164164
* @returns `true` if the visited node added node-specific
165165
* metadata to `nodeInfo`
166166
*/
167-
_parseTemplateNodeAttributes(node: Element|null, templateInfo: TemplateInfo|null, nodeInfo: NodeInfo|null): boolean;
167+
_parseTemplateNodeAttributes(node: _Element|null, templateInfo: TemplateInfo|null, nodeInfo: NodeInfo|null): boolean;
168168

169169
/**
170170
* Parses a single template node attribute and adds node metadata to
@@ -181,7 +181,7 @@ declare namespace Polymer {
181181
* @returns `true` if the visited node added node-specific
182182
* metadata to `nodeInfo`
183183
*/
184-
_parseTemplateNodeAttribute(node: Element|null, templateInfo: TemplateInfo, nodeInfo: NodeInfo, name: string, value: string): boolean;
184+
_parseTemplateNodeAttribute(node: _Element|null, templateInfo: TemplateInfo, nodeInfo: NodeInfo, name: string, value: string): boolean;
185185

186186
/**
187187
* Returns the `content` document fragment for a given template.

types/lib/utils/gestures.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ declare namespace Polymer {
3434
* @returns Returns the deepest shadowRoot inclusive element
3535
* found at the screen position given.
3636
*/
37-
function deepTargetFind(x: number, y: number): Element|null;
37+
function deepTargetFind(x: number, y: number): _Element|null;
3838

3939

4040
/**
@@ -66,7 +66,7 @@ declare namespace Polymer {
6666
* This value is checked on first move, thus it should be called prior to
6767
* adding event listeners.
6868
*/
69-
function setTouchAction(node: Element, value: string): void;
69+
function setTouchAction(node: _Element, value: string): void;
7070

7171

7272
/**

0 commit comments

Comments
 (0)