Skip to content

Commit ec35b80

Browse files
committed
Allow callbacks unioned with null and/or undefined
1 parent 510bc81 commit ec35b80

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8213,8 +8213,8 @@ namespace ts {
82138213
for (let i = 0; i < checkCount; i++) {
82148214
const sourceType = i < sourceMax ? getTypeOfParameter(sourceParams[i]) : getRestTypeOfSignature(source);
82158215
const targetType = i < targetMax ? getTypeOfParameter(targetParams[i]) : getRestTypeOfSignature(target);
8216-
const sourceSig = getSingleCallSignature(sourceType);
8217-
const targetSig = getSingleCallSignature(targetType);
8216+
const sourceSig = getSingleCallSignature(getNonNullableType(sourceType));
8217+
const targetSig = getSingleCallSignature(getNonNullableType(targetType));
82188218
// In order to ensure that any generic type Foo<T> is at least co-variant with respect to T no matter
82198219
// how Foo uses T, we need to relate parameters bi-variantly (given that parameters are input positions,
82208220
// they naturally relate only contra-variantly). However, if the source and target parameters both have
@@ -8223,7 +8223,9 @@ namespace ts {
82238223
// similar to return values, callback parameters are output positions. This means that a Promise<T>,
82248224
// where T is used only in callback parameter positions, will be co-variant (as opposed to bi-variant)
82258225
// with respect to T.
8226-
const related = sourceSig && targetSig && !sourceSig.typePredicate && !targetSig.typePredicate ?
8226+
const callbacks = sourceSig && targetSig && !sourceSig.typePredicate && !targetSig.typePredicate &&
8227+
(getFalsyFlags(sourceType) & TypeFlags.Nullable) === (getFalsyFlags(targetType) & TypeFlags.Nullable);
8228+
const related = callbacks ?
82278229
compareSignaturesRelated(targetSig, sourceSig, /*checkAsCallback*/ true, /*ignoreReturnTypes*/ false, reportErrors, errorReporter, compareTypes) :
82288230
!checkAsCallback && compareTypes(sourceType, targetType, /*reportErrors*/ false) || compareTypes(targetType, sourceType, reportErrors);
82298231
if (!related) {

0 commit comments

Comments
 (0)