Skip to content

narrowing an undefined | A property not working anymore #10169

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
zpdDG4gta8XKpMCd opened this issue Aug 5, 2016 · 1 comment
Closed

narrowing an undefined | A property not working anymore #10169

zpdDG4gta8XKpMCd opened this issue Aug 5, 2016 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@zpdDG4gta8XKpMCd
Copy link

nightly build August 5, 2016

function noUnnecessaryTypeAnnotations(node: ts.Node, checker: ts.TypeChecker): Issue | void {
    if (isVariableDeclaration(node)) {
        if (node.initializer !== undefined && node.type !== undefined) {
            node.initializer; // <-- expected: Expression; actual: Expression | undefined
        }
   }
}
@ahejlsberg
Copy link
Member

ahejlsberg commented Aug 5, 2016

The issue here is that the checker thinks node.type !== undefined might be a discriminant type guard, so it resets other type guards for properties of the form node.xxx. A workaround would be to reverse the two type guards (but of course you'll then have the same problem for node.type).

@ahejlsberg ahejlsberg added the Bug A bug in TypeScript label Aug 5, 2016
@ahejlsberg ahejlsberg added this to the TypeScript 2.0.1 milestone Aug 5, 2016
@ahejlsberg ahejlsberg self-assigned this Aug 6, 2016
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Aug 8, 2016
@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
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

2 participants