From 8545cdd1bfb18c2d164e4ad994f7535e25facd75 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Tue, 5 May 2020 16:45:14 -0400 Subject: [PATCH] Fix userAssert's type annotation (#28191) * Fix userAssert's type annotation Matches `devAssert`'s change in #24047. * Remove old notes * Add single cast Closure is narrowing the type to `Object` due to the `typeof x === 'object'` check. Seems like a bug. * Speed up check-types by 30s --- build-system/compile/compile.js | 2 ++ extensions/amp-analytics/0.1/events.js | 2 +- src/log.js | 23 +++-------------------- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/build-system/compile/compile.js b/build-system/compile/compile.js index 7eb4d7196f1f..6123fd11cd7e 100644 --- a/build-system/compile/compile.js +++ b/build-system/compile/compile.js @@ -315,6 +315,8 @@ function compile( // See https://github.com/google/closure-compiler/wiki/Warnings#warnings-categories // for a full list of closure's default error / warning levels. if (options.typeCheckOnly) { + compilerOptions.checks_only = true; + // Don't modify compilation_level to a lower level since // it won't do strict type checking if its whitespace only. compilerOptions.define.push('TYPECHECK_ONLY=true'); diff --git a/extensions/amp-analytics/0.1/events.js b/extensions/amp-analytics/0.1/events.js index 48c7dacb6ffe..51ced2dbe620 100644 --- a/extensions/amp-analytics/0.1/events.js +++ b/extensions/amp-analytics/0.1/events.js @@ -1112,7 +1112,7 @@ export class TimerEventTracker extends EventTracker { } const timerHandler = new TimerEventHandler( - timerSpec, + /** @type {!JsonObject} */ (timerSpec), startBuilder, stopBuilder ); diff --git a/src/log.js b/src/log.js index 7b4fd3f42245..98b87930ef9f 100644 --- a/src/log.js +++ b/src/log.js @@ -385,9 +385,6 @@ export class Log { * elements in an array. When e.g. passed to console.error this yields * native displays of things like HTML elements. * - * NOTE: for an explanation of the tempate R implementation see - * https://github.com/google/closure-library/blob/08858804/closure/goog/asserts/asserts.js#L192-L213 - * * @param {T} shouldBeTrueish The value to assert. The assert fails if it does * not evaluate to true. * @param {!Array|string=} opt_message The assertion message @@ -877,9 +874,6 @@ export function isFromEmbed(win, opt_element) { * elements in an array. When e.g. passed to console.error this yields * native displays of things like HTML elements. * - * NOTE: for an explanation of the tempate R implementation see - * https://github.com/google/closure-library/blob/08858804/closure/goog/asserts/asserts.js#L192-L213 - * * @param {T} shouldBeTrueish The value to assert. The assert fails if it does * not evaluate to true. * @param {!Array|string=} opt_message The assertion message @@ -940,9 +934,6 @@ export function devAssert( * elements in an array. When e.g. passed to console.error this yields * native displays of things like HTML elements. * - * NOTE: for an explanation of the tempate R implementation see - * https://github.com/google/closure-library/blob/08858804/closure/goog/asserts/asserts.js#L192-L213 - * * @param {T} shouldBeTrueish The value to assert. The assert fails if it does * not evaluate to true. * @param {!Array|string=} opt_message The assertion message @@ -955,18 +946,10 @@ export function devAssert( * @param {*=} opt_7 Optional argument * @param {*=} opt_8 Optional argument * @param {*=} opt_9 Optional argument - * @return {R} The value of shouldBeTrueish. + * @return {T} The value of shouldBeTrueish. + * @throws {!Error} When `shouldBeTrueish` is falsey. * @template T - * @template R := - * mapunion(T, (V) => - * cond(eq(V, 'null'), - * none(), - * cond(eq(V, 'undefined'), - * none(), - * V))) - * =: - * @throws {!Error} When `value` is `null` or `undefined`. - * @closurePrimitive {asserts.matchesReturn} + * @closurePrimitive {asserts.truthy} */ export function userAssert( shouldBeTrueish,