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

Skip to content

Correct the declaration emit for overload implementation if there is single overload signature #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/baselines/reference/declFileFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand Down Expand Up @@ -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() {
}
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions tests/baselines/reference/declFileFunctions.types
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/cases/compiler/declFileFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand Down