Add switch comparability test and update baselines
This commit is contained in:
parent
00ebf59b50
commit
982abc2944
|
@ -1,4 +1,4 @@
|
|||
tests/cases/compiler/switchAssignmentCompat.ts(4,10): error TS2678: Type 'typeof Foo' is not comparable to type '0'.
|
||||
tests/cases/compiler/switchAssignmentCompat.ts(4,10): error TS2678: Type 'typeof Foo' is not comparable to type 'number'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/switchAssignmentCompat.ts (1 errors) ====
|
||||
|
@ -7,6 +7,6 @@ tests/cases/compiler/switchAssignmentCompat.ts(4,10): error TS2678: Type 'typeof
|
|||
switch (0) {
|
||||
case Foo: break; // Error expected
|
||||
~~~
|
||||
!!! error TS2678: Type 'typeof Foo' is not comparable to type '0'.
|
||||
!!! error TS2678: Type 'typeof Foo' is not comparable to type 'number'.
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
tests/cases/compiler/switchCaseCircularRefeference.ts(5,10): error TS2678: Type '{ a: "A"; b: any; } | { a: "C"; e: any; }' is not comparable to type '"A" | "C"'.
|
||||
Type '{ a: "C"; e: any; }' is not comparable to type '"A" | "C"'.
|
||||
Type '{ a: "C"; e: any; }' is not comparable to type '"C"'.
|
||||
tests/cases/compiler/switchCaseCircularRefeference.ts(5,10): error TS2678: Type '{ a: "A"; b: any; } | { a: "C"; e: any; }' is not comparable to type 'string'.
|
||||
Type '{ a: "C"; e: any; }' is not comparable to type 'string'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/switchCaseCircularRefeference.ts (1 errors) ====
|
||||
|
@ -10,9 +9,8 @@ tests/cases/compiler/switchCaseCircularRefeference.ts(5,10): error TS2678: Type
|
|||
switch (x.a) {
|
||||
case x:
|
||||
~
|
||||
!!! error TS2678: Type '{ a: "A"; b: any; } | { a: "C"; e: any; }' is not comparable to type '"A" | "C"'.
|
||||
!!! error TS2678: Type '{ a: "C"; e: any; }' is not comparable to type '"A" | "C"'.
|
||||
!!! error TS2678: Type '{ a: "C"; e: any; }' is not comparable to type '"C"'.
|
||||
!!! error TS2678: Type '{ a: "A"; b: any; } | { a: "C"; e: any; }' is not comparable to type 'string'.
|
||||
!!! error TS2678: Type '{ a: "C"; e: any; }' is not comparable to type 'string'.
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -1,25 +1,22 @@
|
|||
tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(4,10): error TS2678: Type 'typeof Foo' is not comparable to type '0'.
|
||||
tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(5,10): error TS2678: Type '"sss"' is not comparable to type '0'.
|
||||
tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(6,10): error TS2678: Type '123' is not comparable to type '0'.
|
||||
tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2678: Type 'true' is not comparable to type '0'.
|
||||
tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(4,10): error TS2678: Type 'typeof Foo' is not comparable to type 'number'.
|
||||
tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(5,10): error TS2678: Type 'string' is not comparable to type 'number'.
|
||||
tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2678: Type 'boolean' is not comparable to type 'number'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/switchCasesExpressionTypeMismatch.ts (4 errors) ====
|
||||
==== tests/cases/compiler/switchCasesExpressionTypeMismatch.ts (3 errors) ====
|
||||
class Foo { }
|
||||
|
||||
switch (0) {
|
||||
case Foo: break; // Error
|
||||
~~~
|
||||
!!! error TS2678: Type 'typeof Foo' is not comparable to type '0'.
|
||||
!!! error TS2678: Type 'typeof Foo' is not comparable to type 'number'.
|
||||
case "sss": break; // Error
|
||||
~~~~~
|
||||
!!! error TS2678: Type '"sss"' is not comparable to type '0'.
|
||||
!!! error TS2678: Type 'string' is not comparable to type 'number'.
|
||||
case 123: break; // No Error
|
||||
~~~
|
||||
!!! error TS2678: Type '123' is not comparable to type '0'.
|
||||
case true: break; // Error
|
||||
~~~~
|
||||
!!! error TS2678: Type 'true' is not comparable to type '0'.
|
||||
!!! error TS2678: Type 'boolean' is not comparable to type 'number'.
|
||||
}
|
||||
|
||||
var s: any = 0;
|
||||
|
|
29
tests/baselines/reference/switchComparableCompatForBrands.js
Normal file
29
tests/baselines/reference/switchComparableCompatForBrands.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
//// [switchComparableCompatForBrands.ts]
|
||||
class MyBrand
|
||||
{
|
||||
private _a: number;
|
||||
}
|
||||
|
||||
function test(strInput: string & MyBrand) {
|
||||
switch(strInput)
|
||||
{
|
||||
case "a":
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//// [switchComparableCompatForBrands.js]
|
||||
var MyBrand = (function () {
|
||||
function MyBrand() {
|
||||
}
|
||||
return MyBrand;
|
||||
}());
|
||||
function test(strInput) {
|
||||
switch (strInput) {
|
||||
case "a":
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
=== tests/cases/compiler/switchComparableCompatForBrands.ts ===
|
||||
class MyBrand
|
||||
>MyBrand : Symbol(MyBrand, Decl(switchComparableCompatForBrands.ts, 0, 0))
|
||||
{
|
||||
private _a: number;
|
||||
>_a : Symbol(MyBrand._a, Decl(switchComparableCompatForBrands.ts, 1, 1))
|
||||
}
|
||||
|
||||
function test(strInput: string & MyBrand) {
|
||||
>test : Symbol(test, Decl(switchComparableCompatForBrands.ts, 3, 1))
|
||||
>strInput : Symbol(strInput, Decl(switchComparableCompatForBrands.ts, 5, 14))
|
||||
>MyBrand : Symbol(MyBrand, Decl(switchComparableCompatForBrands.ts, 0, 0))
|
||||
|
||||
switch(strInput)
|
||||
>strInput : Symbol(strInput, Decl(switchComparableCompatForBrands.ts, 5, 14))
|
||||
{
|
||||
case "a":
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
=== tests/cases/compiler/switchComparableCompatForBrands.ts ===
|
||||
class MyBrand
|
||||
>MyBrand : MyBrand
|
||||
{
|
||||
private _a: number;
|
||||
>_a : number
|
||||
}
|
||||
|
||||
function test(strInput: string & MyBrand) {
|
||||
>test : (strInput: string & MyBrand) => 1 | 0
|
||||
>strInput : string & MyBrand
|
||||
>MyBrand : MyBrand
|
||||
|
||||
switch(strInput)
|
||||
>strInput : string & MyBrand
|
||||
{
|
||||
case "a":
|
||||
>"a" : "a"
|
||||
|
||||
return 1;
|
||||
>1 : 1
|
||||
}
|
||||
return 0;
|
||||
>0 : 0
|
||||
}
|
||||
|
13
tests/cases/compiler/switchComparableCompatForBrands.ts
Normal file
13
tests/cases/compiler/switchComparableCompatForBrands.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
class MyBrand
|
||||
{
|
||||
private _a: number;
|
||||
}
|
||||
|
||||
function test(strInput: string & MyBrand) {
|
||||
switch(strInput)
|
||||
{
|
||||
case "a":
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue