Skip to content

Type Gaurds Don't Narrow Type in Inner Functions #10927

Description

TypeScript Version: 2.0.2

Code

functionisNumber(test: number|string): test is number{returntypeoftest==="number";}functionblah(arg: ()=>void): void{}letx: any=4;if(isNumber(x)){x;// x is correctly narrowed to number hereblah(()=>{x;// typeof x is any again})}

Expected behavior:
(I think) x should still be inferred as type number in the inner function.

Actual behavior:
x is inferred as any

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions