Skip to content

Null assertion operator blocking control flow anlysis #23662

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
mhegazy opened this issue Apr 24, 2018 · 5 comments
Closed

Null assertion operator blocking control flow anlysis #23662

mhegazy opened this issue Apr 24, 2018 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@mhegazy
Copy link
Contributor

mhegazy commented Apr 24, 2018

TypeScript Version: 2.9.0-dev.20180422

Search Terms:

Code

class Base { b!: number }
class Derived extends Base { d!: number; }    

declare var x: Base | undefined;

declare function isDerived(x: any): x is Derived;


if (x) { 
    if (isDerived(x!)) { 
        x // Base;
    }
    if (isDerived(x)) {
        x // Derived;
    }
}

Expected behavior:

x in both instances should have the same type.

Actual behavior:

x has two different types based on whether null assertion operator was used or not.

@mhegazy mhegazy added the Bug A bug in TypeScript label Apr 24, 2018
@RyanCavanaugh
Copy link
Member

#15655 ?

@RyanCavanaugh
Copy link
Member

Eh not quite. But I think there is a dupe of this somewhere

@mhegazy
Copy link
Contributor Author

mhegazy commented Apr 25, 2018

Eh not quite. But I think there is a dupe of this somewhere

yeah.. i remember seeing this before, but could not find it. my search skills are not what they used to be..

@ghost
Copy link

ghost commented Jul 24, 2018

Duplicate of #15655 (thanks @rubenlg)

@ghost ghost marked this as a duplicate of #15655 Jul 24, 2018
@ghost ghost added Duplicate An existing issue was already created and removed In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Jul 24, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants