diff --git a/tests/baselines/reference/equalityWithUnionTypes01.errors.txt b/tests/baselines/reference/equalityWithUnionTypes01.errors.txt new file mode 100644 index 00000000000..985ba9e5867 --- /dev/null +++ b/tests/baselines/reference/equalityWithUnionTypes01.errors.txt @@ -0,0 +1,47 @@ +tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts(13,5): error TS2365: Operator '===' cannot be applied to types 'number | I2' and 'I1'. +tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts(13,16): error TS2365: Operator '===' cannot be applied to types 'I1' and 'number | I2'. +tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts(15,10): error TS2365: Operator '!==' cannot be applied to types 'number | I2' and 'I1'. +tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts(15,21): error TS2365: Operator '!==' cannot be applied to types 'I1' and 'number | I2'. +tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts(17,10): error TS2365: Operator '==' cannot be applied to types 'number | I2' and 'I1'. +tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts(17,20): error TS2365: Operator '==' cannot be applied to types 'I1' and 'number | I2'. +tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts(19,10): error TS2365: Operator '!=' cannot be applied to types 'number | I2' and 'I1'. +tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts(19,20): error TS2365: Operator '!=' cannot be applied to types 'I1' and 'number | I2'. + + +==== tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts (8 errors) ==== + interface I1 { + p1: number + } + + interface I2 extends I1 { + p2: number; + } + + var x = { p1: 10, p2: 20 }; + var y: number | I2 = x; + var z: I1 = x; + + if (y === z || z === y) { + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'number | I2' and 'I1'. + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'I1' and 'number | I2'. + } + else if (y !== z || z !== y) { + ~~~~~~~ +!!! error TS2365: Operator '!==' cannot be applied to types 'number | I2' and 'I1'. + ~~~~~~~ +!!! error TS2365: Operator '!==' cannot be applied to types 'I1' and 'number | I2'. + } + else if (y == z || z == y) { + ~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types 'number | I2' and 'I1'. + ~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types 'I1' and 'number | I2'. + } + else if (y != z || z != y) { + ~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types 'number | I2' and 'I1'. + ~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types 'I1' and 'number | I2'. + } \ No newline at end of file diff --git a/tests/baselines/reference/equalityWithUnionTypes01.js b/tests/baselines/reference/equalityWithUnionTypes01.js new file mode 100644 index 00000000000..05e9f25cd69 --- /dev/null +++ b/tests/baselines/reference/equalityWithUnionTypes01.js @@ -0,0 +1,34 @@ +//// [equalityWithUnionTypes01.ts] +interface I1 { + p1: number +} + +interface I2 extends I1 { + p2: number; +} + +var x = { p1: 10, p2: 20 }; +var y: number | I2 = x; +var z: I1 = x; + +if (y === z || z === y) { +} +else if (y !== z || z !== y) { +} +else if (y == z || z == y) { +} +else if (y != z || z != y) { +} + +//// [equalityWithUnionTypes01.js] +var x = { p1: 10, p2: 20 }; +var y = x; +var z = x; +if (y === z || z === y) { +} +else if (y !== z || z !== y) { +} +else if (y == z || z == y) { +} +else if (y != z || z != y) { +} diff --git a/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt b/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt new file mode 100644 index 00000000000..ee60c210253 --- /dev/null +++ b/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt @@ -0,0 +1,40 @@ +tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithUnionTypes01.ts(19,10): error TS2322: Type 'number | boolean' is not assignable to type 'string | number'. + Type 'boolean' is not assignable to type 'string | number'. + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithUnionTypes01.ts(23,10): error TS2322: Type 'boolean' is not assignable to type 'string | number'. + Type 'boolean' is not assignable to type 'number'. + + +==== tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithUnionTypes01.ts (2 errors) ==== + + var strOrNum: string | number; + var numOrBool: number | boolean; + var str: string; + var num: number; + var bool: boolean; + + switch (strOrNum) { + // Identical + case strOrNum: + break; + + // Constituents + case str: + case num: + break; + + // Overlap in constituents + case numOrBool: + ~~~~~~~~~ +!!! error TS2322: Type 'number | boolean' is not assignable to type 'string | number'. +!!! error TS2322: Type 'boolean' is not assignable to type 'string | number'. +!!! error TS2322: Type 'boolean' is not assignable to type 'number'. + break; + + // No relation + case bool: + ~~~~ +!!! error TS2322: Type 'boolean' is not assignable to type 'string | number'. +!!! error TS2322: Type 'boolean' is not assignable to type 'number'. + break; + } \ No newline at end of file diff --git a/tests/baselines/reference/switchCaseWithUnionTypes01.js b/tests/baselines/reference/switchCaseWithUnionTypes01.js new file mode 100644 index 00000000000..5c34ea674dc --- /dev/null +++ b/tests/baselines/reference/switchCaseWithUnionTypes01.js @@ -0,0 +1,48 @@ +//// [switchCaseWithUnionTypes01.ts] + +var strOrNum: string | number; +var numOrBool: number | boolean; +var str: string; +var num: number; +var bool: boolean; + +switch (strOrNum) { + // Identical + case strOrNum: + break; + + // Constituents + case str: + case num: + break; + + // Overlap in constituents + case numOrBool: + break; + + // No relation + case bool: + break; +} + +//// [switchCaseWithUnionTypes01.js] +var strOrNum; +var numOrBool; +var str; +var num; +var bool; +switch (strOrNum) { + // Identical + case strOrNum: + break; + // Constituents + case str: + case num: + break; + // Overlap in constituents + case numOrBool: + break; + // No relation + case bool: + break; +} diff --git a/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt b/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt new file mode 100644 index 00000000000..2a9dceaf8a6 --- /dev/null +++ b/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt @@ -0,0 +1,35 @@ +tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithUnionTypes01.ts(13,9): error TS2352: Neither type 'I1' nor type 'number | I2' is assignable to the other. + Type 'I1' is not assignable to type 'I2'. + Property 'p2' is missing in type 'I1'. +tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithUnionTypes01.ts(14,9): error TS2352: Neither type 'I1' nor type 'number' is assignable to the other. +tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithUnionTypes01.ts(16,9): error TS2352: Neither type 'number | I2' nor type 'I1' is assignable to the other. + Type 'number' is not assignable to type 'I1'. + + +==== tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithUnionTypes01.ts (3 errors) ==== + interface I1 { + p1: number + } + + interface I2 extends I1 { + p2: number; + } + + var x = { p1: 10, p2: 20 }; + var y: number | I2 = x; + var z: I1 = x; + + var a = z; + ~~~~~~~~~~~~~~ +!!! error TS2352: Neither type 'I1' nor type 'number | I2' is assignable to the other. +!!! error TS2352: Type 'I1' is not assignable to type 'I2'. +!!! error TS2352: Property 'p2' is missing in type 'I1'. + var b = z; + ~~~~~~~~~ +!!! error TS2352: Neither type 'I1' nor type 'number' is assignable to the other. + var c = z; + var d = y; + ~~~~~ +!!! error TS2352: Neither type 'number | I2' nor type 'I1' is assignable to the other. +!!! error TS2352: Type 'number' is not assignable to type 'I1'. + \ No newline at end of file diff --git a/tests/baselines/reference/typeAssertionsWithUnionTypes01.js b/tests/baselines/reference/typeAssertionsWithUnionTypes01.js new file mode 100644 index 00000000000..9cc448f6217 --- /dev/null +++ b/tests/baselines/reference/typeAssertionsWithUnionTypes01.js @@ -0,0 +1,27 @@ +//// [typeAssertionsWithUnionTypes01.ts] +interface I1 { + p1: number +} + +interface I2 extends I1 { + p2: number; +} + +var x = { p1: 10, p2: 20 }; +var y: number | I2 = x; +var z: I1 = x; + +var a = z; +var b = z; +var c = z; +var d = y; + + +//// [typeAssertionsWithUnionTypes01.js] +var x = { p1: 10, p2: 20 }; +var y = x; +var z = x; +var a = z; +var b = z; +var c = z; +var d = y;