Skip to content

Cannot infer right type from overload functions #16689

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
k8w opened this issue Jun 22, 2017 · 3 comments
Closed

Cannot infer right type from overload functions #16689

k8w opened this issue Jun 22, 2017 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@k8w
Copy link

k8w commented Jun 22, 2017

TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
2.4.0

Code

interface Test{
    show(): string;
    show(arg: (a:string)=>void): void;
    show(arg: (a:string, b:number)=>void): void;
}

declare let t:Test;

t.show();
t.show(a=>{});
t.show((a,b)=>{});

Expected behavior:
Compile success.
Both a=>{} and (a,b)=>{} can infer right type to a and b instead of implicitly has an 'any' type

Actual behavior:

index.ts(11,9): error TS7006: Parameter 'a' implicitly has an 'any' type.
index.ts(11,11): error TS7006: Parameter 'b' implicitly has an 'any' type.

@kitsonk
Copy link
Contributor

kitsonk commented Jun 22, 2017

Don't over complicated things:

interface Test{
    show(arg?: (a:string, b?:number)=>void): void;
}

declare let t:Test;

t.show();
t.show(a=>{});
t.show((a, b) => { });

@RyanCavanaugh
Copy link
Member

Duplicate #11936

Note: Don't mark callback parameters as optional

interface Test{
    show(arg?: (a:string, b:number)=>void): void;
}

declare let t:Test;

t.show();
t.show(a=>{});
t.show((a, b) => { });

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 22, 2017
@kitsonk
Copy link
Contributor

kitsonk commented Jun 22, 2017

Note: Don't mark callback parameters as optional

Ooops, sorry, yes I forgot.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 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

3 participants