Skip to content

Commit c623e6c

Browse files
committed
Adding a few more tests
1 parent 529fcfd commit c623e6c

File tree

7 files changed

+166
-0
lines changed

7 files changed

+166
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [contextualIntersectionType.ts]
2+
var x: { a: (s: string) => string } & { b: (n: number) => number };
3+
x = {
4+
a: s => s,
5+
b: n => n
6+
};
7+
8+
9+
//// [contextualIntersectionType.js]
10+
var x;
11+
x = {
12+
a: function (s) { return s; },
13+
b: function (n) { return n; }
14+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== tests/cases/conformance/types/intersection/contextualIntersectionType.ts ===
2+
var x: { a: (s: string) => string } & { b: (n: number) => number };
3+
>x : Symbol(x, Decl(contextualIntersectionType.ts, 0, 3))
4+
>a : Symbol(a, Decl(contextualIntersectionType.ts, 0, 8))
5+
>s : Symbol(s, Decl(contextualIntersectionType.ts, 0, 13))
6+
>b : Symbol(b, Decl(contextualIntersectionType.ts, 0, 39))
7+
>n : Symbol(n, Decl(contextualIntersectionType.ts, 0, 44))
8+
9+
x = {
10+
>x : Symbol(x, Decl(contextualIntersectionType.ts, 0, 3))
11+
12+
a: s => s,
13+
>a : Symbol(a, Decl(contextualIntersectionType.ts, 1, 5))
14+
>s : Symbol(s, Decl(contextualIntersectionType.ts, 2, 6))
15+
>s : Symbol(s, Decl(contextualIntersectionType.ts, 2, 6))
16+
17+
b: n => n
18+
>b : Symbol(b, Decl(contextualIntersectionType.ts, 2, 14))
19+
>n : Symbol(n, Decl(contextualIntersectionType.ts, 3, 6))
20+
>n : Symbol(n, Decl(contextualIntersectionType.ts, 3, 6))
21+
22+
};
23+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
=== tests/cases/conformance/types/intersection/contextualIntersectionType.ts ===
2+
var x: { a: (s: string) => string } & { b: (n: number) => number };
3+
>x : { a: (s: string) => string; } & { b: (n: number) => number; }
4+
>a : (s: string) => string
5+
>s : string
6+
>b : (n: number) => number
7+
>n : number
8+
9+
x = {
10+
>x = { a: s => s, b: n => n} : { a: (s: string) => string; b: (n: number) => number; }
11+
>x : { a: (s: string) => string; } & { b: (n: number) => number; }
12+
>{ a: s => s, b: n => n} : { a: (s: string) => string; b: (n: number) => number; }
13+
14+
a: s => s,
15+
>a : (s: string) => string
16+
>s => s : (s: string) => string
17+
>s : string
18+
>s : string
19+
20+
b: n => n
21+
>b : (n: number) => number
22+
>n => n : (n: number) => number
23+
>n : number
24+
>n : number
25+
26+
};
27+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
tests/cases/conformance/types/intersection/intersectionTypeAssignment.ts(8,1): error TS2322: Type '{ a: string; }' is not assignable to type '{ a: string; b: string; }'.
2+
Property 'b' is missing in type '{ a: string; }'.
3+
tests/cases/conformance/types/intersection/intersectionTypeAssignment.ts(9,1): error TS2322: Type '{ a: string; }' is not assignable to type '{ a: string; } & { b: string; }'.
4+
Type '{ a: string; }' is not assignable to type '{ b: string; }'.
5+
Property 'b' is missing in type '{ a: string; }'.
6+
tests/cases/conformance/types/intersection/intersectionTypeAssignment.ts(13,1): error TS2322: Type '{ b: string; }' is not assignable to type '{ a: string; b: string; }'.
7+
Property 'a' is missing in type '{ b: string; }'.
8+
tests/cases/conformance/types/intersection/intersectionTypeAssignment.ts(14,1): error TS2322: Type '{ b: string; }' is not assignable to type '{ a: string; } & { b: string; }'.
9+
Type '{ b: string; }' is not assignable to type '{ a: string; }'.
10+
Property 'a' is missing in type '{ b: string; }'.
11+
12+
13+
==== tests/cases/conformance/types/intersection/intersectionTypeAssignment.ts (4 errors) ====
14+
var a: { a: string };
15+
var b: { b: string };
16+
var x: { a: string, b: string };
17+
var y: { a: string } & { b: string };
18+
19+
a = x;
20+
a = y;
21+
x = a; // Error
22+
~
23+
!!! error TS2322: Type '{ a: string; }' is not assignable to type '{ a: string; b: string; }'.
24+
!!! error TS2322: Property 'b' is missing in type '{ a: string; }'.
25+
y = a; // Error
26+
~
27+
!!! error TS2322: Type '{ a: string; }' is not assignable to type '{ a: string; } & { b: string; }'.
28+
!!! error TS2322: Type '{ a: string; }' is not assignable to type '{ b: string; }'.
29+
!!! error TS2322: Property 'b' is missing in type '{ a: string; }'.
30+
31+
b = x;
32+
b = y;
33+
x = b; // Error
34+
~
35+
!!! error TS2322: Type '{ b: string; }' is not assignable to type '{ a: string; b: string; }'.
36+
!!! error TS2322: Property 'a' is missing in type '{ b: string; }'.
37+
y = b; // Error
38+
~
39+
!!! error TS2322: Type '{ b: string; }' is not assignable to type '{ a: string; } & { b: string; }'.
40+
!!! error TS2322: Type '{ b: string; }' is not assignable to type '{ a: string; }'.
41+
!!! error TS2322: Property 'a' is missing in type '{ b: string; }'.
42+
43+
x = y;
44+
y = x;
45+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//// [intersectionTypeAssignment.ts]
2+
var a: { a: string };
3+
var b: { b: string };
4+
var x: { a: string, b: string };
5+
var y: { a: string } & { b: string };
6+
7+
a = x;
8+
a = y;
9+
x = a; // Error
10+
y = a; // Error
11+
12+
b = x;
13+
b = y;
14+
x = b; // Error
15+
y = b; // Error
16+
17+
x = y;
18+
y = x;
19+
20+
21+
//// [intersectionTypeAssignment.js]
22+
var a;
23+
var b;
24+
var x;
25+
var y;
26+
a = x;
27+
a = y;
28+
x = a; // Error
29+
y = a; // Error
30+
b = x;
31+
b = y;
32+
x = b; // Error
33+
y = b; // Error
34+
x = y;
35+
y = x;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var x: { a: (s: string) => string } & { b: (n: number) => number };
2+
x = {
3+
a: s => s,
4+
b: n => n
5+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var a: { a: string };
2+
var b: { b: string };
3+
var x: { a: string, b: string };
4+
var y: { a: string } & { b: string };
5+
6+
a = x;
7+
a = y;
8+
x = a; // Error
9+
y = a; // Error
10+
11+
b = x;
12+
b = y;
13+
x = b; // Error
14+
y = b; // Error
15+
16+
x = y;
17+
y = x;

0 commit comments

Comments
 (0)