8000 Added tests specifically for assignment compatibility between types w… · fleurdeswift/TypeScript@b10733b · GitHub
[go: up one dir, main page]

Skip to content

Commit b10733b

Browse files
Added tests specifically for assignment compatibility between types with call signatures returning type predicate types.
1 parent 57a3d2b commit b10733b

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// @declaration: true
2+
3+
class A {
4+
private a;
5+
}
6+
7+
class B extends A {
8+
private b;
9+
}
10+
11+
function isA(x: any): x is A {
12+
return x instanceof A;
13+
}
14+
15+
function isB(x: any): x is B {
16+
return x instanceof B;
17+
}
18+
19+
let myIsA = isA;
20+
let myIsB = isB;
21+
22+
myIsA = myIsB;
23+
myIsB = myIsA;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @declaration: true
2+
3+
class A {
4+
private a;
5+
}
6+
7+
function isA(x: any): x is A {
8+
return x instanceof A;
9+
}
10+
11+
function isAny(x: any): x is any {
12+
return x instanceof B;
13+
}
14+
15+
let myIsA = isA;
16+
let myIsAny = isAny;
17+
18+
myIsA = myIsAny;
19+
myIsAny = myIsA;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// @declaration: true
2+
3+
interface A {
4+
a?;
5+
}
6+
7+
interface B {
8+
}
9+
10+
function isA(x: any): x is A {
11+
return !!(<A>x).a;
12+
}
13+
14+
function isB(x: any): x is B {
15+
return !!isA(x);
16+
}
17+
18+
let myIsA = isA;
19+
let myIsAny = isB;
20+
21+
myIsA = myIsAny;
22+
myIsAny = myIsA;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// @declaration: true
2+
3+
enum E {
4+
A = 1,
5+
B = 2,
6+
C = 3,
7+
}
8+
9+
function isA(x: any): x is number {
10+
return typeof x === "number";
11+
}
12+
13+
function isB(x: any): x is E {
14+
switch (x) {
15+
case E.A:
16+
case E.B:
17< 6D8B code class="diff-text syntax-highlighted-line addition">+
case E.C:
18+
return true;
19+
}
20+
return false;
21+
}
22+
23+
let myIsA = isA;
24+
let myIsB = isB;
25+
26+
myIsA = myIsB;
27+
myIsB = myIsA;

0 commit comments

Comments
 (0)
0