fix(45489): add test to cover comparison operator with intersection type (#45936)

This commit is contained in:
Oleksandr T 2021-09-21 02:35:55 +03:00 committed by GitHub
parent ec114b8931
commit 15a46bb72d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,15 @@
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIntersectionType.ts(2,1): error TS2365: Operator '>' cannot be applied to types '{ a: 1; }' and 'number'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIntersectionType.ts(5,1): error TS2365: Operator '>' cannot be applied to types '{ a: 1; } & { b: number; }' and 'number'.
==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIntersectionType.ts (2 errors) ====
declare let a: { a: 1 }
a > 1;
~~~~~
!!! error TS2365: Operator '>' cannot be applied to types '{ a: 1; }' and 'number'.
declare let b: { a: 1 } & { b: number }
b > 1;
~~~~~
!!! error TS2365: Operator '>' cannot be applied to types '{ a: 1; } & { b: number; }' and 'number'.

View File

@ -0,0 +1,11 @@
//// [comparisonOperatorWithIntersectionType.ts]
declare let a: { a: 1 }
a > 1;
declare let b: { a: 1 } & { b: number }
b > 1;
//// [comparisonOperatorWithIntersectionType.js]
a > 1;
b > 1;

View File

@ -0,0 +1,16 @@
=== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIntersectionType.ts ===
declare let a: { a: 1 }
>a : Symbol(a, Decl(comparisonOperatorWithIntersectionType.ts, 0, 11))
>a : Symbol(a, Decl(comparisonOperatorWithIntersectionType.ts, 0, 16))
a > 1;
>a : Symbol(a, Decl(comparisonOperatorWithIntersectionType.ts, 0, 11))
declare let b: { a: 1 } & { b: number }
>b : Symbol(b, Decl(comparisonOperatorWithIntersectionType.ts, 3, 11))
>a : Symbol(a, Decl(comparisonOperatorWithIntersectionType.ts, 3, 16))
>b : Symbol(b, Decl(comparisonOperatorWithIntersectionType.ts, 3, 27))
b > 1;
>b : Symbol(b, Decl(comparisonOperatorWithIntersectionType.ts, 3, 11))

View File

@ -0,0 +1,20 @@
=== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithIntersectionType.ts ===
declare let a: { a: 1 }
>a : { a: 1; }
>a : 1
a > 1;
>a > 1 : boolean
>a : { a: 1; }
>1 : 1
declare let b: { a: 1 } & { b: number }
>b : { a: 1; } & { b: number; }
>a : 1
>b : number
b > 1;
>b > 1 : boolean
>b : { a: 1; } & { b: number; }
>1 : 1

View File

@ -0,0 +1,5 @@
declare let a: { a: 1 }
a > 1;
declare let b: { a: 1 } & { b: number }
b > 1;