Skip to content

Commit ffc35e4

Browse files
committed
Update various Polymer annotations to constrain generated types.
1 parent 6a0d214 commit ffc35e4

22 files changed

+80
-80
lines changed

lib/elements/array-selector.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211

212212
/**
213213
* Clears the selection state.
214-
*
214+
* @returns {void}
215215
*/
216216
clearSelection() {
217217
// Unbind previous selection

lib/elements/dom-bind.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,19 @@
6161
this.__children = null;
6262
}
6363

64-
// assumes only one observed attribute
64+
/** @returns {void} */
6565
attributeChangedCallback() {
66+
// assumes only one observed attribute
6667
this.mutableData = true;
6768
}
6869

70+
/** @returns {void} */
6971
connectedCallback() {
7072
this.style.display = 'none';
7173
this.render();
7274
}
7375

76+
/** @returns {void} */
7477
disconnectedCallback() {
7578
this.__removeChildren();
7679
}

lib/elements/dom-module.html

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474
return null;
7575
}
7676

77+
/**
78+
* @param {string} name
79+
* @returns {void}
80+
*/
7781
attributeChangedCallback(name, old, value) {
7882
if (old !== value) {
7983
this.register();

lib/legacy/legacy-element-mixin.html

+15-14
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
* @param {string} name Name of attribute.
130130
* @param {?string} old Old value of attribute.
131131
* @param {?string} value Current value of attribute.
132+
* @returns {void}
132133
* @override
133134
*/
134135
attributeChangedCallback(name, old, value) {
@@ -484,7 +485,7 @@
484485
* any `<content>` elements are replaced with the list of nodes distributed
485486
* to the `<content>`, the result of its `getDistributedNodes` method.
486487
* @this {Element}
487-
* @return {Array<Node>} List of effective child nodes.
488+
* @return {!Array<!Node>} List of effective child nodes.
488489
*/
489490
getEffectiveChildNodes() {
490491
const domApi = /** @type {Polymer.DomApi} */(Polymer.dom(this));
@@ -497,7 +498,7 @@
497498
* children that are insertion points.
498499
* @param {string} selector Selector to run.
499500
* @this {Element}
500-
* @return {Array<Node>} List of distributed elements that match selector.
501+
* @return {!Array<!Node>} List of distributed elements that match selector.
501502
*/
502503
queryDistributedElements(selector) {
503504
const domApi = /** @type {Polymer.DomApi} */(Polymer.dom(this));
@@ -510,7 +511,7 @@
510511
* any `<content>` elements are replaced with the list of elements
511512
* distributed to the `<content>`.
512513
*
513-
* @return {Array<Node>} List of effective children.
514+
* @return {!Array<!Node>} List of effective children.
514515
*/
515516
getEffectiveChildren() {
516517
let list = this.getEffectiveChildNodes();
@@ -554,7 +555,7 @@
554555
* match `selector`. These can be dom child nodes or elements distributed
555556
* to children that are insertion points.
556557
* @param {string} selector Selector to run.
557-
* @return {Array<Node>} List of effective child nodes that match selector.
558+
* @return {!Array<!Node>} List of effective child nodes that match selector.
558559
*/
559560
queryAllEffectiveChildren(selector) {
560561
return this.queryDistributedElements(selector);
@@ -568,7 +569,7 @@
568569
*
569570
* @param {string=} slctr CSS selector to choose the desired
570571
* `<slot>`. Defaults to `content`.
571-
* @return {Array<Node>} List of distributed nodes for the `<slot>`.
572+
* @return {!Array<!Node>} List of distributed nodes for the `<slot>`.
572573
*/
573574
getContentChildNodes(slctr) {
574575
let content = this.root.querySelector(slctr || 'slot');
@@ -586,12 +587,12 @@
586587
*
587588
* @param {string=} slctr CSS selector to choose the desired
588589
* `<content>`. Defaults to `content`.
589-
* @return {Array<HTMLElement>} List of distributed nodes for the
590+
* @return {!Array<!HTMLElement>} List of distributed nodes for the
590591
* `<slot>`.
591592
* @suppress {invalidCasts}
592593
*/
593594
getContentChildren(slctr) {
594-
let children = /** @type {Array<HTMLElement>} */(this.getContentChildNodes(slctr).filter(function(n) {
595+
let children = /** @type {!Array<!HTMLElement>} */(this.getContentChildNodes(slctr).filter(function(n) {
595596
return (n.nodeType === Node.ELEMENT_NODE);
596597
}));
597598
return children;
@@ -649,7 +650,7 @@
649650
* }
650651
*
651652
* @param {string} jobName String to identify the debounce job.
652-
* @param {function()} callback Function that is called (with `this`
653+
* @param {function():void} callback Function that is called (with `this`
653654
* context) when the wait time elapses.
654655
* @param {number} wait Optional wait time in milliseconds (ms) after the
655656
* last signal that must elapse before invoking `callback`
@@ -713,7 +714,7 @@
713714
* By default (if no waitTime is specified), async callbacks are run at
714715
* microtask timing, which will occur before paint.
715716
*
716-
* @param {Function} callback The callback function to run, bound to `this`.
717+
* @param {!Function} callback The callback function to run, bound to `this`.
717718
* @param {number=} waitTime Time to wait before calling the
718719
* `callback`. If unspecified or 0, the callback will be run at microtask
719720
* timing (before paint).
@@ -769,13 +770,13 @@
769770
* element will contain the imported document contents.
770771
*
771772
* @param {string} href URL to document to load.
772-
* @param {Function} onload Callback to notify when an import successfully
773+
* @param {!Function=} onload Callback to notify when an import successfully
773774
* loaded.
774-
* @param {Function} onerror Callback to notify when an import
775+
* @param {!Function=} onerror Callback to notify when an import
775776
* unsuccessfully loaded.
776-
* @param {boolean} optAsync True if the import should be loaded `async`.
777+
* @param {boolean=} optAsync True if the import should be loaded `async`.
777778
* Defaults to `false`.
778-
* @return {HTMLLinkElement} The link element for the URL to be loaded.
779+
* @return {!HTMLLinkElement} The link element for the URL to be loaded.
779780
*/
780781
importHref(href, onload, onerror, optAsync) { // eslint-disable-line no-unused-vars
781782
let loadFn = onload ? onload.bind(this) : null;
@@ -788,7 +789,7 @@
788789
* prefixed.
789790
*
790791
* @param {string} selector Selector to test.
791-
* @param {Element=} node Element to test the selector against.
792+
* @param {!Element=} node Element to test the selector against.
792793
* @return {boolean} Whether the element matches the selector.
793794
*/
794795
elementMatches(selector, node) {

lib/legacy/polymer-fn.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* @function Polymer
3030
* @param {!PolymerInit} info Object containing Polymer metadata and functions
3131
* to become class methods.
32-
* @return {!HTMLElement} Generated class
32+
* @return {function(new: HTMLElement)} Generated class
3333
* @suppress {duplicate, invalidCasts, checkTypes}
3434
*/
3535
window.Polymer._polymerFn = function(info) {

lib/legacy/polymer.dom.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@
157157
}
158158

159159
/**
160-
* @return {Array} Returns a flattened list of all child nodes and nodes assigned
161-
* to child slots.
160+
* @return {!Array<!Node>} Returns a flattened list of all child nodes and
161+
* nodes assigned to child slots.
162162
*/
163163
getEffectiveChildNodes() {
164164
return Polymer.FlattenedNodesObserver.getFlattenedNodes(this.node);

lib/utils/async.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
*
6969
* @memberof Polymer.Async.timeOut
7070
* @param {number} delay Time to wait before calling callbacks in ms
71-
* @return {AsyncInterface} An async timeout interface
71+
* @return {!AsyncInterface} An async timeout interface
7272
*/
7373
after(delay) {
7474
return {
@@ -81,7 +81,7 @@
8181
*
8282
* @function
8383
* @memberof Polymer.Async.timeOut
84-
* @param {Function} fn Callback to run
84+
* @param {!Function} fn Callback to run
8585
* @return {number} Handle used for canceling task
8686
*/
8787
run: window.setTimeout.bind(window),
@@ -109,7 +109,7 @@
109109
*
110110
* @function
111111
* @memberof Polymer.Async.animationFrame
112-
* @param {Function} fn Callback to run
112+
* @param {!Function} fn Callback to run
113113
* @return {number} Handle used for canceling task
114114
*/
115115
run: window.requestAnimationFrame.bind(window),
@@ -137,7 +137,7 @@
137137
* Enqueues a function called at `requestIdleCallback` timing.
138138
*
139139
* @memberof Polymer.Async.idlePeriod
140-
* @param {function(IdleDeadline)} fn Callback to run
140+
* @param {function(!IdleDeadline):void} fn Callback to run
141141
* @return {number} Handle used for canceling task
142142
*/
143143
run(fn) {
@@ -179,7 +179,7 @@
179179
* Enqueues a function called at microtask timing.
180180
*
181181
* @memberof Polymer.Async.microTask
182-
* @param {Function} callback Callback to run
182+
* @param {!Function=} callback Callback to run
183183
* @return {number} Handle used for canceling task
184184
*/
185185
run(callback) {

lib/utils/flush.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Adds a `Polymer.Debouncer` to a list of globally flushable tasks.
1919
*
2020
* @memberof Polymer
21-
* @param {Polymer.Debouncer} debouncer Debouncer to enqueue
21+
* @param {!Polymer.Debouncer} debouncer Debouncer to enqueue
2222
* @return {void}
2323
*/
2424
Polymer.enqueueDebouncer = function(debouncer) {

lib/utils/gestures.html

+10-10
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,9 @@
427427
* Adds an event listener to a node for the given gesture type.
428428
*
429429
* @memberof Polymer.Gestures
430-
* @param {Node} node Node to add listener on
430+
* @param {!Node} node Node to add listener on
431431
* @param {string} evType Gesture type: `down`, `up`, `track`, or `tap`
432-
* @param {Function} handler Event listener function to call
432+
* @param {!Function} handler Event listener function to call
433433
* @return {boolean} Returns true if a gesture event listener was added.
434434
* @this {Gestures}
435435
*/
@@ -445,9 +445,9 @@
445445
* Removes an event listener from a node for the given gesture type.
446446
*
447447
* @memberof Polymer.Gestures
448-
* @param {Node} node Node to remove listener from
448+
* @param {!Node} node Node to remove listener from
449449
* @param {string} evType Gesture type: `down`, `up`, `track`, or `tap`
450-
* @param {Function} handler Event listener function previously passed to
450+
* @param {!Function} handler Event listener function previously passed to
451451
* `addListener`.
452452
* @return {boolean} Returns true if a gesture event listener was removed.
453453
* @this {Gestures}
@@ -464,7 +464,7 @@
464464
* automate the event listeners for the native events
465465
*
466466
* @private
467-
* @param {HTMLElement} node Node on which to add the event.
467+
* @param {!HTMLElement} node Node on which to add the event.
468468
* @param {string} evType Event type to add.
469469
* @param {function(Event?)} handler Event handler function.
470470
* @return {void}
@@ -504,7 +504,7 @@
504504
* automate event listener removal for native events
505505
*
506506
* @private
507-
* @param {HTMLElement} node Node on which to remove the event.
507+
* @param {!HTMLElement} node Node on which to remove the event.
508508
* @param {string} evType Event type to remove.
509509
* @param {function(Event?)} handler Event handler function.
510510
* @return {void}
@@ -536,7 +536,7 @@
536536
* gesture event types.
537537
*
538538
* @memberof Polymer.Gestures
539-
* @param {GestureRecognizer} recog Gesture recognizer descriptor
539+
* @param {!GestureRecognizer} recog Gesture recognizer descriptor
540540
* @return {void}
541541
* @this {Gestures}
542542
*/
@@ -573,7 +573,7 @@
573573
* adding event listeners.
574574
*
575575
* @memberof Polymer.Gestures
576-
* @param {Element} node Node to set touch action setting on
576+
* @param {!Element} node Node to set touch action setting on
577577
* @param {string} value Touch action value
578578
* @return {void}
579579
*/
@@ -588,9 +588,9 @@
588588
* Dispatches an event on the `target` element of `type` with the given
589589
* `detail`.
590590
* @private
591-
* @param {EventTarget} target The element on which to fire an event.
591+
* @param {!EventTarget} target The element on which to fire an event.
592592
* @param {string} type The type of event to fire.
593-
* @param {Object=} detail The detail object to populate on the event.
593+
* @param {!Object=} detail The detail object to populate on the event.
594594
* @return {void}
595595
*/
596596
_fire: function(target, type, detail) {

lib/utils/import-href.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
*
3737
* @memberof Polymer
3838
* @param {string} href URL to document to load.
39-
* @param {Function=} onload Callback to notify when an import successfully
39+
* @param {!Function=} onload Callback to notify when an import successfully
4040
* loaded.
41-
* @param {Function=} onerror Callback to notify when an import
41+
* @param {!Function=} onerror Callback to notify when an import
4242
* unsuccessfully loaded.
4343
* @param {boolean=} optAsync True if the import should be loaded `async`.
4444
* Defaults to `false`.
45-
* @return {HTMLLinkElement} The link element for the URL to be loaded.
45+
* @return {!HTMLLinkElement} The link element for the URL to be loaded.
4646
*/
4747
Polymer.importHref = function(href, onload, onerror, optAsync) {
4848
let link = /** @type {HTMLLinkElement} */

lib/utils/settings.html

+1-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
(function() {
1717
'use strict';
1818

19-
/**
20-
* Legacy settings.
21-
* @namespace
22-
* @memberof Polymer
23-
*/
2419
const settings = Polymer.Settings || {};
2520
settings.useShadow = !(window.ShadyDOM);
2621
settings.useNativeCSSProperties =
@@ -32,6 +27,7 @@
3227
* Sets the global, legacy settings.
3328
*
3429
* @deprecated
30+
* @namespace
3531
* @memberof Polymer
3632
*/
3733
Polymer.Settings = settings;

types/lib/elements/array-selector.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ declare namespace Polymer {
6868
/**
6969
* Clears the selection state.
7070
*/
71-
clearSelection(): any;
71+
clearSelection(): void;
7272

7373
/**
7474
* Returns whether the item is currently selected.

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

+3-7
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,9 @@ declare namespace Polymer {
3030
Polymer.OptionalMutableData(
3131
Polymer.GestureEventListeners(
3232
Polymer.Element))) {
33-
34-
/**
35-
* assumes only one observed attribute
36-
*/
37-
attributeChangedCallback(): any;
38-
connectedCallback(): any;
39-
disconnectedCallback(): any;
33+
attributeChangedCallback(): void;
34+
connectedCallback(): void;
35+
disconnectedCallback(): void;
4036

4137
/**
4238
* Forces the element to render its content. This is typically only

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ declare namespace Polymer {
3333
* let img = customElements.get('dom-module').import('foo', 'img');
3434
*/
3535
class DomModule extends HTMLElement {
36-
attributeChangedCallback(name: any, old: any, value: any): any;
36+
attributeChangedCallback(name: string, old: any, value: any): void;
3737

3838
/**
3939
* Registers the dom-module at a given id. This method should only be called

0 commit comments

Comments
 (0)