From 262352ec5bd8514edcfbeaacaff31664b37b6aef Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 28 Oct 2015 16:09:45 -0700 Subject: [PATCH] Added tests on intersection types. --- .../equalityWithIntersectionTypes01.ts | 24 ++++++++++++++++++ .../switchCaseWithIntersectionTypes01.ts | 25 +++++++++++++++++++ .../typeAssertionsWithIntersectionTypes01.ts | 20 +++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts create mode 100644 tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithIntersectionTypes01.ts create mode 100644 tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithIntersectionTypes01.ts diff --git a/tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts b/tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts new file mode 100644 index 00000000000..74c0ebb7412 --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts @@ -0,0 +1,24 @@ +interface I1 { + p1: number +} + +interface I2 extends I1 { + p2: number; +} + +interface I3 { + p3: number; +} + +var x = { p1: 10, p2: 20, p3: 30 }; +var y: I1 & I3 = x; +var z: I2 = x; + +if (y === z || z === y) { +} +else if (y !== z || z !== y) { +} +else if (y == z || z == y) { +} +else if (y != z || z != y) { +} \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithIntersectionTypes01.ts b/tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithIntersectionTypes01.ts new file mode 100644 index 00000000000..fd629306b10 --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithIntersectionTypes01.ts @@ -0,0 +1,25 @@ + +var strAndNum: string & number; +var numAndBool: number & boolean; +var str: string; +var num: number; +var bool: boolean; + +switch (strAndNum) { + // Identical + case strAndNum: + break; + + // Constituents + case str: + case num: + break; + + // Overlap in constituents + case numAndBool: + break; + + // No relation + case bool: + break; +} \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithIntersectionTypes01.ts b/tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithIntersectionTypes01.ts new file mode 100644 index 00000000000..1afc760ef85 --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithIntersectionTypes01.ts @@ -0,0 +1,20 @@ +interface I1 { + p1: number +} + +interface I2 extends I1 { + p2: number; +} + +interface I3 { + p3: number; +} + +var x = { p1: 10, p2: 20, p3: 30 }; +var y: I1 & I3 = x; +var z: I2 = x; + +var a = z; +var b = z; +var c = z; +var d = y;