Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Fix type checking in matcher_types.js.
Browse files Browse the repository at this point in the history
Adds explicit casts to clarify two cases where the type checker isn't quite sophisticated enough to infer the correct types.

Background: Closure Compiler is trying to land a change to improve inference of qualified names.  An upshot of this is that it will soon understand that "this.getDescription" is supposed to be a `function(): string` (rather than just unknown as it does currently), which causes a type error when it tries to return a `string|function(): string` (note that the compiler does not currently propagate the flow-sensitive context that `description` is definitely a string from outside the closure to inside).
  • Loading branch information
shicks authored and jacobsa committed Mar 19, 2018
1 parent b4cacaa commit 4abd4af
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions gjstest/public/matcher_types.js
Expand Up @@ -70,13 +70,15 @@ gjstest.Matcher = function(description, negativeDescription, predicate) {
if (description instanceof Function) {
this.getDescription = description;
} else {
this.getDescription = function() { return description; };
this.getDescription =
function() { return /** @type {string} */ (description); };
}

if (negativeDescription instanceof Function) {
this.getNegativeDescription = negativeDescription;
} else {
this.getNegativeDescription = function() { return negativeDescription; };
this.getNegativeDescription =
function() { return /** @type {string} */ (negativeDescription); };
}
};

Expand Down

0 comments on commit 4abd4af

Please sign in to comment.