Skip to content

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

Closed
@falsandtru

Description

@falsandtru

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:

Metadata

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