Skip to content

Type narrowing doesn't work with mutable variables in closures #23776

Closed

Description

Includes arguments.

TypeScript Version: 2.9.0-dev.201xxxxx

Search Terms:

Code

declare const a: {} | void;
if (a instanceof Object) a; // {}
if (a instanceof Object) () => a; // {}
declare let b: {} | void;
if (b instanceof Object) b; // {}
if (b instanceof Object) () => b;

Expected behavior:

if (b instanceof Object) () => b; // {}

Actual behavior:

if (b instanceof Object) () => b; // void | {}

Playground Link:

Related Issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions