Skip to content

Flow analysis doesn't work with es6 collections 'has' method #13086

Open
@MastroLindus

Description

@MastroLindus

TypeScript Version: 2.1.1

Code

const x = new Map<string, string>();
x.set("key", "value");
if (x.has("key")) {
  const y : string = x.get("key");  // error: y is string | undefined, not string
}

Expected behavior:
y is narrowed down to string
Actual behavior:
y is still string | undefined even after checking if the map has that key

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions