Skip to content

Commit 15a46bb

Browse files
authored
fix(45489): add test to cover comparison operator with intersection type (microsoft#45936)
1 parent ec114b8 commit 15a46bb

5 files changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIntersectionType.ts(2,1): error TS2365: Operator '>' cannot be applied to types '{ a: 1; }' and 'number'.
2+
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIntersectionType.ts(5,1): error TS2365: Operator '>' cannot be applied to types '{ a: 1; } & { b: number; }' and 'number'.
3+
4+
5+
==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIntersectionType.ts (2 errors) ====
6+
declare let a: { a: 1 }
7+
a > 1;
8+
~~~~~
9+
!!! error TS2365: Operator '>' cannot be applied to types '{ a: 1; }' and 'number'.
10+
11+
declare let b: { a: 1 } & { b: number }
12+
b > 1;
13+
~~~~~
14+
!!! error TS2365: Operator '>' cannot be applied to types '{ a: 1; } & { b: number; }' and 'number'.
15+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [comparisonOperatorWithIntersectionType.ts]
2+
declare let a: { a: 1 }
3+
a > 1;
4+
5+
declare let b: { a: 1 } & { b: number }
6+
b > 1;
7+
8+
9+
//// [comparisonOperatorWithIntersectionType.js]
10+
a > 1;
11+
b > 1;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIntersectionType.ts ===
2+
declare let a: { a: 1 }
3+
>a : Symbol(a, Decl(comparisonOperatorWithIntersectionType.ts, 0, 11))
4+
>a : Symbol(a, Decl(comparisonOperatorWithIntersectionType.ts, 0, 16))
5+
6+
a > 1;
7+
>a : Symbol(a, Decl(comparisonOperatorWithIntersectionType.ts, 0, 11))
8+
9+
declare let b: { a: 1 } & { b: number }
10+
>b : Symbol(b, Decl(comparisonOperatorWithIntersectionType.ts, 3, 11))
11+
>a : Symbol(a, Decl(comparisonOperatorWithIntersectionType.ts, 3, 16))
12+
>b : Symbol(b, Decl(comparisonOperatorWithIntersectionType.ts, 3, 27))
13+
14+
b > 1;
15+
>b : Symbol(b, Decl(comparisonOperatorWithIntersectionType.ts, 3, 11))
16+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIntersectionType.ts ===
2+
declare let a: { a: 1 }
3+
>a : { a: 1; }
4+
>a : 1
5+
6+
a > 1;
7+
>a > 1 : boolean
8+
>a : { a: 1; }
9+
>1 : 1
10+
11+
declare let b: { a: 1 } & { b: number }
12+
>b : { a: 1; } & { b: number; }
13+
>a : 1
14+
>b : number
15+
16+
b > 1;
17+
>b > 1 : boolean
18+
>b : { a: 1; } & { b: number; }
19+
>1 : 1
20+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare let a: { a: 1 }
2+
a > 1;
3+
4+
declare let b: { a: 1 } & { b: number }
5+
b > 1;

0 commit comments

Comments
 (0)