Skip to content

Commit cef9d85

Browse files
authored
Merge pull request #11765 from Microsoft/aozgaa/AddTestForComparingNumericLiteral
add test from comparing numeric literals to branded numbers
2 parents 3263fde + 9a9cbe1 commit cef9d85

File tree

3 files changed

+179
-0
lines changed

3 files changed

+179
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNumericLiteral.ts(5,1): error TS2365: Operator '>' cannot be applied to types 'BrandedNum' and '0'.
2+
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNumericLiteral.ts(10,1): error TS2365: Operator '<' cannot be applied to types 'BrandedNum' and '0'.
3+
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNumericLiteral.ts(15,1): error TS2365: Operator '>=' cannot be applied to types 'BrandedNum' and '0'.
4+
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNumericLiteral.ts(20,1): error TS2365: Operator '<=' cannot be applied to types 'BrandedNum' and '0'.
5+
6+
7+
==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNumericLiteral.ts (4 errors) ====
8+
type BrandedNum = number & { __numberBrand: any };
9+
var x : BrandedNum;
10+
11+
// operator >
12+
x > 0;
13+
~~~~~
14+
!!! error TS2365: Operator '>' cannot be applied to types 'BrandedNum' and '0'.
15+
x > <number>0;
16+
x > <BrandedNum>0;
17+
18+
// operator <
19+
x < 0;
20+
~~~~~
21+
!!! error TS2365: Operator '<' cannot be applied to types 'BrandedNum' and '0'.
22+
x < <number>0;
23+
x < <BrandedNum>0;
24+
25+
// operator >=
26+
x >= 0;
27+
~~~~~~
28+
!!! error TS2365: Operator '>=' cannot be applied to types 'BrandedNum' and '0'.
29+
x >= <number>0;
30+
x >= <BrandedNum>0;
31+
32+
// operator <=
33+
x <= 0;
34+
~~~~~~
35+
!!! error TS2365: Operator '<=' cannot be applied to types 'BrandedNum' and '0'.
36+
x <= <number>0;
37+
x <= <BrandedNum>0;
38+
39+
// operator ==
40+
x == 0;
41+
x == <number>0;
42+
x == <BrandedNum>0;
43+
44+
// operator !=
45+
x != 0;
46+
x != <number>0;
47+
x != <BrandedNum>0;
48+
49+
// operator ===
50+
x === 0;
51+
x === <number>0;
52+
x === <BrandedNum>0;
53+
54+
// operator !==
55+
x !== 0;
56+
x !== <number>0;
57+
x !== <BrandedNum>0;
58+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//// [comparisonOperatorWithNumericLiteral.ts]
2+
type BrandedNum = number & { __numberBrand: any };
3+
var x : BrandedNum;
4+
5+
// operator >
6+
x > 0;
7+
x > <number>0;
8+
x > <BrandedNum>0;
9+
10+
// operator <
11+
x < 0;
12+
x < <number>0;
13+
x < <BrandedNum>0;
14+
15+
// operator >=
16+
x >= 0;
17+
x >= <number>0;
18+
x >= <BrandedNum>0;
19+
20+
// operator <=
21+
x <= 0;
22+
x <= <number>0;
23+
x <= <BrandedNum>0;
24+
25+
// operator ==
26+
x == 0;
27+
x == <number>0;
28+
x == <BrandedNum>0;
29+
30+
// operator !=
31+
x != 0;
32+
x != <number>0;
33+
x != <BrandedNum>0;
34+
35+
// operator ===
36+
x === 0;
37+
x === <number>0;
38+
x === <BrandedNum>0;
39+
40+
// operator !==
41+
x !== 0;
42+
x !== <number>0;
43+
x !== <BrandedNum>0;
44+
45+
46+
//// [comparisonOperatorWithNumericLiteral.js]
47+
var x;
48+
// operator >
49+
x > 0;
50+
x > 0;
51+
x > 0;
52+
// operator <
53+
x < 0;
54+
x < 0;
55+
x < 0;
56+
// operator >=
57+
x >= 0;
58+
x >= 0;
59+
x >= 0;
60+
// operator <=
61+
x <= 0;
62+
x <= 0;
63+
x <= 0;
64+
// operator ==
65+
x == 0;
66+
x == 0;
67+
x == 0;
68+
// operator !=
69+
x != 0;
70+
x != 0;
71+
x != 0;
72+
// operator ===
73+
x === 0;
74+
x === 0;
75+
x === 0;
76+
// operator !==
77+
x !== 0;
78+
x !== 0;
79+
x !== 0;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
type BrandedNum = number & { __numberBrand: any };
2+
var x : BrandedNum;
3+
4+
// operator >
5+
x > 0;
6+
x > <number>0;
7+
x > <BrandedNum>0;
8+
9+
// operator <
10+
x < 0;
11+
x < <number>0;
12+
x < <BrandedNum>0;
13+
14+
// operator >=
15+
x >= 0;
16+
x >= <number>0;
17+
x >= <BrandedNum>0;
18+
19+
// operator <=
20+
x <= 0;
21+
x <= <number>0;
22+
x <= <BrandedNum>0;
23+
24+
// operator ==
25+
x == 0;
26+
x == <number>0;
27+
x == <BrandedNum>0;
28+
29+
// operator !=
30+
x != 0;
31+
x != <number>0;
32+
x != <BrandedNum>0;
33+
34+
// operator ===
35+
x === 0;
36+
x === <number>0;
37+
x === <BrandedNum>0;
38+
39+
// operator !==
40+
x !== 0;
41+
x !== <number>0;
42+
x !== <BrandedNum>0;

0 commit comments

Comments
 (0)