File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -77,4 +77,23 @@ function foo(x: A | undefined) {
77
77
x ; // A
78
78
}
79
79
x ; // A
80
+ }
81
+
82
+ // X is neither assignable to Y nor a subtype of Y
83
+ // Y is assignable to X, but not a subtype of X
84
+
85
+ interface X {
86
+ x ?: string ;
87
+ }
88
+
89
+ class Y {
90
+ y : string ;
91
+ }
92
+
93
+ function goo ( x : X ) {
94
+ x ;
95
+ if ( x instanceof Y ) {
96
+ x . y ;
97
+ }
98
+ x ;
80
99
}
Original file line number Diff line number Diff line change
1
+ // Repro from #10145
2
+
3
+ interface A { type : 'A' }
4
+ interface B { type : 'B' }
5
+
6
+ function isA ( x : A | B ) : x is A { return x . type === 'A' ; }
7
+ function isB ( x : A | B ) : x is B { return x . type === 'B' ; }
8
+
9
+ function foo1 ( x : A | B ) : any {
10
+ x ; // A | B
11
+ if ( isA ( x ) ) {
12
+ return x ; // A
13
+ }
14
+ x ; // B
15
+ if ( isB ( x ) ) {
16
+ return x ; // B
17
+ }
18
+ x ; // never
19
+ }
20
+
21
+ function foo2 ( x : A | B ) : any {
22
+ x ; // A | B
23
+ if ( x . type === 'A' ) {
24
+ return x ; // A
25
+ }
26
+ x ; // B
27
+ if ( x . type === 'B' ) {
28
+ return x ; // B
29
+ }
30
+ x ; // never
31
+ }
You can’t perform that action at this time.
0 commit comments