Skip to content

Commit

Permalink
Fix userAssert's type annotation (#28191)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jridgewell committed May 5, 2020
1 parent 52ea599 commit 8545cdd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
2 changes: 2 additions & 0 deletions build-system/compile/compile.js
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-analytics/0.1/events.js
Expand Up @@ -1112,7 +1112,7 @@ export class TimerEventTracker extends EventTracker {
}

const timerHandler = new TimerEventHandler(
timerSpec,
/** @type {!JsonObject} */ (timerSpec),
startBuilder,
stopBuilder
);
Expand Down
23 changes: 3 additions & 20 deletions src/log.js
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 8545cdd

Please sign in to comment.