preserve some old behavior at @DanielRosenwassers request

This commit is contained in:
Wesley Wigham
2015-12-08 17:45:11 -08:00
parent 459430165d
commit 0228ec3ced
3 changed files with 20 additions and 2 deletions

View File

@@ -5633,6 +5633,16 @@ namespace ts {
if (targetReturnType === voidType) return result;
const sourceReturnType = getReturnTypeOfSignature(source);
// The follow block preserves old behavior forbidding boolean returning functions from being assignable to type guard returning functions
if (targetReturnType.flags & TypeFlags.PredicateType && (targetReturnType as PredicateType).predicate.kind === TypePredicateKind.Identifier) {
if (!(sourceReturnType.flags & TypeFlags.PredicateType)) {
if (reportErrors) {
reportError(Diagnostics.Signature_0_must_have_a_type_predicate, signatureToString(source));
}
return Ternary.False;
}
}
return result & isRelatedTo(sourceReturnType, targetReturnType, reportErrors);
}