Tests to check equivalency of union types

A union type encompasses an unordered set of unrelated types (that is, types that aren’t subtypes of each other). The following rules govern union types:
•	A | B is equivalent to A if B is a subtype of A.
•	A | B is equivalent to B | A.
•	AB | C is equivalent to A | BC, where AB is A | B and BC is B | C.
This commit is contained in:
Sheetal Nandi
2014-11-03 09:20:20 -08:00
parent 7634f741d9
commit 568049474e
3 changed files with 121 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
//// [unionTypeEquivalence.ts]
// A | B is equivalent to A if B is a subtype of A
class C { }
class D extends C { }
var x: C;
var x : C | D;
// A | B is equivalent to B | A.
var y: string | number;
var y : number | string;
// AB | C is equivalent to A | BC, where AB is A | B and BC is B | C.
var z : string | number | boolean;
var z : (string | number) | boolean;
var z : string | (number | boolean);
var AB : string | number;
var BC : number | boolean;
var z1: typeof AB | boolean;
var z1: string | typeof BC;
//// [unionTypeEquivalence.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
// A | B is equivalent to A if B is a subtype of A
var C = (function () {
function C() {
}
return C;
})();
var D = (function (_super) {
__extends(D, _super);
function D() {
_super.apply(this, arguments);
}
return D;
})(C);
var x;
var x;
// A | B is equivalent to B | A.
var y;
var y;
// AB | C is equivalent to A | BC, where AB is A | B and BC is B | C.
var z;
var z;
var z;
var AB;
var BC;
var z1;
var z1;

View File

@@ -0,0 +1,49 @@
=== tests/cases/conformance/types/union/unionTypeEquivalence.ts ===
// A | B is equivalent to A if B is a subtype of A
class C { }
>C : C
class D extends C { }
>D : D
>C : C
var x: C;
>x : C
>C : C
var x : C | D;
>x : C
>C : C
>D : D
// A | B is equivalent to B | A.
var y: string | number;
>y : string | number
var y : number | string;
>y : string | number
// AB | C is equivalent to A | BC, where AB is A | B and BC is B | C.
var z : string | number | boolean;
>z : string | number | boolean
var z : (string | number) | boolean;
>z : string | number | boolean
var z : string | (number | boolean);
>z : string | number | boolean
var AB : string | number;
>AB : string | number
var BC : number | boolean;
>BC : number | boolean
var z1: typeof AB | boolean;
>z1 : string | number | boolean
>AB : string | number
var z1: string | typeof BC;
>z1 : string | number | boolean
>BC : number | boolean

View File

@@ -0,0 +1,18 @@
// A | B is equivalent to A if B is a subtype of A
class C { }
class D extends C { }
var x: C;
var x : C | D;
// A | B is equivalent to B | A.
var y: string | number;
var y : number | string;
// AB | C is equivalent to A | BC, where AB is A | B and BC is B | C.
var z : string | number | boolean;
var z : (string | number) | boolean;
var z : string | (number | boolean);
var AB : string | number;
var BC : number | boolean;
var z1: typeof AB | boolean;
var z1: string | typeof BC;