Skip to content

Type narrowing is not allowed if variable is reassigned after the use site inside if block #1764

Closed
@vladima

Description

@vladima

Current implementation is very conservative when looking for assignments during application of type narrowing.

function len(x: number | string) {
     if (typeof x === 'number') {
         var t = x.toExponential();
         //x = "aaaa"; // uncomment me
     }
}

variable is reassigned after the usage of narrowed type but type narrowing still not kicked in

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions