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!
```
This commit is contained in:
Nathan Shively-Sanders 2017-08-07 10:56:18 -07:00
parent a453eff575
commit a282cbb07e

View File

@ -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) {