From b3dfd38e305fbfeb3aedc9427680e2844c28644d Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Wed, 26 Apr 2017 17:29:38 -0700 Subject: [PATCH] slighly better typing for mixin funcion --- closure.log | 77 ++++++++++++++++++-------------------------- lib/utils/mixin.html | 9 +++--- 2 files changed, 36 insertions(+), 50 deletions(-) diff --git a/closure.log b/closure.log index d895f9e9b7..58621a3970 100644 --- a/closure.log +++ b/closure.log @@ -5,6 +5,32 @@ Found : undefined return window.Polymer._polymerFn(info); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +/polymer.html_script_1.js:44: WARNING - Invalid type for parameter 1 of function cachingMixin. +Expected : Function|null +Found : T + + let cachedMixin = cachingMixin(mixin); + ^^^^^ + +/polymer.html_script_1.js:47: WARNING - Returned type does not match declared return type. +Expected : T +Found : function({__mixinSet:?} (loose)):{__mixinSet:?} (loose) + + return function(base) { + ^^^^^^^^^^^^^^^^^^^^^^^ + +/polymer.html_script_1.js:49: WARNING - Cannot access property __dedupeId of non-object type T. + if (baseSet && baseSet[mixin.__dedupeId]) { + ^^^^^ + +/polymer.html_script_1.js:52: WARNING - Cannot call non-function type T + let extended = mixin(base); + ^^^^^^^^^^^ + +/polymer.html_script_1.js:58: WARNING - Cannot access property __dedupeId of non-object type T. + extended.__mixinSet[mixin.__dedupeId] = true; + ^^^^^ + /polymer.html_script_10.js:144: WARNING - Property name never defined on trigger of type Object let triggerPath = trigger.name; ^^^^^^^^^^^^ @@ -197,11 +223,6 @@ The found type is a union that includes an unexpected type: null inst.__data[splicesPath] = {indexSplices: null}; ^^^^^^^^^^^ -/polymer.html_script_10.js:1042: WARNING - propertyEffectsBase extends non-object type ?. - - const propertyEffectsBase = Polymer.TemplateStamp(Polymer.PropertyAccessors(superClass)); - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - /polymer.html_script_10.js:1076: WARNING - Invalid type for parameter 1 of function Object.create. Expected : Object|null Found : * @@ -485,11 +506,6 @@ Found : PropertyEffects value = inst.__data[path]; ^^^^^^^^^^^ -/polymer.html_script_11.js:105: WARNING - polymerElementBase extends non-object type ?. - - const polymerElementBase = Polymer.PropertyEffects(base); - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - /polymer.html_script_11.js:126: WARNING - Property properties never defined on klass of type HTMLElement klass.properties : {}; ^^^^^^^^^^^^^^^^ @@ -717,11 +733,6 @@ Found : PolymerElement * @param {Polymer.Debouncer?} debouncer Debouncer object. ^^^^^^^^^^^^^^^^^ -/polymer.html_script_14.js:31: WARNING - GestureEventListeners extends non-object type ?. - - class GestureEventListeners extends superClass { - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - /polymer.html_script_21.js:189: WARNING - Dangerous use of the global THIS object return this.node[method].apply(this.node, arguments); ^^^^ @@ -746,11 +757,6 @@ Found : PolymerElement !(window.customElements.polyfillWrapFlushCallback); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -/polymer.html_script_22.js:30: WARNING - legacyElementBase extends non-object type ?. - - const legacyElementBase = Polymer.GestureEventListeners(Polymer.ElementMixin(base)); - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - /polymer.html_script_22.js:863: WARNING - Function this.splice: called with 3 argument(s). Function requires at least 4 argument(s) and at most 4. return this.splice(arrayOrPath, index, 1); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -803,16 +809,6 @@ Found : HTMLElement<|function(new:HTMLElement):?|> window.Polymer._polymerFn = function(info) { ^^^^^^^^^^^^^^^^^^^^^^^^^ -/polymer.html_script_25.js:67: WARNING - MutableData extends non-object type ?. - - class MutableData extends superClass { - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -/polymer.html_script_25.js:138: WARNING - OptionalMutableData extends non-object type ?. - - class OptionalMutableData extends superClass { - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - /polymer.html_script_25.js:170: WARNING - Property mutableData never defined on this of type OptionalMutableData return mutablePropertyChange(this, property, value, old, this.mutableData); ^^^^^^^^^^^^^^^^ @@ -1214,11 +1210,6 @@ Found : DomIf<|function(new:DomIf):undefined|> customElements.define(DomIf.is, DomIf); ^^^^^ -/polymer.html_script_32.js:86: WARNING - ArraySelectorMixin extends non-object type ?. - - constructor() { - ^^^^^^^^^^^^^^^ - /polymer.html_script_32.js:143: WARNING - Property items never defined on this of type ArraySelectorMixin if (selected.has(this.items[idx])) { ^^^^^^^^^^ @@ -1332,6 +1323,10 @@ Found : Element return this._style; ^^^^^^^^^^^^^^^^^^^ +/polymer.html_script_34.js:5: WARNING - Property _mutablePropertyChange never defined on Polymer.MutableData of type function(?):? + let mutablePropertyChange = Polymer.MutableData._mutablePropertyChange; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + /polymer.html_script_34.js:132: WARNING - Dangerous use of the global THIS object return mutablePropertyChange(this, property, value, old, this.mutableData); ^^^^ @@ -1380,11 +1375,6 @@ Found : Element let parts = this.split(path); ^^^^ -/polymer.html_script_8.js:103: WARNING - PropertyAccessors extends non-object type ?. - - constructor() { - ^^^^^^^^^^^^^^^ - /polymer.html_script_8.js:117: WARNING - Function this._attributeToProperty: called with 2 argument(s). Function requires at least 3 argument(s) and at most 3. this._attributeToProperty(name, value); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -1419,11 +1409,6 @@ Found : PropertyAccessors{__serializing:boolean} _setPendingProperty(property, value) { ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -/polymer.html_script_9.js:106: WARNING - TemplateStamp extends non-object type ?. - - class TemplateStamp extends superClass { - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - /polymer.html_script_9.js:110: WARNING - Cannot add property $ to a struct instance after it is constructed. this.$ = null; ^^^^^^ @@ -1510,4 +1495,4 @@ externs/closure-types.js:759: WARNING - property toggle on interface Polymer_Arr Polymer_ArraySelectorMixin.prototype.toggle; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -0 error(s), 331 warning(s), 72.6% typed +0 error(s), 328 warning(s), 72.6% typed diff --git a/lib/utils/mixin.html b/lib/utils/mixin.html index 12a4ebb3c8..0e2a99dab3 100644 --- a/lib/utils/mixin.html +++ b/lib/utils/mixin.html @@ -47,14 +47,15 @@ * applications. * * @memberof Polymer - * @param {Function} mixin ES6 class expression mixin to wrap - * @return {Function} Wrapped mixin that deduplicates and memoizes + * @template T + * @param {T} mixin ES6 class expression mixin to wrap + * @return {T} Wrapped mixin that deduplicates and memoizes * mixin applications to base */ Polymer.dedupingMixin = function(mixin) { - mixin = cachingMixin(mixin); + let cachedMixin = cachingMixin(mixin); // maintain a unique id for each mixin - mixin.__dedupeId = ++dedupeId; + cachedMixin.__dedupeId = ++dedupeId; return function(base) { let baseSet = base.__mixinSet; if (baseSet && baseSet[mixin.__dedupeId]) {