Skip to content

Type inference broke down in Visual Studio 2017 #14629

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
ArtemAvramenko opened this issue Mar 13, 2017 · 3 comments
Closed

Type inference broke down in Visual Studio 2017 #14629

ArtemAvramenko opened this issue Mar 13, 2017 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@ArtemAvramenko
Copy link

TypeScript Version: 2.1.1

Code

class A {

    func(callback: () => void);
    func(callback: (code: number) => void);
    func(callback: Function) {
    }

    test() {
        this.func(code => { });
    }
}

Expected behavior:
typeinference2015

Actual behavior:
typeinference2017

@mhegazy
Copy link
Contributor

mhegazy commented Mar 13, 2017

If i were to guess, your VS 2015 was using 2.0 or earlier, your VS 2017 is using 2.1. If so, you can find more details about this in #11936.

it has always been any, the parameter help was showing the wrong overload in this case, but at build time the type was any silently, with TS 2.1, you should get an error under --noImplicitAny.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Mar 13, 2017
@ArtemAvramenko
Copy link
Author

Why it is any? Function has two overloads, one of them is parameterless. If I specify parameter, it is definitely second overload with number parameter.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 13, 2017

#11936 has discussion on why overload resolution works this way. it is mostly a design limitation. It is important to note, that previously it was any (though your hover in VS told you it was number), now it is still any, but will consistently report an error if --noImplicitany is enabled.

@mhegazy mhegazy closed this as completed Apr 21, 2017
@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants