Skip to content
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

Specialized function overloading (type guards) #15885

Closed
olegdunkan opened this issue May 16, 2017 · 2 comments
Closed

Specialized function overloading (type guards) #15885

olegdunkan opened this issue May 16, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@olegdunkan
Copy link

olegdunkan commented May 16, 2017

Sorry, It maybe duplicate, but I can't find an issue.
Let we have this code:

class C {
    x:number;
}
function fn(name:"a" );
function fn(name:"b", x:string );
function fn(name:"c", x:C);
function fn(name:"a"|"b"|"c", x?:string|C) {
    if (name ==="c") {
        x.x = 1; //error     
    }
}

We can infer that x has C type inside "c" = true branch of the condition.
Is there special type guard for this case?
If isn't then are there any plans to support this behavior?

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 16, 2017
@RyanCavanaugh
Copy link
Member

#14515

@olegdunkan
Copy link
Author

@RyanCavanaugh thanks

@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

2 participants