Skip to content

narrowing an undefined | A property not working anymore #10169

Closed

Description

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
        }
   }
}

Activity

  1. ahejlsberg commented on Aug 5, 2016

    @ahejlsberg
    Member

    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).

  2. added this to the milestone on Aug 5, 2016
  3. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions