Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b514fa5

Browse files
committed
Merge pull request microsoft#514 from Microsoft/overloadSignatureDeclaration
Correct the declaration emit for overload implementation if there is single overload signature
2 parents 0a6f027 + 519ef5b commit b514fa5

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

src/compiler/checker.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -7096,7 +7096,20 @@ module ts {
70967096
function isImplementationOfOverload(node: FunctionDeclaration) {
70977097
if (node.body) {
70987098
var symbol = getSymbolOfNode(node);
7099-
return getSignaturesOfSymbol(symbol).length > 1;
7099+
var signaturesOfSymbol = getSignaturesOfSymbol(symbol);
7100+
// If this function body corresponds to function with multiple signature, it is implementation of overload
7101+
// eg: function foo(a: string): string;
7102+
// function foo(a: number): number;
7103+
// function foo(a: any) { // This is implementation of the overloads
7104+
// return a;
7105+
// }
7106+
return signaturesOfSymbol.length > 1 ||
7107+
// If there is single signature for the symbol, it is overload if that signature isnt coming from the node
7108+
// eg: function foo(a: string): string;
7109+
// function foo(a: any) { // This is implementation of the overloads
7110+
// return a;
7111+
// }
7112+
(signaturesOfSymbol.length === 1 && signaturesOfSymbol[0].declaration !== node);
71007113
}
71017114
return false;
71027115
}

tests/baselines/reference/declFileFunctions.js

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export function fooWithOverloads(a: any): any {
2121
return a;
2222
}
2323

24+
export function fooWithSingleOverload(a: string): string;
25+
export function fooWithSingleOverload(a: any) {
26+
return a;
27+
}
28+
2429
/** This comment should appear for nonExportedFoo*/
2530
function nonExportedFoo() {
2631
}
@@ -83,6 +88,10 @@ function fooWithOverloads(a) {
8388
return a;
8489
}
8590
exports.fooWithOverloads = fooWithOverloads;
91+
function fooWithSingleOverload(a) {
92+
return a;
93+
}
94+
exports.fooWithSingleOverload = fooWithSingleOverload;
8695
/** This comment should appear for nonExportedFoo*/
8796
function nonExportedFoo() {
8897
}
@@ -134,6 +143,7 @@ export declare function fooWithParameters(/** this is comment about a*/ a: strin
134143
export declare function fooWithRestParameters(a: string, ...rests: string[]): string;
135144
export declare function fooWithOverloads(a: string): string;
136145
export declare function fooWithOverloads(a: number): number;
146+
export declare function fooWithSingleOverload(a: string): string;
137147
//// [declFileFunctions_1.d.ts]
138148
/** This comment should appear for foo*/
139149
declare function globalfoo(): void;

tests/baselines/reference/declFileFunctions.types

+12
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ export function fooWithOverloads(a: any): any {
4747
>a : any
4848
}
4949

50+
export function fooWithSingleOverload(a: string): string;
51+
>fooWithSingleOverload : (a: string) => string
52+
>a : string
53+
54+
export function fooWithSingleOverload(a: any) {
55+
>fooWithSingleOverload : (a: string) => string
56+
>a : any
57+
58+
return a;
59+
>a : any
60+
}
61+
5062
/** This comment should appear for nonExportedFoo*/
5163
function nonExportedFoo() {
5264
>nonExportedFoo : () => void

tests/cases/compiler/declFileFunctions.ts

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ export function fooWithOverloads(a: any): any {
2323
return a;
2424
}
2525

26+
export function fooWithSingleOverload(a: string): string;
27+
export function fooWithSingleOverload(a: any) {
28+
return a;
29+
}
30+
2631
/** This comment should appear for nonExportedFoo*/
2732
function nonExportedFoo() {
2833
}

0 commit comments

Comments
 (0)