Skip to content

signature overloading breaking change? #6397

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

Closed
Artazor opened this issue Jan 8, 2016 · 3 comments
Closed

signature overloading breaking change? #6397

Artazor opened this issue Jan 8, 2016 · 3 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@Artazor
Copy link
Contributor

Artazor commented Jan 8, 2016

Looks like that in 1.7.5 overloading order became significant in some cases

  1. specific first
declare class A {
    f(x:string): any;
    f(x:{[key: string]: any}): A;
}

var a: A;
var x = a.f("A") + 1;  // OK in both TS 1.7.5 and TS 1.5.3
  1. specific second
declare class A {
    f(x:{[key: string]: any}): A;
    f(x:string): any;
}

var a: A;
var x = a.f("A") + 1; // Fails on TS 1.7.5 (Worked on 1.5.3). Inferred f result as A

Is it by design?

@ahejlsberg
Copy link
Member

Yes, it is by design. Specifically, it is an effect of the change in #4074.

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Jan 8, 2016
@RyanCavanaugh
Copy link
Member

Overloading has always been order-sensitive -- the first signature that matches is the one that's selected.

Recommended fix would be to replace [key: string]: any with [key: string]: {}

@Artazor
Copy link
Contributor Author

Artazor commented Jan 8, 2016

@ahejlsberg, @RyanCavanaugh - thank you for explanation

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants