Skip to content

Commit

Permalink
[NTI] Allow a constructor with @return to be typed as the corresponding
Browse files Browse the repository at this point in the history
function type.

Fixes #2321 on github.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=153760294
  • Loading branch information
dimvar committed Apr 21, 2017
1 parent 4fe5f0d commit 9665985
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ private boolean isSubtypeOfHelper(FunctionType other, boolean checkThisType,

// covariance for the new: type
if (this.nominalType == null && other.nominalType != null
|| this.nominalType != null && other.nominalType == null
|| this.nominalType != null && other.nominalType != null
&& !this.nominalType.isSubtypeOf(other.nominalType, subSuperMap)) {
return false;
Expand Down
14 changes: 14 additions & 0 deletions test/com/google/javascript/jscomp/NewTypeInferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19911,4 +19911,18 @@ public void testDontTurnKnownObjectIntoLooseBecauseOfBottomSpecialization() {
" this.prop = new Foo;",
"}"));
}

public void testAllowConstructorWithReturnToBeTypedAsFunction() {
typeCheck(LINE_JOINER.join(
"/**",
" * @constructor",
" * @param {number} x",
" * @return {number}",
" */",
"function Foo(x) { return x; }",
"function f(/** function(number):number */ x) {",
" x(123);",
"}",
"f(Foo);"));
}
}

0 comments on commit 9665985

Please sign in to comment.