Skip to content

Type guard doesn't work on import #12081

Closed

Description

TypeScript Version: nightly (2.1.0-dev.20161107)

Code

// @strictNullChecks: true

// @Filename: /node_modules/@types/foo/index.d.ts
declare const foo: { x: number } | undefined;
export default foo;

// @Filename: /a.ts
import foo from "foo";
foo && foo.x;

Expected behavior:

No error.

Actual behavior:

error TS2532: Object is possibly 'undefined'.

Activity

  1. ghost added
    BugA bug in TypeScript
    on Nov 7, 2016
  2. modified the milestones: TypeScript 2.3, on Mar 24, 2017
  3. ghost added
    FixedA PR has been merged for this issue
    on Jun 20, 2017
  4. mgroenhoff commented on Nov 21, 2017

    @mgroenhoff

    Awesome. Thanks! 👍

  5. modified the milestones: , TypeScript 2.7 on Nov 21, 2017
  6. 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