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

type guards can not work #4324

Closed
zpdDG4gta8XKpMCd opened this issue Aug 15, 2015 · 2 comments
Closed

type guards can not work #4324

zpdDG4gta8XKpMCd opened this issue Aug 15, 2015 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@zpdDG4gta8XKpMCd
Copy link

interface A { x : number; }
interface B { y: string; }
type C = A | B;
function isA(value: C): value is A {
    return 'x' in value;
}
var c: C = {x : 1 };
if (isA(c)) {
    c.x = 10; // <-- breakes here
} else {
    c = null; // <-- why is it a crime to assign null to c?
}
@tinganho
Copy link
Contributor

I think this might be related to that assignments is not allowed on type guards or they will revert back to the original type?

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 18, 2015
@RyanCavanaugh
Copy link
Member

Assignments to c "turn off" type guards everywhere because we don't yet use control flow analysis to detect that the else branch does not affect the consequent branch.

See #2388

@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

3 participants