Skip to content

Commit 5613be4

Browse files
committed
Only methods and constructors are bivariant in --strictFunctionTypes mode
1 parent 1795614 commit 5613be4

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3549,7 +3549,7 @@ namespace ts {
35493549
return;
35503550
}
35513551

3552-
if (resolved.callSignatures.length === 1 && !resolved.constructSignatures.length && isStrictSignature(resolved.callSignatures[0])) {
3552+
if (resolved.callSignatures.length === 1 && !resolved.constructSignatures.length) {
35533553
const parenthesizeSignature = shouldAddParenthesisAroundFunctionType(resolved.callSignatures[0], flags);
35543554
if (parenthesizeSignature) {
35553555
writePunctuation(writer, SyntaxKind.OpenParenToken);
@@ -3560,7 +3560,7 @@ namespace ts {
35603560
}
35613561
return;
35623562
}
3563-
if (resolved.constructSignatures.length === 1 && !resolved.callSignatures.length && isStrictSignature(resolved.constructSignatures[0])) {
3563+
if (resolved.constructSignatures.length === 1 && !resolved.callSignatures.length) {
35643564
if (flags & TypeFormatFlags.InElementType) {
35653565
writePunctuation(writer, SyntaxKind.OpenParenToken);
35663566
}
@@ -8522,17 +8522,6 @@ namespace ts {
85228522
/*errorReporter*/ undefined, compareTypesAssignable) !== Ternary.False;
85238523
}
85248524

8525-
// A signature is considered strict if it is declared in a function type literal, a constructor type
8526-
// literal, a function expression, an arrow function, or a function declaration with no overloads. A
8527-
// strict signature is subject to strict checking in strictFunctionTypes mode.
8528-
function isStrictSignature(signature: Signature) {
8529-
const declaration = signature.declaration;
8530-
const kind = declaration ? declaration.kind : SyntaxKind.Unknown;
8531-
return kind === SyntaxKind.FunctionType || kind === SyntaxKind.ConstructorType ||
8532-
kind === SyntaxKind.FunctionExpression || kind === SyntaxKind.ArrowFunction ||
8533-
(kind === SyntaxKind.FunctionDeclaration && getSingleCallSignature(getTypeOfSymbol(getSymbolOfNode(declaration))));
8534-
}
8535-
85368525
type ErrorReporter = (message: DiagnosticMessage, arg0?: string, arg1?: string) => void;
85378526

85388527
/**
@@ -8558,7 +8547,9 @@ namespace ts {
85588547
source = instantiateSignatureInContextOf(source, target, /*contextualMapper*/ undefined, compareTypes);
85598548
}
85608549

8561-
const strictVariance = strictFunctionTypes && isStrictSignature(target);
8550+
const kind = target.declaration ? target.declaration.kind : SyntaxKind.Unknown;
8551+
const strictVariance = strictFunctionTypes && kind !== SyntaxKind.MethodDeclaration &&
8552+
kind !== SyntaxKind.MethodSignature && kind !== SyntaxKind.Constructor;
85628553
let result = Ternary.True;
85638554

85648555
const sourceThisType = getThisTypeOfSignature(source);

0 commit comments

Comments
 (0)