Skip to content

CFA not work in function #13142

Description

@k8w

TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)
2.1.4

Code

let f:string | null = 'xx';
let v:string;
if(f){
    [].forEach(item=>{
        v = f;
    })
}

Expected behavior:
Compile successfully

Actual behavior:

test.ts(5,9): error TS2322: Type 'string | null' is not assignable to type 'string'.
Type 'null' is not assignable to type 'string'.

Activity

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

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