Skip to content

Commit

Permalink
add void return type annotations (#5000)
Browse files Browse the repository at this point in the history
* add void return type annotations

* define dom api prototype members as functions

* fix renderstatus optional parameters

* fix style-gatherer types

* fix templatize types

* fix event listener remove types

* use generics in mixinBehaviors

* update gen-typescript-declarations

* add memberof annotation to domapi methods

* add domapi types

* move dom methods to correct place

* use parameterless NodeList for the dom API
  • Loading branch information
43081j authored and dfreedm committed Jan 9, 2018
1 parent 60e7121 commit 589684a
Show file tree
Hide file tree
Showing 38 changed files with 271 additions and 175 deletions.
43 changes: 22 additions & 21 deletions externs/closure-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ Polymer_PropertiesChanged.prototype._serializeValue = function(value){};
*/
Polymer_PropertiesChanged.prototype._deserializeValue = function(value, type){};
/**
* @param {Object} props Object whose keys are names of accessors.
* @param {!Object} props Object whose keys are names of accessors.
* @return {void}
*/
Polymer_PropertiesChanged.createProperties = function(props){};
/**
Expand Down Expand Up @@ -226,14 +227,14 @@ Polymer_TemplateStamp.prototype._addMethodEventListenerToNode = function(node, e
/**
* @param {!Node} node Node to add event listener to
* @param {string} eventName Name of event
* @param {Function} handler Listener function to add
* @param {function (!Event): void} handler Listener function to add
* @return {void}
*/
Polymer_TemplateStamp.prototype._addEventListenerToNode = function(node, eventName, handler){};
/**
* @param {Node} node Node to remove event listener from
* @param {string} eventName Name of event
* @param {Function} handler Listener function to remove
* @param {function (!Event): void} handler Listener function to remove
* @return {void}
*/
Polymer_TemplateStamp.prototype._removeEventListenerFromNode = function(node, eventName, handler){};
Expand Down Expand Up @@ -471,7 +472,7 @@ Polymer_PropertyEffects.prototype._hasComputedEffect = function(property){};
*/
Polymer_PropertyEffects.prototype._setPendingPropertyOrPath = function(path, value, shouldNotify, isPathNotification){};
/**
* @param {Node} node The node to set a property on
* @param {!Node} node The node to set a property on
* @param {string} prop The property to set
* @param {*} value The value to set
* @return {void}
Expand Down Expand Up @@ -637,7 +638,7 @@ Polymer_PropertyEffects.prototype._createReflectedProperty = function(property){
*/
Polymer_PropertyEffects.prototype._createComputedProperty = function(property, expression, dynamicFn){};
/**
* @param {HTMLTemplateElement} template Template containing binding
* @param {!HTMLTemplateElement} template Template containing binding
bindings
* @param {boolean=} instanceBinding When false (default), performs
"prototypical" binding of the template and overwrites any previously
Expand Down Expand Up @@ -726,9 +727,9 @@ Polymer_PropertyEffects.createReflectedProperty = function(property){};
*/
Polymer_PropertyEffects.createComputedProperty = function(property, expression, dynamicFn){};
/**
* @param {HTMLTemplateElement} template Template containing binding
* @param {!HTMLTemplateElement} template Template containing binding
bindings
* @return {Object}
* @return {!TemplateInfo}
*/
Polymer_PropertyEffects.bindTemplate = function(template){};
/**
Expand Down Expand Up @@ -779,7 +780,7 @@ Polymer_PropertiesMixin.prototype.disconnectedCallback = function(){};
*/
Polymer_PropertiesMixin.typeForProperty = function(name){};
/**
* @return {undefined}
* @return {void}
*/
Polymer_PropertiesMixin.finalize = function(){};
/**
Expand Down Expand Up @@ -888,14 +889,14 @@ function Polymer_GestureEventListeners(){}
/**
* @param {!Node} node Node to add event listener to
* @param {string} eventName Name of event
* @param {Function} handler Listener function to add
* @param {function (!Event): void} handler Listener function to add
* @return {void}
*/
Polymer_GestureEventListeners.prototype._addEventListenerToNode = function(node, eventName, handler){};
/**
* @param {!Node} node Node to remove event listener from
* @param {string} eventName Name of event
* @param {Function} handler Listener function to remove
* @param {function (!Event): void} handler Listener function to remove
* @return {void}
*/
Polymer_GestureEventListeners.prototype._removeEventListenerFromNode = function(node, eventName, handler){};
Expand Down Expand Up @@ -1034,9 +1035,9 @@ Polymer_LegacyElementMixin.prototype.serializeValueToAttribute = function(value,
*/
Polymer_LegacyElementMixin.prototype.extend = function(prototype, api){};
/**
* @param {Object} target Target object to copy properties to.
* @param {Object} source Source object to copy properties from.
* @return {Object}
* @param {!Object} target Target object to copy properties to.
* @param {!Object} source Source object to copy properties from.
* @return {!Object}
*/
Polymer_LegacyElementMixin.prototype.mixin = function(target, source){};
/**
Expand All @@ -1048,7 +1049,7 @@ Polymer_LegacyElementMixin.prototype.mixin = function(target, source){};
Polymer_LegacyElementMixin.prototype.chainObject = function(object, prototype){};
/**
* @param {HTMLTemplateElement} template HTML template element to instance.
* @return {DocumentFragment}
* @return {!DocumentFragment}
*/
Polymer_LegacyElementMixin.prototype.instanceTemplate = function(template){};
/**
Expand All @@ -1059,7 +1060,7 @@ Polymer_LegacyElementMixin.prototype.instanceTemplate = function(template){};
`bubbles` (boolean, defaults to `true`),
`cancelable` (boolean, defaults to false), and
`node` on which to fire the event (HTMLElement, defaults to `this`).
* @return {Event}
* @return {!Event}
*/
Polymer_LegacyElementMixin.prototype.fire = function(type, detail, options){};
/**
Expand Down Expand Up @@ -1139,7 +1140,7 @@ Polymer_LegacyElementMixin.prototype.getContentChildren = function(slctr){};
*/
Polymer_LegacyElementMixin.prototype.isLightDescendant = function(node){};
/**
* @param {Element=} node The element to be checked.
* @param {!Element} node The element to be checked.
* @return {boolean}
*/
Polymer_LegacyElementMixin.prototype.isLocalDescendant = function(node){};
Expand All @@ -1160,7 +1161,7 @@ Polymer_LegacyElementMixin.prototype.getComputedStyleValue = function(property){
context) when the wait time elapses.
* @param {number} wait Optional wait time in milliseconds (ms) after the
last signal that must elapse before invoking `callback`
* @return {Object}
* @return {!Object}
*/
Polymer_LegacyElementMixin.prototype.debounce = function(jobName, callback, wait){};
/**
Expand Down Expand Up @@ -1194,16 +1195,16 @@ Polymer_LegacyElementMixin.prototype.async = function(callback, waitTime){};
Polymer_LegacyElementMixin.prototype.cancelAsync = function(handle){};
/**
* @param {string} tag HTML element tag to create.
* @param {Object} props Object of properties to configure on the
* @param {Object=} props Object of properties to configure on the
instance.
* @return {Element}
* @return {!Element}
*/
Polymer_LegacyElementMixin.prototype.create = function(tag, props){};
/**
* @param {string} href URL to document to load.
* @param {!Function=} onload Callback to notify when an import successfully
* @param {?function (!Event): void=} onload Callback to notify when an import successfully
loaded.
* @param {!Function=} onerror Callback to notify when an import
* @param {?function (!ErrorEvent): void=} onerror Callback to notify when an import
unsuccessfully loaded.
* @param {boolean=} optAsync True if the import should be loaded `async`.
Defaults to `false`.
Expand Down
8 changes: 4 additions & 4 deletions lib/elements/dom-repeat.html
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@
* `modelForElement(el).set('item.<sub-prop>', value)`
* should be used.
*
* @param {HTMLElement} el Element for which to return the item.
* @param {!HTMLElement} el Element for which to return the item.
* @return {*} Item associated with the element.
*/
itemForElement(el) {
Expand All @@ -687,8 +687,8 @@
* If `sort` is provided, the index will reflect the sorted order (rather
* than the original array order).
*
* @param {HTMLElement} el Element for which to return the index.
* @return {*} Row index associated with the element (note this may
* @param {!HTMLElement} el Element for which to return the index.
* @return {?number} Row index associated with the element (note this may
* not correspond to the array index if a user `sort` is applied).
*/
indexForElement(el) {
Expand All @@ -709,7 +709,7 @@
* model.set('item.checked', true);
* }
*
* @param {HTMLElement} el Element for which to return a template model.
* @param {!HTMLElement} el Element for which to return a template model.
* @return {TemplateInstanceBase} Model representing the binding scope for
* the element.
*/
Expand Down
7 changes: 4 additions & 3 deletions lib/legacy/class.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
* to ensure that any legacy behaviors can rely on legacy Polymer API on
* the underlying element.
*
* @param {!(Object|Array)} behaviors Behavior object or array of behaviors.
* @param {!HTMLElement|function(new:HTMLElement)} klass Element class.
* @return {function(new:HTMLElement)} Returns a new Element class extended by the
* @template T
* @param {!(PolymerInit|Array<!PolymerInit>)} behaviors Behavior object or array of behaviors.
* @param {function(new:T)} klass Element class.
* @return {function(new:T)} Returns a new Element class extended by the
* passed in `behaviors` and also by `Polymer.LegacyElementMixin`.
* @memberof Polymer
* @suppress {invalidCasts, checkTypes}
Expand Down
24 changes: 12 additions & 12 deletions lib/legacy/legacy-element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@
* properties. To ensure only `ownProperties` are copied from source
* to target and that accessor implementations are copied, use `extend`.
*
* @param {Object} target Target object to copy properties to.
* @param {Object} source Source object to copy properties from.
* @return {Object} Target object that was passed as first argument.
* @param {!Object} target Target object to copy properties to.
* @param {!Object} source Source object to copy properties from.
* @return {!Object} Target object that was passed as first argument.
*/
mixin(target, source) {
for (let i in source) {
Expand Down Expand Up @@ -352,12 +352,12 @@
* returns a document fragment containing the imported content.
*
* @param {HTMLTemplateElement} template HTML template element to instance.
* @return {DocumentFragment} Document fragment containing the imported
* @return {!DocumentFragment} Document fragment containing the imported
* template content.
*/
instanceTemplate(template) {
let content = this.constructor._contentForTemplate(template);
let dom = /** @type {DocumentFragment} */
let dom = /** @type {!DocumentFragment} */
(document.importNode(content, true));
return dom;
}
Expand All @@ -377,7 +377,7 @@
* `bubbles` (boolean, defaults to `true`),
* `cancelable` (boolean, defaults to false), and
* `node` on which to fire the event (HTMLElement, defaults to `this`).
* @return {Event} The new event that was fired.
* @return {!Event} The new event that was fired.
*/
fire(type, detail, options) {
options = options || {};
Expand Down Expand Up @@ -631,7 +631,7 @@
/**
* Checks whether an element is in this element's local DOM tree.
*
* @param {Element=} node The element to be checked.
* @param {!Element} node The element to be checked.
* @return {boolean} true if node is in this element's local DOM tree.
*/
isLocalDescendant(node) {
Expand Down Expand Up @@ -679,7 +679,7 @@
* context) when the wait time elapses.
* @param {number} wait Optional wait time in milliseconds (ms) after the
* last signal that must elapse before invoking `callback`
* @return {Object} Returns a debouncer object on which exists the
* @return {!Object} Returns a debouncer object on which exists the
* following methods: `isActive()` returns true if the debouncer is
* active; `cancel()` cancels the debouncer if it is active;
* `flush()` immediately invokes the debounced callback if the debouncer
Expand Down Expand Up @@ -768,9 +768,9 @@
* Convenience method for creating an element and configuring it.
*
* @param {string} tag HTML element tag to create.
* @param {Object} props Object of properties to configure on the
* @param {Object=} props Object of properties to configure on the
* instance.
* @return {Element} Newly created and configured element.
* @return {!Element} Newly created and configured element.
*/
create(tag, props) {
let elt = document.createElement(tag);
Expand All @@ -795,9 +795,9 @@
* element will contain the imported document contents.
*
* @param {string} href URL to document to load.
* @param {!Function=} onload Callback to notify when an import successfully
* @param {?function(!Event):void=} onload Callback to notify when an import successfully
* loaded.
* @param {!Function=} onerror Callback to notify when an import
* @param {?function(!ErrorEvent):void=} onerror Callback to notify when an import
* unsuccessfully loaded.
* @param {boolean=} optAsync True if the import should be loaded `async`.
* Defaults to `false`.
Expand Down
Loading

0 comments on commit 589684a

Please sign in to comment.