diff --git a/.travis.yml b/.travis.yml index d0e905188e1f8..93b2254db071d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,8 +28,7 @@ script: - npm run ava - gulp lint - gulp build --fortesting --css-only - # TODO(jridgewell, #4347) Enable once assertions prove truthiness again. - # - gulp check-types + - gulp check-types - gulp dist --fortesting - gulp presubmit # dep-check needs to occur after build since we rely on build to generate diff --git a/ads/ads.extern.js b/ads/ads.extern.js index e1a50a7db9eae..99bb8593ab235 100644 --- a/ads/ads.extern.js +++ b/ads/ads.extern.js @@ -148,10 +148,3 @@ data.antid; data.anapiid; window.MADSAdrequest = {}; window.MADSAdrequest.adrequest; -/** - * @constructor - * @param {!Window} global - * @param {!Object} data - */ -window.EzoicAmpAd = function(global, data) {}; -window.EzoicAmpAd.prototype.createAd; diff --git a/src/experiments.js b/src/experiments.js index a28305869e93b..e4afe7ee7b401 100644 --- a/src/experiments.js +++ b/src/experiments.js @@ -36,7 +36,7 @@ const COOKIE_EXPIRATION_INTERVAL = COOKIE_MAX_AGE_DAYS * 24 * 60 * 60 * 1000; /** @const {string} */ const CANARY_EXPERIMENT_ID = 'dev-channel'; -/** @type {Object} */ +/** @type {Object|undefined} */ let toggles_; /** diff --git a/src/log.js b/src/log.js index dfbe4e119923d..d4ca7e615c248 100644 --- a/src/log.js +++ b/src/log.js @@ -219,7 +219,6 @@ export class Log { * @param {...*} var_args Arguments substituted into %s in the message. * @return {T} The value of shouldBeTrueish. * @template T - * @throws {Error} */ /*eslint "google-camelcase/google-camelcase": 0*/ assert(shouldBeTrueish, opt_message, var_args) { diff --git a/src/observable.js b/src/observable.js index f0621d221dc94..3ad72313b95a8 100644 --- a/src/observable.js +++ b/src/observable.js @@ -53,13 +53,13 @@ export class Observable { /** * Fires an event. All observers are called. - * @param {TYPE} event + * @param {TYPE=} opt_event */ - fire(event) { + fire(opt_event) { const handlers = this.handlers_; for (let i = 0; i < handlers.length; i++) { const handler = handlers[i]; - handler(event); + handler(opt_event); } } diff --git a/src/service/viewer-impl.js b/src/service/viewer-impl.js index 9d167686c0bf2..ffdf245131c97 100644 --- a/src/service/viewer-impl.js +++ b/src/service/viewer-impl.js @@ -125,7 +125,7 @@ export class Viewer { /** @private {number} */ this.prerenderSize_ = 1; - /** @private {string} */ + /** @private {ViewportType} */ this.viewportType_ = ViewportType.NATURAL; /** @private {number} */ @@ -188,7 +188,7 @@ export class Viewer { this.isRuntimeOn_ = !parseInt(this.params_['off'], 10); dev().fine(TAG_, '- runtimeOn:', this.isRuntimeOn_); - this.overtakeHistory_ = parseInt(this.params_['history'], 10) || + this.overtakeHistory_ = !!(parseInt(this.params_['history'], 10)) || this.overtakeHistory_; dev().fine(TAG_, '- history:', this.overtakeHistory_); @@ -237,6 +237,9 @@ export class Viewer { // Wait for document to become visible. this.docState_.onVisibilityChanged(this.recheckVisibilityState_.bind(this)); + /** @private {function()|undefined} */ + this.messagingReadyResolver_ = undefined; + /** * This promise will resolve when communications channel has been * established or timeout in 20 seconds. The timeout is needed to avoid @@ -248,10 +251,10 @@ export class Viewer { timerFor(this.win).timeoutPromise( 20000, new Promise(resolve => { - /** @private @const {function()|undefined} */ this.messagingReadyResolver_ = resolve; })).catch(reason => { - throw getChannelError(reason); + throw getChannelError(/** @type {!Error|string|undefined} */ ( + reason)); }) : null; /** @@ -265,7 +268,8 @@ export class Viewer { this.messagingReadyPromise_ .catch(reason => { // Don't fail promise, but still report. - reportError(getChannelError(reason)); + reportError(getChannelError( + /** @type {!Error|string|undefined} */ (reason))); }) : null; // Trusted viewer and referrer. @@ -283,10 +287,12 @@ export class Viewer { this.isTrustedViewerOrigin_(this.win.location.ancestorOrigins[0])); trustedViewerPromise = Promise.resolve(trustedViewerResolved); } else { + + /** @private {!function(boolean)|undefined} */ + this.trustedViewerResolver_ = undefined; // Wait for comms channel to confirm the origin. trustedViewerResolved = undefined; trustedViewerPromise = new Promise(resolve => { - /** @const @private {!function(boolean)|undefined} */ this.trustedViewerResolver_ = resolve; }); } @@ -294,6 +300,9 @@ export class Viewer { /** @const @private {!Promise} */ this.isTrustedViewer_ = trustedViewerPromise; + /** @private {!function(string)|undefined} */ + this.viewerOriginResolver_ = undefined; + /** @const @private {!Promise} */ this.viewerOrigin_ = new Promise(resolve => { if (!this.isEmbedded()) { @@ -868,7 +877,7 @@ export class Viewer { /** * Requests AMP document to receive a message from Viewer. * @param {string} eventType - * @param {*} data + * @param {!JSONType} data * @param {boolean} unusedAwaitResponse * @return {(!Promise<*>|undefined)} * @export @@ -1065,7 +1074,7 @@ function parseParams_(str, allParams) { /** * Creates an error for the case where a channel cannot be established. - * @param {!Error=} opt_reason + * @param {!Error|string=} opt_reason * @return {!Error} */ function getChannelError(opt_reason) { diff --git a/src/service/viewport-impl.js b/src/service/viewport-impl.js index 931d22adc5635..d0da3401dd9b5 100644 --- a/src/service/viewport-impl.js +++ b/src/service/viewport-impl.js @@ -500,8 +500,8 @@ export class Viewport { return null; } if (this.viewportMeta_ === undefined) { - this.viewportMeta_ = this.win_.document.querySelector( - 'meta[name=viewport]'); + this.viewportMeta_ = /** @type {?HTMLMetaElement} */ ( + this.win_.document.querySelector('meta[name=viewport]')); if (this.viewportMeta_) { this.originalViewportMetaString_ = this.viewportMeta_.content; } @@ -1253,7 +1253,7 @@ export function updateViewportMetaString(currentValue, updateParams) { if (params[k] !== updateParams[k]) { changed = true; if (updateParams[k] !== undefined) { - params[k] = updateParams[k]; + params[k] = /** @type {string} */ (updateParams[k]); } else { delete params[k]; } diff --git a/src/service/vsync-impl.js b/src/service/vsync-impl.js index 140698b03b75d..3fef0c7a8be8f 100644 --- a/src/service/vsync-impl.js +++ b/src/service/vsync-impl.js @@ -125,7 +125,7 @@ export class Vsync { * will be undefined. * * @param {!VsyncTaskSpecDef} task - * @param {VsyncStateDef=} opt_state + * @param {!VsyncStateDef=} opt_state */ run(task, opt_state) { this.tasks_.push(task); diff --git a/src/service/xhr-impl.js b/src/service/xhr-impl.js index 59c288ead1379..95c8c32bcb234 100644 --- a/src/service/xhr-impl.js +++ b/src/service/xhr-impl.js @@ -100,7 +100,7 @@ export class Xhr { if (opt_init && opt_init.responseType == 'document') { return fetchPolyfill(input, opt_init); } - return fetchPolyfill(input, opt_init); + return (this.win.fetch || fetchPolyfill).apply(null, arguments); } /** diff --git a/src/url.js b/src/url.js index bfdf8ed32f308..085b15b3bfa39 100644 --- a/src/url.js +++ b/src/url.js @@ -61,7 +61,7 @@ export let Location; */ export function parseUrl(url) { if (!a) { - a = self.document.createElement('a'); + a = /** @type {HTMLAnchorElement} */ (self.document.createElement('a')); cache = self.UrlCache || (self.UrlCache = Object.create(null)); } @@ -200,7 +200,7 @@ export function assertHttpsUrl( urlString, elementContext, sourceName = 'source') { user().assert(urlString != null, '%s %s must be available', elementContext, sourceName); - const url = parseUrl(urlString); + const url = parseUrl(/** @type {string} */ (urlString)); user().assert( url.protocol == 'https:' || /^(\/\/)/.test(urlString) || url.hostname == 'localhost' || endsWith(url.hostname, '.localhost'), @@ -208,7 +208,7 @@ export function assertHttpsUrl( '"https://" or "//" or be relative and served from ' + 'either https or from localhost. Invalid value: %s', elementContext, sourceName, urlString); - return urlString; + return /** @type {string} */ (urlString); } /**