diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9f88df3aa8dad..5316b16eb6689 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7093,7 +7093,20 @@ module ts { function isImplementationOfOverload(node: FunctionDeclaration) { if (node.body) { var symbol = getSymbolOfNode(node); - return getSignaturesOfSymbol(symbol).length > 1; + var signaturesOfSymbol = getSignaturesOfSymbol(symbol); + // If this function body corresponds to function with multiple signature, it is implementation of overload + // eg: function foo(a: string): string; + // function foo(a: number): number; + // function foo(a: any) { // This is implementation of the overloads + // return a; + // } + return signaturesOfSymbol.length > 1 || + // If there is single signature for the symbol, it is overload if that signature isnt coming from the node + // eg: function foo(a: string): string; + // function foo(a: any) { // This is implementation of the overloads + // return a; + // } + (signaturesOfSymbol.length === 1 && signaturesOfSymbol[0].declaration !== node); } return false; } diff --git a/tests/baselines/reference/declFileFunctions.js b/tests/baselines/reference/declFileFunctions.js index b5018e1fb1d67..da1917163e186 100644 --- a/tests/baselines/reference/declFileFunctions.js +++ b/tests/baselines/reference/declFileFunctions.js @@ -21,6 +21,11 @@ export function fooWithOverloads(a: any): any { return a; } +export function fooWithSingleOverload(a: string): string; +export function fooWithSingleOverload(a: any) { + return a; +} + /** This comment should appear for nonExportedFoo*/ function nonExportedFoo() { } @@ -83,6 +88,10 @@ function fooWithOverloads(a) { return a; } exports.fooWithOverloads = fooWithOverloads; +function fooWithSingleOverload(a) { + return a; +} +exports.fooWithSingleOverload = fooWithSingleOverload; /** This comment should appear for nonExportedFoo*/ function nonExportedFoo() { } @@ -134,6 +143,7 @@ export declare function fooWithParameters(/** this is comment about a*/ a: strin export declare function fooWithRestParameters(a: string, ...rests: string[]): string; export declare function fooWithOverloads(a: string): string; export declare function fooWithOverloads(a: number): number; +export declare function fooWithSingleOverload(a: string): string; //// [declFileFunctions_1.d.ts] /** This comment should appear for foo*/ declare function globalfoo(): void; diff --git a/tests/baselines/reference/declFileFunctions.types b/tests/baselines/reference/declFileFunctions.types index 46281813eb081..bfbe658a7583c 100644 --- a/tests/baselines/reference/declFileFunctions.types +++ b/tests/baselines/reference/declFileFunctions.types @@ -47,6 +47,18 @@ export function fooWithOverloads(a: any): any { >a : any } +export function fooWithSingleOverload(a: string): string; +>fooWithSingleOverload : (a: string) => string +>a : string + +export function fooWithSingleOverload(a: any) { +>fooWithSingleOverload : (a: string) => string +>a : any + + return a; +>a : any +} + /** This comment should appear for nonExportedFoo*/ function nonExportedFoo() { >nonExportedFoo : () => void diff --git a/tests/cases/compiler/declFileFunctions.ts b/tests/cases/compiler/declFileFunctions.ts index ead3fdd1f254c..e7ce3d07f8202 100644 --- a/tests/cases/compiler/declFileFunctions.ts +++ b/tests/cases/compiler/declFileFunctions.ts @@ -23,6 +23,11 @@ export function fooWithOverloads(a: any): any { return a; } +export function fooWithSingleOverload(a: string): string; +export function fooWithSingleOverload(a: any) { + return a; +} + /** This comment should appear for nonExportedFoo*/ function nonExportedFoo() { }