You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
User-defined type guards seemingly unused when given an intersection type #10144
interfaceFoo{x: number;s: string;}interfaceBar{y: number;z: number;}interfaceHasNum{a: number;}typeFooOrBar=Foo|Bar;typeFooOrBarWithNum=FooOrBar&HasNum;functionis_foo(f: FooOrBar): f is Foo{return(fasFoo).x!==undefined;}letobj: FooOrBarWithNum={a: 5,x: 5,s: "hello"};if(is_foo(obj)){obj.x;// ERROR: Property 'x' does not exist on type (Foo | Bar) & HasNum}letobj_2: FooOrBar=obj;// Cast it back to just a FooOrBar.if(is_foo(obj_2)){obj_2.x;// This compiles just fine.}
Expected behavior:
I would expect obj to have type Foo inside of the if-block.
Actual behavior: obj is not refined, but obj_2 is.
changed the title [-]User-defined type guards broken when used with Intersection Types[/-][+]User-defined type guards seemingly unused when used with Intersection Types[/+]on Aug 4, 2016
changed the title [-]User-defined type guards seemingly unused when used with Intersection Types[/-][+]User-defined type guards seemingly unused when given an intersection type[/+]on Aug 4, 2016
Activity
[-]User-defined type guards broken when used with Intersection Types[/-][+]User-defined type guards seemingly unused when used with Intersection Types[/+][-]User-defined type guards seemingly unused when used with Intersection Types[/-][+]User-defined type guards seemingly unused when given an intersection type[/+]yortus commentedon Aug 4, 2016
This looks related to or a duplicate of #9919
yortus commentedon Oct 21, 2016
This works now. Fixed by #11717.