From a282cbb07e18f0ef1bfd21633f8b461fa961e42f Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 7 Aug 2017 10:56:18 -0700 Subject: [PATCH] Weak type errors for signature-only types too Now source types that only have a call signature (like functions) or construct signature will get a weak type error too. This is really good for catching uncalled functions: ```ts functionTakingWeakType(returnWeakType); // OOPS. Forgot to call `returnWeakType()`. That's an error! ``` --- src/compiler/checker.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a8af11e7803..990bfd546a3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8938,7 +8938,9 @@ namespace ts { !(target.flags & TypeFlags.Union) && !isIntersectionConstituent && source !== globalObjectType && - getPropertiesOfType(source).length > 0 && + (getPropertiesOfType(source).length > 0 || + getSignaturesOfType(source, SignatureKind.Call).length > 0 || + getSignaturesOfType(source, SignatureKind.Construct).length > 0) && isWeakType(target) && !hasCommonProperties(source, target)) { if (reportErrors) {