Skip to content

Commit 017a76b

Browse files
committed
Merge pull request #357 from Microsoft/specialized_signatures
fixed check for call\construct signatures in interfaces
2 parents 7fc1b8c + 3fc10ed commit 017a76b

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

src/compiler/checker.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4946,12 +4946,26 @@ module ts {
49464946
return;
49474947
}
49484948

4949+
var symbol = getSymbolOfNode(signatureDeclarationNode);
49494950
// TypeScript 1.0 spec (April 2014): 3.7.2.4
49504951
// Every specialized call or construct signature in an object type must be assignable
49514952
// to at least one non-specialized call or construct signature in the same object type
4952-
var signaturesOfSymbol = getSignaturesOfSymbol(getSymbolOfNode(signatureDeclarationNode));
4953-
for (var i = 0; i < signaturesOfSymbol.length; i++) {
4954-
var otherSignature = signaturesOfSymbol[i];
4953+
var signaturesToCheck: Signature[];
4954+
// Unnamed (call\construct) signatures in interfaces are inherited and not shadowed so examining just node symbol won't give complete answer.
4955+
// Use declaring type to obtain full list of signatures.
4956+
if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === SyntaxKind.InterfaceDeclaration) {
4957+
Debug.assert(signatureDeclarationNode.kind === SyntaxKind.CallSignature || signatureDeclarationNode.kind === SyntaxKind.ConstructSignature);
4958+
var signatureKind = signatureDeclarationNode.kind === SyntaxKind.CallSignature ? SignatureKind.Call : SignatureKind.Construct;
4959+
var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent);
4960+
var containingType = getDeclaredTypeOfSymbol(containingSymbol);
4961+
signaturesToCheck = getSignaturesOfType(containingType, signatureKind);
4962+
}
4963+
else {
4964+
signaturesToCheck = getSignaturesOfSymbol(getSymbolOfNode(signatureDeclarationNode));
4965+
}
4966+
4967+
for (var i = 0; i < signaturesToCheck.length; i++) {
4968+
var otherSignature = signaturesToCheck[i];
49554969
if (!otherSignature.hasStringLiterals && isSignatureAssignableTo(signature, otherSignature)) {
49564970
return;
49574971
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [specializedSignatureInInterface.ts]
2+
interface A {
3+
(key:string):void;
4+
}
5+
6+
interface B extends A {
7+
(key:'foo'):string;
8+
(key:'bar'):string;
9+
}
10+
11+
//// [specializedSignatureInInterface.js]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface A {
2+
(key:string):void;
3+
}
4+
5+
interface B extends A {
6+
(key:'foo'):string;
7+
(key:'bar'):string;
8+
}

0 commit comments

Comments
 (0)