Skip to content

Strange boolean-discriminant narrowing with strictNullChecks off #10564

Description

@gcnew

TypeScript Version: nightly (2.1.0-dev.20160826)

Code

typeResult={success: true}|{success: false,error: string}functionhandleError(res: Result){if(res.success===true){return;}res.error;// OK}functionhandleError2(res: Result){if(res.success!==false){return;}res.error;// OK}functionhandleError3(res: Result){if(res.success){return;}res.error;// Property 'error' does not exist on type 'Result'// but should be OK}

Expected behavior:
All three cases should behave the same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: check: Control FlowThe issue relates to control flow analysisEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions