From 002bb6f04b5fb7fecf8decf1c331d07b222b27e5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 27 Oct 2015 15:23:38 -0700 Subject: [PATCH 01/22] Added tests. --- .../matchable/equalityWithUnionTypes01.ts | 20 +++++++++++++++ .../matchable/switchCaseWithUnionTypes01.ts | 25 +++++++++++++++++++ .../typeAssertionsWithUnionTypes01.ts | 16 ++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts create mode 100644 tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithUnionTypes01.ts create mode 100644 tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithUnionTypes01.ts diff --git a/tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts b/tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts new file mode 100644 index 0000000000000..d83277b975a12 --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts @@ -0,0 +1,20 @@ +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) { +} \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithUnionTypes01.ts b/tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithUnionTypes01.ts new file mode 100644 index 0000000000000..bdbfaf2df475c --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithUnionTypes01.ts @@ -0,0 +1,25 @@ + +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; +} \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithUnionTypes01.ts b/tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithUnionTypes01.ts new file mode 100644 index 0000000000000..3010c5f159a76 --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithUnionTypes01.ts @@ -0,0 +1,16 @@ +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; From 7426aca392e1d62c6e9985e2cd6909bc9432be80 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 27 Oct 2015 15:23:51 -0700 Subject: [PATCH 02/22] Accepted baselines. --- .../equalityWithUnionTypes01.errors.txt | 47 ++++++++++++++++++ .../reference/equalityWithUnionTypes01.js | 34 +++++++++++++ .../switchCaseWithUnionTypes01.errors.txt | 40 ++++++++++++++++ .../reference/switchCaseWithUnionTypes01.js | 48 +++++++++++++++++++ .../typeAssertionsWithUnionTypes01.errors.txt | 35 ++++++++++++++ .../typeAssertionsWithUnionTypes01.js | 27 +++++++++++ 6 files changed, 231 insertions(+) create mode 100644 tests/baselines/reference/equalityWithUnionTypes01.errors.txt create mode 100644 tests/baselines/reference/equalityWithUnionTypes01.js create mode 100644 tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt create mode 100644 tests/baselines/reference/switchCaseWithUnionTypes01.js create mode 100644 tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt create mode 100644 tests/baselines/reference/typeAssertionsWithUnionTypes01.js diff --git a/tests/baselines/reference/equalityWithUnionTypes01.errors.txt b/tests/baselines/reference/equalityWithUnionTypes01.errors.txt new file mode 100644 index 0000000000000..985ba9e5867de --- /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 0000000000000..05e9f25cd69ac --- /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 0000000000000..ee60c21025344 --- /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 0000000000000..5c34ea674dc96 --- /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 0000000000000..2a9dceaf8a66b --- /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 0000000000000..9cc448f62176f --- /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; From 43f158d4185ce3432edadee7aefc299dc641435b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 27 Oct 2015 16:17:26 -0700 Subject: [PATCH 03/22] Added "comparability" relation. It's currently equivalent to assignability. --- src/compiler/checker.ts | 47 +++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f64c25217bd7a..cebbe9380e371 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -211,6 +211,7 @@ namespace ts { let subtypeRelation: Map = {}; let assignableRelation: Map = {}; + let comparableRelation: Map = {}; let identityRelation: Map = {}; // This is for caching the result of getSymbolDisplayBuilder. Do not access directly. @@ -4738,6 +4739,14 @@ namespace ts { return checkTypeAssignableTo(source, target, /*errorNode*/ undefined); } + /** + * This is *not* a bi-directional relationship. + * If one needs to check both directions for comparability, use a second call to this function or 'checkTypeComparableTo'. + */ + function isTypeComparableTo(source: Type, target: Type): boolean { + return checkTypeComparableTo(source, target, /*errorNode*/ undefined); + } + function checkTypeSubtypeOf(source: Type, target: Type, errorNode: Node, headMessage?: DiagnosticMessage, containingMessageChain?: DiagnosticMessageChain): boolean { return checkTypeRelatedTo(source, target, subtypeRelation, errorNode, headMessage, containingMessageChain); } @@ -4746,6 +4755,14 @@ namespace ts { return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage, containingMessageChain); } + /** + * This is *not* a bi-directional relationship. + * If one needs to check both directions for comparability, use a second call to this function or 'isTypeComparableTo'. + */ + function checkTypeComparableTo(source: Type, target: Type, errorNode: Node, headMessage?: DiagnosticMessage, containingMessageChain?: DiagnosticMessageChain): boolean { + return checkTypeRelatedTo(source, target, comparableRelation, errorNode, headMessage, containingMessageChain); + } + function isSignatureAssignableTo(source: Signature, target: Signature): boolean { let sourceType = getOrCreateTypeFromSignature(source); let targetType = getOrCreateTypeFromSignature(target); @@ -4756,7 +4773,7 @@ namespace ts { * Checks if 'source' is related to 'target' (e.g.: is a assignable to). * @param source The left-hand-side of the relation. * @param target The right-hand-side of the relation. - * @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. + * @param relation The relation considered. One of 'identityRelation', 'assignableRelation', 'subTypeRelation', or 'comparableRelation'. * Used as both to determine which checks are performed and as a cache of previously computed results. * @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. * @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @@ -4781,6 +4798,7 @@ namespace ts { Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking"); + const isAssignableOrComparableRelation = relation === assignableRelation || relation === comparableRelation; let result = isRelatedTo(source, target, errorNode !== undefined, headMessage); if (overflow) { error(errorNode, Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target)); @@ -4834,7 +4852,7 @@ namespace ts { if (source === nullType && target !== undefinedType) return Ternary.True; if (source.flags & TypeFlags.Enum && target === numberType) return Ternary.True; if (source.flags & TypeFlags.StringLiteral && target === stringType) return Ternary.True; - if (relation === assignableRelation) { + if (isAssignableOrComparableRelation) { if (isTypeAny(source)) return Ternary.True; if (source === numberType && target.flags & TypeFlags.Enum) return Ternary.True; } @@ -4942,8 +4960,8 @@ namespace ts { } if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union || source.flags & TypeFlags.Intersection && target.flags & TypeFlags.Intersection) { - if (result = eachTypeRelatedToSomeType(source, target)) { - if (result &= eachTypeRelatedToSomeType(target, source)) { + if (result = eachTypeRelatedToSomeType(source, target, /*reportErrors*/ false)) { + if (result &= eachTypeRelatedToSomeType(target, source, /*reportErrors*/ false)) { return result; } } @@ -4958,7 +4976,7 @@ namespace ts { function isKnownProperty(type: Type, name: string): boolean { if (type.flags & TypeFlags.ObjectType) { const resolved = resolveStructuredTypeMembers(type); - if (relation === assignableRelation && (type === globalObjectType || resolved.properties.length === 0) || + if (isAssignableOrComparableRelation && (type === globalObjectType || resolved.properties.length === 0) || resolved.stringIndexType || resolved.numberIndexType || getPropertyOfType(type, name)) { return true; } @@ -4992,11 +5010,11 @@ namespace ts { return false; } - function eachTypeRelatedToSomeType(source: UnionOrIntersectionType, target: UnionOrIntersectionType): Ternary { + function eachTypeRelatedToSomeType(source: UnionOrIntersectionType, target: UnionOrIntersectionType, reportErrors: boolean): Ternary { let result = Ternary.True; let sourceTypes = source.types; for (let sourceType of sourceTypes) { - let related = typeRelatedToSomeType(sourceType, target, false); + let related = typeRelatedToSomeType(sourceType, target, reportErrors); if (!related) { return Ternary.False; } @@ -9381,8 +9399,9 @@ namespace ts { let targetType = getTypeFromTypeNode(node.type); if (produceDiagnostics && targetType !== unknownType) { let widenedType = getWidenedType(exprType); - if (!(isTypeAssignableTo(targetType, widenedType))) { - checkTypeAssignableTo(exprType, targetType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); + + if (!isTypeComparableTo(targetType, widenedType)) { + checkTypeComparableTo(exprType, targetType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); } } return targetType; @@ -10225,7 +10244,7 @@ namespace ts { case SyntaxKind.ExclamationEqualsToken: case SyntaxKind.EqualsEqualsEqualsToken: case SyntaxKind.ExclamationEqualsEqualsToken: - if (!isTypeAssignableTo(leftType, rightType) && !isTypeAssignableTo(rightType, leftType)) { + if (!isTypeComparableTo(leftType, rightType) && !isTypeComparableTo(rightType, leftType)) { reportOperatorError(); } return booleanType; @@ -12689,12 +12708,12 @@ namespace ts { if (produceDiagnostics && clause.kind === SyntaxKind.CaseClause) { let caseClause = clause; - // TypeScript 1.0 spec (April 2014):5.9 + // TypeScript 1.0 spec (April 2014): 5.9 // In a 'switch' statement, each 'case' expression must be of a type that is assignable to or from the type of the 'switch' expression. let caseType = checkExpression(caseClause.expression); - if (!isTypeAssignableTo(expressionType, caseType)) { - // check 'expressionType isAssignableTo caseType' failed, try the reversed check and report errors if it fails - checkTypeAssignableTo(caseType, expressionType, caseClause.expression, /*headMessage*/ undefined); + + if (!isTypeComparableTo(expressionType, caseType)) { + checkTypeComparableTo(caseType, expressionType, caseClause.expression, /*headMessage*/ undefined); } } forEach(clause.statements, checkSourceElement); From 1edb007acc899879488cecd850241c384dfb92a5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 27 Oct 2015 17:00:28 -0700 Subject: [PATCH 04/22] Check for partial satisfiability when using the comparable relationship. --- src/compiler/checker.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cebbe9380e371..52a9d6db1e7bb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4877,11 +4877,17 @@ namespace ts { // Note that the "each" checks must precede the "some" checks to produce the correct results if (source.flags & TypeFlags.Union) { + if (relation === comparableRelation && (result = someTypeRelatedToType(source as UnionType, target, reportErrors))) { + return result; + } if (result = eachTypeRelatedToType(source, target, reportErrors)) { return result; } } else if (target.flags & TypeFlags.Intersection) { + if (relation === comparableRelation && (result = typeRelatedToSomeType(source, target as IntersectionType, reportErrors))) { + return result; + } if (result = typeRelatedToEachType(source, target, reportErrors)) { return result; } From 9a5e3e3498e4d381df146c21abf7cd3d0e9ad8b1 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 27 Oct 2015 23:53:17 -0700 Subject: [PATCH 05/22] Avoid a redundant stricter check when using the new relation. --- src/compiler/checker.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 52a9d6db1e7bb..c976b92b5a499 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4877,18 +4877,26 @@ namespace ts { // Note that the "each" checks must precede the "some" checks to produce the correct results if (source.flags & TypeFlags.Union) { - if (relation === comparableRelation && (result = someTypeRelatedToType(source as UnionType, target, reportErrors))) { - return result; + if (relation === comparableRelation) { + result = someTypeRelatedToType(source as UnionType, target, reportErrors); + } + else { + result = eachTypeRelatedToType(source, target, reportErrors); } - if (result = eachTypeRelatedToType(source, target, reportErrors)) { + + if (result) { return result; } } else if (target.flags & TypeFlags.Intersection) { - if (relation === comparableRelation && (result = typeRelatedToSomeType(source, target as IntersectionType, reportErrors))) { - return result; + if (relation === comparableRelation) { + result = typeRelatedToSomeType(source, target as IntersectionType, reportErrors); + } + else { + result = typeRelatedToEachType(source, target, reportErrors); } - if (result = typeRelatedToEachType(source, target, reportErrors)) { + + if (result) { return result; } } @@ -4897,7 +4905,8 @@ namespace ts { // on either side that need to be prioritized. For example, A | B = (A | B) & (C | D) or // A & B = (A & B) | (C & D). if (source.flags & TypeFlags.Intersection) { - // If target is a union type the following check will report errors so we suppress them here + // If target is a union type then the check following this one will report errors, + // so we'll suppress any errors we could run into here. if (result = someTypeRelatedToType(source, target, reportErrors && !(target.flags & TypeFlags.Union))) { return result; } From 42b3ce4d0c6a7b8ac5e89136ce54a6ed01f699e4 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 27 Oct 2015 23:58:24 -0700 Subject: [PATCH 06/22] Rename the relationship to "matchable by". --- src/compiler/checker.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c976b92b5a499..02ecc43aa4dc3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -211,7 +211,7 @@ namespace ts { let subtypeRelation: Map = {}; let assignableRelation: Map = {}; - let comparableRelation: Map = {}; + let matchableRelation: Map = {}; let identityRelation: Map = {}; // This is for caching the result of getSymbolDisplayBuilder. Do not access directly. @@ -4743,8 +4743,8 @@ namespace ts { * This is *not* a bi-directional relationship. * If one needs to check both directions for comparability, use a second call to this function or 'checkTypeComparableTo'. */ - function isTypeComparableTo(source: Type, target: Type): boolean { - return checkTypeComparableTo(source, target, /*errorNode*/ undefined); + function isTypeMatchableBy(source: Type, target: Type): boolean { + return checkTypeMatchableBy(source, target, /*errorNode*/ undefined); } function checkTypeSubtypeOf(source: Type, target: Type, errorNode: Node, headMessage?: DiagnosticMessage, containingMessageChain?: DiagnosticMessageChain): boolean { @@ -4757,10 +4757,10 @@ namespace ts { /** * This is *not* a bi-directional relationship. - * If one needs to check both directions for comparability, use a second call to this function or 'isTypeComparableTo'. + * If one needs to check both directions for comparability, use a second call to this function or 'isTypeMatchableBy'. */ - function checkTypeComparableTo(source: Type, target: Type, errorNode: Node, headMessage?: DiagnosticMessage, containingMessageChain?: DiagnosticMessageChain): boolean { - return checkTypeRelatedTo(source, target, comparableRelation, errorNode, headMessage, containingMessageChain); + function checkTypeMatchableBy(source: Type, target: Type, errorNode: Node, headMessage?: DiagnosticMessage, containingMessageChain?: DiagnosticMessageChain): boolean { + return checkTypeRelatedTo(source, target, matchableRelation, errorNode, headMessage, containingMessageChain); } function isSignatureAssignableTo(source: Signature, target: Signature): boolean { @@ -4773,7 +4773,7 @@ namespace ts { * Checks if 'source' is related to 'target' (e.g.: is a assignable to). * @param source The left-hand-side of the relation. * @param target The right-hand-side of the relation. - * @param relation The relation considered. One of 'identityRelation', 'assignableRelation', 'subTypeRelation', or 'comparableRelation'. + * @param relation The relation considered. One of 'identityRelation', 'assignableRelation', 'subTypeRelation', or 'matchableRelation'. * Used as both to determine which checks are performed and as a cache of previously computed results. * @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. * @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @@ -4798,7 +4798,7 @@ namespace ts { Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking"); - const isAssignableOrComparableRelation = relation === assignableRelation || relation === comparableRelation; + const isAssignableOrComparableRelation = relation === assignableRelation || relation === matchableRelation; let result = isRelatedTo(source, target, errorNode !== undefined, headMessage); if (overflow) { error(errorNode, Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target)); @@ -4877,7 +4877,7 @@ namespace ts { // Note that the "each" checks must precede the "some" checks to produce the correct results if (source.flags & TypeFlags.Union) { - if (relation === comparableRelation) { + if (relation === matchableRelation) { result = someTypeRelatedToType(source as UnionType, target, reportErrors); } else { @@ -4889,7 +4889,7 @@ namespace ts { } } else if (target.flags & TypeFlags.Intersection) { - if (relation === comparableRelation) { + if (relation === matchableRelation) { result = typeRelatedToSomeType(source, target as IntersectionType, reportErrors); } else { @@ -9415,8 +9415,8 @@ namespace ts { if (produceDiagnostics && targetType !== unknownType) { let widenedType = getWidenedType(exprType); - if (!isTypeComparableTo(targetType, widenedType)) { - checkTypeComparableTo(exprType, targetType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); + if (!isTypeMatchableBy(targetType, widenedType)) { + checkTypeMatchableBy(exprType, targetType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); } } return targetType; @@ -10259,7 +10259,7 @@ namespace ts { case SyntaxKind.ExclamationEqualsToken: case SyntaxKind.EqualsEqualsEqualsToken: case SyntaxKind.ExclamationEqualsEqualsToken: - if (!isTypeComparableTo(leftType, rightType) && !isTypeComparableTo(rightType, leftType)) { + if (!isTypeMatchableBy(leftType, rightType) && !isTypeMatchableBy(rightType, leftType)) { reportOperatorError(); } return booleanType; @@ -12727,8 +12727,8 @@ namespace ts { // In a 'switch' statement, each 'case' expression must be of a type that is assignable to or from the type of the 'switch' expression. let caseType = checkExpression(caseClause.expression); - if (!isTypeComparableTo(expressionType, caseType)) { - checkTypeComparableTo(caseType, expressionType, caseClause.expression, /*headMessage*/ undefined); + if (!isTypeMatchableBy(expressionType, caseType)) { + checkTypeMatchableBy(caseType, expressionType, caseClause.expression, /*headMessage*/ undefined); } } forEach(clause.statements, checkSourceElement); From 929808ef07eb6b394a1a8ea5802f31ed4c7eff7e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 28 Oct 2015 17:09:27 -0700 Subject: [PATCH 07/22] Accepted baselines. --- .../reference/castingTuple.errors.txt | 23 +----- .../equalityWithUnionTypes01.errors.txt | 47 ------------- .../equalityWithUnionTypes01.symbols | 55 +++++++++++++++ .../reference/equalityWithUnionTypes01.types | 70 +++++++++++++++++++ .../switchCaseWithUnionTypes01.errors.txt | 9 +-- .../typeAssertionsWithUnionTypes01.errors.txt | 14 +--- 6 files changed, 128 insertions(+), 90 deletions(-) delete mode 100644 tests/baselines/reference/equalityWithUnionTypes01.errors.txt create mode 100644 tests/baselines/reference/equalityWithUnionTypes01.symbols create mode 100644 tests/baselines/reference/equalityWithUnionTypes01.types diff --git a/tests/baselines/reference/castingTuple.errors.txt b/tests/baselines/reference/castingTuple.errors.txt index 62a36c9c15615..128ee5b5bb497 100644 --- a/tests/baselines/reference/castingTuple.errors.txt +++ b/tests/baselines/reference/castingTuple.errors.txt @@ -1,7 +1,3 @@ -tests/cases/conformance/types/tuple/castingTuple.ts(13,23): error TS2352: Neither type '[number, string]' nor type '[number, string, boolean]' is assignable to the other. - Property '2' is missing in type '[number, string]'. -tests/cases/conformance/types/tuple/castingTuple.ts(16,21): error TS2352: Neither type '[C, D]' nor type '[C, D, A]' is assignable to the other. - Property '2' is missing in type '[C, D]'. tests/cases/conformance/types/tuple/castingTuple.ts(28,10): error TS2352: Neither type '[number, string]' nor type '[number, number]' is assignable to the other. Types of property '1' are incompatible. Type 'string' is not assignable to type 'number'. @@ -10,15 +6,10 @@ tests/cases/conformance/types/tuple/castingTuple.ts(29,10): error TS2352: Neithe Type 'C' is not assignable to type 'A'. Property 'a' is missing in type 'C'. tests/cases/conformance/types/tuple/castingTuple.ts(30,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'. -tests/cases/conformance/types/tuple/castingTuple.ts(30,14): error TS2352: Neither type '[number, string]' nor type 'number[]' is assignable to the other. - Types of property 'pop' are incompatible. - Type '() => number | string' is not assignable to type '() => number'. - Type 'number | string' is not assignable to type 'number'. - Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/tuple/castingTuple.ts(31,1): error TS2304: Cannot find name 't4'. -==== tests/cases/conformance/types/tuple/castingTuple.ts (7 errors) ==== +==== tests/cases/conformance/types/tuple/castingTuple.ts (4 errors) ==== interface I { } class A { a = 10; } class C implements I { c }; @@ -32,15 +23,9 @@ tests/cases/conformance/types/tuple/castingTuple.ts(31,1): error TS2304: Cannot var numStrTuple: [number, string] = [5, "foo"]; var emptyObjTuple = <[{}, {}]>numStrTuple; var numStrBoolTuple = <[number, string, boolean]>numStrTuple; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '[number, string]' nor type '[number, string, boolean]' is assignable to the other. -!!! error TS2352: Property '2' is missing in type '[number, string]'. var classCDTuple: [C, D] = [new C(), new D()]; var interfaceIITuple = <[I, I]>classCDTuple; var classCDATuple = <[C, D, A]>classCDTuple; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '[C, D]' nor type '[C, D, A]' is assignable to the other. -!!! error TS2352: Property '2' is missing in type '[C, D]'. var eleFromCDA1 = classCDATuple[2]; // A var eleFromCDA2 = classCDATuple[5]; // C | D | A var t10: [E1, E2] = [E1.one, E2.one]; @@ -66,12 +51,6 @@ tests/cases/conformance/types/tuple/castingTuple.ts(31,1): error TS2304: Cannot var array1 = numStrTuple; ~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'. - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '[number, string]' nor type 'number[]' is assignable to the other. -!!! error TS2352: Types of property 'pop' are incompatible. -!!! error TS2352: Type '() => number | string' is not assignable to type '() => number'. -!!! error TS2352: Type 'number | string' is not assignable to type 'number'. -!!! error TS2352: Type 'string' is not assignable to type 'number'. t4[2] = 10; ~~ !!! error TS2304: Cannot find name 't4'. diff --git a/tests/baselines/reference/equalityWithUnionTypes01.errors.txt b/tests/baselines/reference/equalityWithUnionTypes01.errors.txt deleted file mode 100644 index 985ba9e5867de..0000000000000 --- a/tests/baselines/reference/equalityWithUnionTypes01.errors.txt +++ /dev/null @@ -1,47 +0,0 @@ -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.symbols b/tests/baselines/reference/equalityWithUnionTypes01.symbols new file mode 100644 index 0000000000000..2baf5034f7741 --- /dev/null +++ b/tests/baselines/reference/equalityWithUnionTypes01.symbols @@ -0,0 +1,55 @@ +=== tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts === +interface I1 { +>I1 : Symbol(I1, Decl(equalityWithUnionTypes01.ts, 0, 0)) + + p1: number +>p1 : Symbol(p1, Decl(equalityWithUnionTypes01.ts, 0, 14)) +} + +interface I2 extends I1 { +>I2 : Symbol(I2, Decl(equalityWithUnionTypes01.ts, 2, 1)) +>I1 : Symbol(I1, Decl(equalityWithUnionTypes01.ts, 0, 0)) + + p2: number; +>p2 : Symbol(p2, Decl(equalityWithUnionTypes01.ts, 4, 25)) +} + +var x = { p1: 10, p2: 20 }; +>x : Symbol(x, Decl(equalityWithUnionTypes01.ts, 8, 3)) +>p1 : Symbol(p1, Decl(equalityWithUnionTypes01.ts, 8, 9)) +>p2 : Symbol(p2, Decl(equalityWithUnionTypes01.ts, 8, 17)) + +var y: number | I2 = x; +>y : Symbol(y, Decl(equalityWithUnionTypes01.ts, 9, 3)) +>I2 : Symbol(I2, Decl(equalityWithUnionTypes01.ts, 2, 1)) +>x : Symbol(x, Decl(equalityWithUnionTypes01.ts, 8, 3)) + +var z: I1 = x; +>z : Symbol(z, Decl(equalityWithUnionTypes01.ts, 10, 3)) +>I1 : Symbol(I1, Decl(equalityWithUnionTypes01.ts, 0, 0)) +>x : Symbol(x, Decl(equalityWithUnionTypes01.ts, 8, 3)) + +if (y === z || z === y) { +>y : Symbol(y, Decl(equalityWithUnionTypes01.ts, 9, 3)) +>z : Symbol(z, Decl(equalityWithUnionTypes01.ts, 10, 3)) +>z : Symbol(z, Decl(equalityWithUnionTypes01.ts, 10, 3)) +>y : Symbol(y, Decl(equalityWithUnionTypes01.ts, 9, 3)) +} +else if (y !== z || z !== y) { +>y : Symbol(y, Decl(equalityWithUnionTypes01.ts, 9, 3)) +>z : Symbol(z, Decl(equalityWithUnionTypes01.ts, 10, 3)) +>z : Symbol(z, Decl(equalityWithUnionTypes01.ts, 10, 3)) +>y : Symbol(y, Decl(equalityWithUnionTypes01.ts, 9, 3)) +} +else if (y == z || z == y) { +>y : Symbol(y, Decl(equalityWithUnionTypes01.ts, 9, 3)) +>z : Symbol(z, Decl(equalityWithUnionTypes01.ts, 10, 3)) +>z : Symbol(z, Decl(equalityWithUnionTypes01.ts, 10, 3)) +>y : Symbol(y, Decl(equalityWithUnionTypes01.ts, 9, 3)) +} +else if (y != z || z != y) { +>y : Symbol(y, Decl(equalityWithUnionTypes01.ts, 9, 3)) +>z : Symbol(z, Decl(equalityWithUnionTypes01.ts, 10, 3)) +>z : Symbol(z, Decl(equalityWithUnionTypes01.ts, 10, 3)) +>y : Symbol(y, Decl(equalityWithUnionTypes01.ts, 9, 3)) +} diff --git a/tests/baselines/reference/equalityWithUnionTypes01.types b/tests/baselines/reference/equalityWithUnionTypes01.types new file mode 100644 index 0000000000000..e6a5ce487d98e --- /dev/null +++ b/tests/baselines/reference/equalityWithUnionTypes01.types @@ -0,0 +1,70 @@ +=== tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts === +interface I1 { +>I1 : I1 + + p1: number +>p1 : number +} + +interface I2 extends I1 { +>I2 : I2 +>I1 : I1 + + p2: number; +>p2 : number +} + +var x = { p1: 10, p2: 20 }; +>x : { p1: number; p2: number; } +>{ p1: 10, p2: 20 } : { p1: number; p2: number; } +>p1 : number +>10 : number +>p2 : number +>20 : number + +var y: number | I2 = x; +>y : number | I2 +>I2 : I2 +>x : { p1: number; p2: number; } + +var z: I1 = x; +>z : I1 +>I1 : I1 +>x : { p1: number; p2: number; } + +if (y === z || z === y) { +>y === z || z === y : boolean +>y === z : boolean +>y : number | I2 +>z : I1 +>z === y : boolean +>z : I1 +>y : number | I2 +} +else if (y !== z || z !== y) { +>y !== z || z !== y : boolean +>y !== z : boolean +>y : number | I2 +>z : I1 +>z !== y : boolean +>z : I1 +>y : number | I2 +} +else if (y == z || z == y) { +>y == z || z == y : boolean +>y == z : boolean +>y : number | I2 +>z : I1 +>z == y : boolean +>z : I1 +>y : number | I2 +} +else if (y != z || z != y) { +>y != z || z != y : boolean +>y != z : boolean +>y : number | I2 +>z : I1 +>z != y : boolean +>z : I1 +>y : number | I2 +} diff --git a/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt b/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt index ee60c21025344..a59c9ec57f73d 100644 --- a/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt +++ b/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt @@ -1,11 +1,8 @@ -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) ==== +==== tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithUnionTypes01.ts (1 errors) ==== var strOrNum: string | number; var numOrBool: number | boolean; @@ -25,10 +22,6 @@ tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithUnionTyp // 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 diff --git a/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt b/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt index 2a9dceaf8a66b..022617c8ba066 100644 --- a/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt +++ b/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt @@ -1,12 +1,7 @@ -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) ==== +==== tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithUnionTypes01.ts (1 errors) ==== interface I1 { p1: number } @@ -20,16 +15,9 @@ tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithUnio 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 From 262352ec5bd8514edcfbeaacaff31664b37b6aef Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 28 Oct 2015 16:09:45 -0700 Subject: [PATCH 08/22] 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 0000000000000..74c0ebb7412e6 --- /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 0000000000000..fd629306b1041 --- /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 0000000000000..1afc760ef851a --- /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; From bdb1db5ae4576e0a1f2472352e7c9e537150556e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 28 Oct 2015 16:11:14 -0700 Subject: [PATCH 09/22] Matchable should have no effect on intersections. --- src/compiler/checker.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 02ecc43aa4dc3..3e2b6a7317f7c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4889,12 +4889,7 @@ namespace ts { } } else if (target.flags & TypeFlags.Intersection) { - if (relation === matchableRelation) { - result = typeRelatedToSomeType(source, target as IntersectionType, reportErrors); - } - else { - result = typeRelatedToEachType(source, target, reportErrors); - } + result = typeRelatedToEachType(source, target, reportErrors); if (result) { return result; From 441dd78114f6e64f43f5a9c94d89e6df18758786 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 28 Oct 2015 17:10:02 -0700 Subject: [PATCH 10/22] Accepted baselines. --- ...equalityWithIntersectionTypes01.errors.txt | 51 +++++++++++++++++++ .../equalityWithIntersectionTypes01.js | 38 ++++++++++++++ ...itchCaseWithIntersectionTypes01.errors.txt | 40 +++++++++++++++ .../switchCaseWithIntersectionTypes01.js | 48 +++++++++++++++++ ...sertionsWithIntersectionTypes01.errors.txt | 34 +++++++++++++ .../typeAssertionsWithIntersectionTypes01.js | 31 +++++++++++ 6 files changed, 242 insertions(+) create mode 100644 tests/baselines/reference/equalityWithIntersectionTypes01.errors.txt create mode 100644 tests/baselines/reference/equalityWithIntersectionTypes01.js create mode 100644 tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt create mode 100644 tests/baselines/reference/switchCaseWithIntersectionTypes01.js create mode 100644 tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt create mode 100644 tests/baselines/reference/typeAssertionsWithIntersectionTypes01.js diff --git a/tests/baselines/reference/equalityWithIntersectionTypes01.errors.txt b/tests/baselines/reference/equalityWithIntersectionTypes01.errors.txt new file mode 100644 index 0000000000000..da18a7742041c --- /dev/null +++ b/tests/baselines/reference/equalityWithIntersectionTypes01.errors.txt @@ -0,0 +1,51 @@ +tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts(17,5): error TS2365: Operator '===' cannot be applied to types 'I1 & I3' and 'I2'. +tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts(17,16): error TS2365: Operator '===' cannot be applied to types 'I2' and 'I1 & I3'. +tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts(19,10): error TS2365: Operator '!==' cannot be applied to types 'I1 & I3' and 'I2'. +tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts(19,21): error TS2365: Operator '!==' cannot be applied to types 'I2' and 'I1 & I3'. +tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts(21,10): error TS2365: Operator '==' cannot be applied to types 'I1 & I3' and 'I2'. +tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts(21,20): error TS2365: Operator '==' cannot be applied to types 'I2' and 'I1 & I3'. +tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts(23,10): error TS2365: Operator '!=' cannot be applied to types 'I1 & I3' and 'I2'. +tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts(23,20): error TS2365: Operator '!=' cannot be applied to types 'I2' and 'I1 & I3'. + + +==== tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts (8 errors) ==== + 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) { + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'I1 & I3' and 'I2'. + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'I2' and 'I1 & I3'. + } + else if (y !== z || z !== y) { + ~~~~~~~ +!!! error TS2365: Operator '!==' cannot be applied to types 'I1 & I3' and 'I2'. + ~~~~~~~ +!!! error TS2365: Operator '!==' cannot be applied to types 'I2' and 'I1 & I3'. + } + else if (y == z || z == y) { + ~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types 'I1 & I3' and 'I2'. + ~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types 'I2' and 'I1 & I3'. + } + else if (y != z || z != y) { + ~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types 'I1 & I3' and 'I2'. + ~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types 'I2' and 'I1 & I3'. + } \ No newline at end of file diff --git a/tests/baselines/reference/equalityWithIntersectionTypes01.js b/tests/baselines/reference/equalityWithIntersectionTypes01.js new file mode 100644 index 0000000000000..151809bb6f8a5 --- /dev/null +++ b/tests/baselines/reference/equalityWithIntersectionTypes01.js @@ -0,0 +1,38 @@ +//// [equalityWithIntersectionTypes01.ts] +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) { +} + +//// [equalityWithIntersectionTypes01.js] +var x = { p1: 10, p2: 20, p3: 30 }; +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/switchCaseWithIntersectionTypes01.errors.txt b/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt new file mode 100644 index 0000000000000..5c2e8ad30fe90 --- /dev/null +++ b/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt @@ -0,0 +1,40 @@ +tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithIntersectionTypes01.ts(19,10): error TS2322: Type 'number & boolean' is not assignable to type 'string & number'. + Type 'number & boolean' is not assignable to type 'string'. + Type 'boolean' is not assignable to type 'string'. +tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithIntersectionTypes01.ts(23,10): error TS2322: Type 'boolean' is not assignable to type 'string & number'. + Type 'boolean' is not assignable to type 'string'. + + +==== tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithIntersectionTypes01.ts (2 errors) ==== + + 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: + ~~~~~~~~~~ +!!! error TS2322: Type 'number & boolean' is not assignable to type 'string & number'. +!!! error TS2322: Type 'number & boolean' is not assignable to type 'string'. +!!! error TS2322: Type 'boolean' is not assignable to type 'string'. + 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 'string'. + break; + } \ No newline at end of file diff --git a/tests/baselines/reference/switchCaseWithIntersectionTypes01.js b/tests/baselines/reference/switchCaseWithIntersectionTypes01.js new file mode 100644 index 0000000000000..4e0ddf7ea76a9 --- /dev/null +++ b/tests/baselines/reference/switchCaseWithIntersectionTypes01.js @@ -0,0 +1,48 @@ +//// [switchCaseWithIntersectionTypes01.ts] + +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; +} + +//// [switchCaseWithIntersectionTypes01.js] +var strAndNum; +var numAndBool; +var str; +var num; +var bool; +switch (strAndNum) { + // Identical + case strAndNum: + break; + // Constituents + case str: + case num: + break; + // Overlap in constituents + case numAndBool: + break; + // No relation + case bool: + break; +} diff --git a/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt b/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt new file mode 100644 index 0000000000000..b5041f6fe55c1 --- /dev/null +++ b/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt @@ -0,0 +1,34 @@ +tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithIntersectionTypes01.ts(17,9): error TS2352: Neither type 'I2' nor type 'I1 & I3' is assignable to the other. + Type 'I2' is not assignable to type 'I3'. + Property 'p3' is missing in type 'I2'. +tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithIntersectionTypes01.ts(18,9): error TS2352: Neither type 'I2' nor type 'I3' is assignable to the other. + + +==== tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithIntersectionTypes01.ts (2 errors) ==== + 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; + ~~~~~~~~~~ +!!! error TS2352: Neither type 'I2' nor type 'I1 & I3' is assignable to the other. +!!! error TS2352: Type 'I2' is not assignable to type 'I3'. +!!! error TS2352: Property 'p3' is missing in type 'I2'. + var b = z; + ~~~~~ +!!! error TS2352: Neither type 'I2' nor type 'I3' is assignable to the other. + var c = z; + var d = y; + \ No newline at end of file diff --git a/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.js b/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.js new file mode 100644 index 0000000000000..31fc831f95f81 --- /dev/null +++ b/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.js @@ -0,0 +1,31 @@ +//// [typeAssertionsWithIntersectionTypes01.ts] +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; + + +//// [typeAssertionsWithIntersectionTypes01.js] +var x = { p1: 10, p2: 20, p3: 30 }; +var y = x; +var z = x; +var a = z; +var b = z; +var c = z; +var d = y; From 841789d162e91f6a88e1db411b7bd22ffc6e23f2 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 29 Oct 2015 16:36:25 -0700 Subject: [PATCH 11/22] Renamed the relationship back to "comparable". --- src/compiler/checker.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3e2b6a7317f7c..ac44a748d6cb6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -211,7 +211,7 @@ namespace ts { let subtypeRelation: Map = {}; let assignableRelation: Map = {}; - let matchableRelation: Map = {}; + let comparableRelation: Map = {}; let identityRelation: Map = {}; // This is for caching the result of getSymbolDisplayBuilder. Do not access directly. @@ -4743,8 +4743,8 @@ namespace ts { * This is *not* a bi-directional relationship. * If one needs to check both directions for comparability, use a second call to this function or 'checkTypeComparableTo'. */ - function isTypeMatchableBy(source: Type, target: Type): boolean { - return checkTypeMatchableBy(source, target, /*errorNode*/ undefined); + function isTypeComparableTo(source: Type, target: Type): boolean { + return checkTypeComparableTo(source, target, /*errorNode*/ undefined); } function checkTypeSubtypeOf(source: Type, target: Type, errorNode: Node, headMessage?: DiagnosticMessage, containingMessageChain?: DiagnosticMessageChain): boolean { @@ -4757,10 +4757,10 @@ namespace ts { /** * This is *not* a bi-directional relationship. - * If one needs to check both directions for comparability, use a second call to this function or 'isTypeMatchableBy'. + * If one needs to check both directions for comparability, use a second call to this function or 'isTypeComparableTo'. */ - function checkTypeMatchableBy(source: Type, target: Type, errorNode: Node, headMessage?: DiagnosticMessage, containingMessageChain?: DiagnosticMessageChain): boolean { - return checkTypeRelatedTo(source, target, matchableRelation, errorNode, headMessage, containingMessageChain); + function checkTypeComparableTo(source: Type, target: Type, errorNode: Node, headMessage?: DiagnosticMessage, containingMessageChain?: DiagnosticMessageChain): boolean { + return checkTypeRelatedTo(source, target, comparableRelation, errorNode, headMessage, containingMessageChain); } function isSignatureAssignableTo(source: Signature, target: Signature): boolean { @@ -4773,7 +4773,7 @@ namespace ts { * Checks if 'source' is related to 'target' (e.g.: is a assignable to). * @param source The left-hand-side of the relation. * @param target The right-hand-side of the relation. - * @param relation The relation considered. One of 'identityRelation', 'assignableRelation', 'subTypeRelation', or 'matchableRelation'. + * @param relation The relation considered. One of 'identityRelation', 'assignableRelation', 'subTypeRelation', or 'comparableRelation'. * Used as both to determine which checks are performed and as a cache of previously computed results. * @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. * @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @@ -4798,7 +4798,7 @@ namespace ts { Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking"); - const isAssignableOrComparableRelation = relation === assignableRelation || relation === matchableRelation; + const isAssignableOrComparableRelation = relation === assignableRelation || relation === comparableRelation; let result = isRelatedTo(source, target, errorNode !== undefined, headMessage); if (overflow) { error(errorNode, Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target)); @@ -4877,7 +4877,7 @@ namespace ts { // Note that the "each" checks must precede the "some" checks to produce the correct results if (source.flags & TypeFlags.Union) { - if (relation === matchableRelation) { + if (relation === comparableRelation) { result = someTypeRelatedToType(source as UnionType, target, reportErrors); } else { @@ -9410,8 +9410,8 @@ namespace ts { if (produceDiagnostics && targetType !== unknownType) { let widenedType = getWidenedType(exprType); - if (!isTypeMatchableBy(targetType, widenedType)) { - checkTypeMatchableBy(exprType, targetType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); + if (!isTypeComparableTo(targetType, widenedType)) { + checkTypeComparableTo(exprType, targetType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); } } return targetType; @@ -10254,7 +10254,7 @@ namespace ts { case SyntaxKind.ExclamationEqualsToken: case SyntaxKind.EqualsEqualsEqualsToken: case SyntaxKind.ExclamationEqualsEqualsToken: - if (!isTypeMatchableBy(leftType, rightType) && !isTypeMatchableBy(rightType, leftType)) { + if (!isTypeComparableTo(leftType, rightType) && !isTypeComparableTo(rightType, leftType)) { reportOperatorError(); } return booleanType; @@ -12722,8 +12722,8 @@ namespace ts { // In a 'switch' statement, each 'case' expression must be of a type that is assignable to or from the type of the 'switch' expression. let caseType = checkExpression(caseClause.expression); - if (!isTypeMatchableBy(expressionType, caseType)) { - checkTypeMatchableBy(caseType, expressionType, caseClause.expression, /*headMessage*/ undefined); + if (!isTypeComparableTo(expressionType, caseType)) { + checkTypeComparableTo(caseType, expressionType, caseClause.expression, /*headMessage*/ undefined); } } forEach(clause.statements, checkSourceElement); From 5cb95d4044aefb378c6ee85f939bb625f697518f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 29 Oct 2015 16:40:34 -0700 Subject: [PATCH 12/22] Renamed test directory. --- .../{matchable => comparable}/equalityWithIntersectionTypes01.ts | 0 .../{matchable => comparable}/equalityWithUnionTypes01.ts | 0 .../switchCaseWithIntersectionTypes01.ts | 0 .../{matchable => comparable}/switchCaseWithUnionTypes01.ts | 0 .../typeAssertionsWithIntersectionTypes01.ts | 0 .../{matchable => comparable}/typeAssertionsWithUnionTypes01.ts | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename tests/cases/conformance/types/typeRelationships/{matchable => comparable}/equalityWithIntersectionTypes01.ts (100%) rename tests/cases/conformance/types/typeRelationships/{matchable => comparable}/equalityWithUnionTypes01.ts (100%) rename tests/cases/conformance/types/typeRelationships/{matchable => comparable}/switchCaseWithIntersectionTypes01.ts (100%) rename tests/cases/conformance/types/typeRelationships/{matchable => comparable}/switchCaseWithUnionTypes01.ts (100%) rename tests/cases/conformance/types/typeRelationships/{matchable => comparable}/typeAssertionsWithIntersectionTypes01.ts (100%) rename tests/cases/conformance/types/typeRelationships/{matchable => comparable}/typeAssertionsWithUnionTypes01.ts (100%) diff --git a/tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts b/tests/cases/conformance/types/typeRelationships/comparable/equalityWithIntersectionTypes01.ts similarity index 100% rename from tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts rename to tests/cases/conformance/types/typeRelationships/comparable/equalityWithIntersectionTypes01.ts diff --git a/tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts b/tests/cases/conformance/types/typeRelationships/comparable/equalityWithUnionTypes01.ts similarity index 100% rename from tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts rename to tests/cases/conformance/types/typeRelationships/comparable/equalityWithUnionTypes01.ts diff --git a/tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithIntersectionTypes01.ts b/tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts similarity index 100% rename from tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithIntersectionTypes01.ts rename to tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts diff --git a/tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithUnionTypes01.ts b/tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithUnionTypes01.ts similarity index 100% rename from tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithUnionTypes01.ts rename to tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithUnionTypes01.ts diff --git a/tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithIntersectionTypes01.ts b/tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts similarity index 100% rename from tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithIntersectionTypes01.ts rename to tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts diff --git a/tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithUnionTypes01.ts b/tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithUnionTypes01.ts similarity index 100% rename from tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithUnionTypes01.ts rename to tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithUnionTypes01.ts From ab7c4e5e43077df3d1b090c6f3f4cae2b734e580 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 29 Oct 2015 16:40:54 -0700 Subject: [PATCH 13/22] Accepted baselines. --- .../equalityWithIntersectionTypes01.errors.txt | 18 +++++++++--------- .../reference/equalityWithUnionTypes01.symbols | 2 +- .../reference/equalityWithUnionTypes01.types | 2 +- ...witchCaseWithIntersectionTypes01.errors.txt | 6 +++--- .../switchCaseWithUnionTypes01.errors.txt | 4 ++-- ...ssertionsWithIntersectionTypes01.errors.txt | 6 +++--- .../typeAssertionsWithUnionTypes01.errors.txt | 4 ++-- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/baselines/reference/equalityWithIntersectionTypes01.errors.txt b/tests/baselines/reference/equalityWithIntersectionTypes01.errors.txt index da18a7742041c..8bffff2218b5c 100644 --- a/tests/baselines/reference/equalityWithIntersectionTypes01.errors.txt +++ b/tests/baselines/reference/equalityWithIntersectionTypes01.errors.txt @@ -1,14 +1,14 @@ -tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts(17,5): error TS2365: Operator '===' cannot be applied to types 'I1 & I3' and 'I2'. -tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts(17,16): error TS2365: Operator '===' cannot be applied to types 'I2' and 'I1 & I3'. -tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts(19,10): error TS2365: Operator '!==' cannot be applied to types 'I1 & I3' and 'I2'. -tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts(19,21): error TS2365: Operator '!==' cannot be applied to types 'I2' and 'I1 & I3'. -tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts(21,10): error TS2365: Operator '==' cannot be applied to types 'I1 & I3' and 'I2'. -tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts(21,20): error TS2365: Operator '==' cannot be applied to types 'I2' and 'I1 & I3'. -tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts(23,10): error TS2365: Operator '!=' cannot be applied to types 'I1 & I3' and 'I2'. -tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts(23,20): error TS2365: Operator '!=' cannot be applied to types 'I2' and 'I1 & I3'. +tests/cases/conformance/types/typeRelationships/comparable/equalityWithIntersectionTypes01.ts(17,5): error TS2365: Operator '===' cannot be applied to types 'I1 & I3' and 'I2'. +tests/cases/conformance/types/typeRelationships/comparable/equalityWithIntersectionTypes01.ts(17,16): error TS2365: Operator '===' cannot be applied to types 'I2' and 'I1 & I3'. +tests/cases/conformance/types/typeRelationships/comparable/equalityWithIntersectionTypes01.ts(19,10): error TS2365: Operator '!==' cannot be applied to types 'I1 & I3' and 'I2'. +tests/cases/conformance/types/typeRelationships/comparable/equalityWithIntersectionTypes01.ts(19,21): error TS2365: Operator '!==' cannot be applied to types 'I2' and 'I1 & I3'. +tests/cases/conformance/types/typeRelationships/comparable/equalityWithIntersectionTypes01.ts(21,10): error TS2365: Operator '==' cannot be applied to types 'I1 & I3' and 'I2'. +tests/cases/conformance/types/typeRelationships/comparable/equalityWithIntersectionTypes01.ts(21,20): error TS2365: Operator '==' cannot be applied to types 'I2' and 'I1 & I3'. +tests/cases/conformance/types/typeRelationships/comparable/equalityWithIntersectionTypes01.ts(23,10): error TS2365: Operator '!=' cannot be applied to types 'I1 & I3' and 'I2'. +tests/cases/conformance/types/typeRelationships/comparable/equalityWithIntersectionTypes01.ts(23,20): error TS2365: Operator '!=' cannot be applied to types 'I2' and 'I1 & I3'. -==== tests/cases/conformance/types/typeRelationships/matchable/equalityWithIntersectionTypes01.ts (8 errors) ==== +==== tests/cases/conformance/types/typeRelationships/comparable/equalityWithIntersectionTypes01.ts (8 errors) ==== interface I1 { p1: number } diff --git a/tests/baselines/reference/equalityWithUnionTypes01.symbols b/tests/baselines/reference/equalityWithUnionTypes01.symbols index 2baf5034f7741..52332cf2e60d8 100644 --- a/tests/baselines/reference/equalityWithUnionTypes01.symbols +++ b/tests/baselines/reference/equalityWithUnionTypes01.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts === +=== tests/cases/conformance/types/typeRelationships/comparable/equalityWithUnionTypes01.ts === interface I1 { >I1 : Symbol(I1, Decl(equalityWithUnionTypes01.ts, 0, 0)) diff --git a/tests/baselines/reference/equalityWithUnionTypes01.types b/tests/baselines/reference/equalityWithUnionTypes01.types index e6a5ce487d98e..27bf01c048bf4 100644 --- a/tests/baselines/reference/equalityWithUnionTypes01.types +++ b/tests/baselines/reference/equalityWithUnionTypes01.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts === +=== tests/cases/conformance/types/typeRelationships/comparable/equalityWithUnionTypes01.ts === interface I1 { >I1 : I1 diff --git a/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt b/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt index 5c2e8ad30fe90..967a59071af01 100644 --- a/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt +++ b/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithIntersectionTypes01.ts(19,10): error TS2322: Type 'number & boolean' is not assignable to type 'string & number'. +tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts(19,10): error TS2322: Type 'number & boolean' is not assignable to type 'string & number'. Type 'number & boolean' is not assignable to type 'string'. Type 'boolean' is not assignable to type 'string'. -tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithIntersectionTypes01.ts(23,10): error TS2322: Type 'boolean' is not assignable to type 'string & number'. +tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts(23,10): error TS2322: Type 'boolean' is not assignable to type 'string & number'. Type 'boolean' is not assignable to type 'string'. -==== tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithIntersectionTypes01.ts (2 errors) ==== +==== tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts (2 errors) ==== var strAndNum: string & number; var numAndBool: number & boolean; diff --git a/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt b/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt index a59c9ec57f73d..66f01cc1d34b3 100644 --- a/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt +++ b/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithUnionTypes01.ts(23,10): error TS2322: Type 'boolean' is not assignable to type 'string | number'. +tests/cases/conformance/types/typeRelationships/comparable/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 (1 errors) ==== +==== tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithUnionTypes01.ts (1 errors) ==== var strOrNum: string | number; var numOrBool: number | boolean; diff --git a/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt b/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt index b5041f6fe55c1..162e55a225eea 100644 --- a/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt +++ b/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithIntersectionTypes01.ts(17,9): error TS2352: Neither type 'I2' nor type 'I1 & I3' is assignable to the other. +tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts(17,9): error TS2352: Neither type 'I2' nor type 'I1 & I3' is assignable to the other. Type 'I2' is not assignable to type 'I3'. Property 'p3' is missing in type 'I2'. -tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithIntersectionTypes01.ts(18,9): error TS2352: Neither type 'I2' nor type 'I3' is assignable to the other. +tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts(18,9): error TS2352: Neither type 'I2' nor type 'I3' is assignable to the other. -==== tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithIntersectionTypes01.ts (2 errors) ==== +==== tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts (2 errors) ==== interface I1 { p1: number } diff --git a/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt b/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt index 022617c8ba066..68ab174ff9807 100644 --- a/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt +++ b/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt @@ -1,7 +1,7 @@ -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/comparable/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 (1 errors) ==== +==== tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithUnionTypes01.ts (1 errors) ==== interface I1 { p1: number } From e224083038b15ecd20990bd4e4fb223c1928bc9e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 3 Nov 2015 17:17:53 -0800 Subject: [PATCH 14/22] Updated error message. --- src/compiler/checker.ts | 11 +++++++++-- src/compiler/diagnosticMessages.json | 8 ++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ac44a748d6cb6..a804cacb7de11 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4832,7 +4832,14 @@ namespace ts { sourceType = typeToString(source, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType); targetType = typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType); } - reportError(message || Diagnostics.Type_0_is_not_assignable_to_type_1, sourceType, targetType); + + if (!message) { + message = relation === comparableRelation ? + Diagnostics.Type_0_is_not_comparable_with_type_1 : + Diagnostics.Type_0_is_not_assignable_to_type_1 + } + + reportError(message, sourceType, targetType); } // Compare two types and return @@ -9411,7 +9418,7 @@ namespace ts { let widenedType = getWidenedType(exprType); if (!isTypeComparableTo(targetType, widenedType)) { - checkTypeComparableTo(exprType, targetType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); + checkTypeComparableTo(exprType, targetType, node); } } return targetType; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 4fdeb1229831c..4f1b48699181c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -888,6 +888,10 @@ "category": "Error", "code": 2322 }, + "Type '{0}' is not comparable with type '{1}'.": { + "category": "Error", + "code": 2323 + }, "Property '{0}' is missing in type '{1}'.": { "category": "Error", "code": 2324 @@ -996,10 +1000,6 @@ "category": "Error", "code": 2351 }, - "Neither type '{0}' nor type '{1}' is assignable to the other.": { - "category": "Error", - "code": 2352 - }, "Object literal may only specify known properties, and '{0}' does not exist in type '{1}'.": { "category": "Error", "code": 2353 From fa6e181ffaa3ac357f139f551cba71b8d004d70a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 3 Nov 2015 17:29:27 -0800 Subject: [PATCH 15/22] Accepted baselines. --- .../baselines/reference/arrayCast.errors.txt | 10 ++++---- .../reference/asOperator2.errors.txt | 4 ++-- .../asOperatorContextualType.errors.txt | 8 +++---- .../reference/asOperatorNames.errors.txt | 4 ++-- .../reference/castingTuple.errors.txt | 22 ++++++++--------- .../reference/contextualTyping39.errors.txt | 8 +++---- .../reference/contextualTyping41.errors.txt | 8 +++---- ...efaultArgsInFunctionExpressions.errors.txt | 8 +++---- tests/baselines/reference/fuzzy.errors.txt | 6 ++--- .../genericTypeAssertions1.errors.txt | 8 +++---- .../genericTypeAssertions2.errors.txt | 6 ++--- .../genericTypeAssertions4.errors.txt | 8 +++---- .../genericTypeAssertions5.errors.txt | 8 +++---- .../genericTypeAssertions6.errors.txt | 16 ++++++------- .../reference/intTypeCheck.errors.txt | 4 ++-- .../reference/literals-negative.errors.txt | 4 ++-- .../noImplicitAnyInCastExpression.errors.txt | 6 ++--- ...bjectTypesIdentityWithPrivates3.errors.txt | 6 ++--- .../switchAssignmentCompat.errors.txt | 4 ++-- ...itchCaseWithIntersectionTypes01.errors.txt | 20 ++++++++-------- .../switchCaseWithUnionTypes01.errors.txt | 8 +++---- ...itchCasesExpressionTypeMismatch.errors.txt | 12 +++++----- .../reference/switchStatements.errors.txt | 6 ++--- .../reference/typeAssertions.errors.txt | 24 +++++++++---------- ...sertionsWithIntersectionTypes01.errors.txt | 14 +++++------ .../typeAssertionsWithUnionTypes01.errors.txt | 4 ++-- 26 files changed, 118 insertions(+), 118 deletions(-) diff --git a/tests/baselines/reference/arrayCast.errors.txt b/tests/baselines/reference/arrayCast.errors.txt index 815813ea7276b..c73f3ce879cf2 100644 --- a/tests/baselines/reference/arrayCast.errors.txt +++ b/tests/baselines/reference/arrayCast.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/arrayCast.ts(3,23): error TS2352: Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other. - Type '{ foo: string; }' is not assignable to type '{ id: number; }'. +tests/cases/compiler/arrayCast.ts(3,23): error TS2323: Type '{ foo: string; }[]' is not comparable with type '{ id: number; }[]'. + Type '{ foo: string; }' is not comparable with type '{ id: number; }'. Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'. @@ -8,9 +8,9 @@ tests/cases/compiler/arrayCast.ts(3,23): error TS2352: Neither type '{ foo: stri // has type { foo: string }[], which is not assignable to { id: number }[]. <{ id: number; }[]>[{ foo: "s" }]; ~~~~~~~~ -!!! error TS2352: Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other. -!!! error TS2352: Type '{ foo: string; }' is not assignable to type '{ id: number; }'. -!!! error TS2352: Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'. +!!! error TS2323: Type '{ foo: string; }[]' is not comparable with type '{ id: number; }[]'. +!!! error TS2323: Type '{ foo: string; }' is not comparable with type '{ id: number; }'. +!!! error TS2323: Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'. // Should succeed, as the {} element causes the type of the array to be {}[] <{ id: number; }[]>[{ foo: "s" }, {}]; \ No newline at end of file diff --git a/tests/baselines/reference/asOperator2.errors.txt b/tests/baselines/reference/asOperator2.errors.txt index 3b074038c26b0..d3eb568d79a88 100644 --- a/tests/baselines/reference/asOperator2.errors.txt +++ b/tests/baselines/reference/asOperator2.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/expressions/asOperator/asOperator2.ts(1,9): error TS2352: Neither type 'number' nor type 'string' is assignable to the other. +tests/cases/conformance/expressions/asOperator/asOperator2.ts(1,9): error TS2323: Type 'number' is not comparable with type 'string'. ==== tests/cases/conformance/expressions/asOperator/asOperator2.ts (1 errors) ==== var x = 23 as string; ~~~~~~~~~~~~ -!!! error TS2352: Neither type 'number' nor type 'string' is assignable to the other. +!!! error TS2323: Type 'number' is not comparable with type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/asOperatorContextualType.errors.txt b/tests/baselines/reference/asOperatorContextualType.errors.txt index c53b407b5cf02..a2ea2a7f83e73 100644 --- a/tests/baselines/reference/asOperatorContextualType.errors.txt +++ b/tests/baselines/reference/asOperatorContextualType.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/expressions/asOperator/asOperatorContextualType.ts(2,9): error TS2352: Neither type '(v: number) => number' nor type '(x: number) => string' is assignable to the other. - Type 'number' is not assignable to type 'string'. +tests/cases/conformance/expressions/asOperator/asOperatorContextualType.ts(2,9): error TS2323: Type '(v: number) => number' is not comparable with type '(x: number) => string'. + Type 'number' is not comparable with type 'string'. ==== tests/cases/conformance/expressions/asOperator/asOperatorContextualType.ts (1 errors) ==== // should error var x = (v => v) as (x: number) => string; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '(v: number) => number' nor type '(x: number) => string' is assignable to the other. -!!! error TS2352: Type 'number' is not assignable to type 'string'. \ No newline at end of file +!!! error TS2323: Type '(v: number) => number' is not comparable with type '(x: number) => string'. +!!! error TS2323: Type 'number' is not comparable with type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/asOperatorNames.errors.txt b/tests/baselines/reference/asOperatorNames.errors.txt index e3dfaab98845b..61847f5dba15f 100644 --- a/tests/baselines/reference/asOperatorNames.errors.txt +++ b/tests/baselines/reference/asOperatorNames.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/expressions/asOperator/asOperatorNames.ts(2,9): error TS2352: Neither type 'number' nor type 'string' is assignable to the other. +tests/cases/conformance/expressions/asOperator/asOperatorNames.ts(2,9): error TS2323: Type 'number' is not comparable with type 'string'. ==== tests/cases/conformance/expressions/asOperator/asOperatorNames.ts (1 errors) ==== var a = 20; var b = a as string; ~~~~~~~~~~~ -!!! error TS2352: Neither type 'number' nor type 'string' is assignable to the other. +!!! error TS2323: Type 'number' is not comparable with type 'string'. var as = "hello"; var as1 = as as string; \ No newline at end of file diff --git a/tests/baselines/reference/castingTuple.errors.txt b/tests/baselines/reference/castingTuple.errors.txt index 128ee5b5bb497..04caf8e22c593 100644 --- a/tests/baselines/reference/castingTuple.errors.txt +++ b/tests/baselines/reference/castingTuple.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/types/tuple/castingTuple.ts(28,10): error TS2352: Neither type '[number, string]' nor type '[number, number]' is assignable to the other. +tests/cases/conformance/types/tuple/castingTuple.ts(28,10): error TS2323: Type '[number, string]' is not comparable with type '[number, number]'. Types of property '1' are incompatible. - Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/tuple/castingTuple.ts(29,10): error TS2352: Neither type '[C, D]' nor type '[A, I]' is assignable to the other. + Type 'string' is not comparable with type 'number'. +tests/cases/conformance/types/tuple/castingTuple.ts(29,10): error TS2323: Type '[C, D]' is not comparable with type '[A, I]'. Types of property '0' are incompatible. - Type 'C' is not assignable to type 'A'. + Type 'C' is not comparable with type 'A'. Property 'a' is missing in type 'C'. tests/cases/conformance/types/tuple/castingTuple.ts(30,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'. tests/cases/conformance/types/tuple/castingTuple.ts(31,1): error TS2304: Cannot find name 't4'. @@ -39,15 +39,15 @@ tests/cases/conformance/types/tuple/castingTuple.ts(31,1): error TS2304: Cannot // error var t3 = <[number, number]>numStrTuple; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '[number, string]' nor type '[number, number]' is assignable to the other. -!!! error TS2352: Types of property '1' are incompatible. -!!! error TS2352: Type 'string' is not assignable to type 'number'. +!!! error TS2323: Type '[number, string]' is not comparable with type '[number, number]'. +!!! error TS2323: Types of property '1' are incompatible. +!!! error TS2323: Type 'string' is not comparable with type 'number'. var t9 = <[A, I]>classCDTuple; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '[C, D]' nor type '[A, I]' is assignable to the other. -!!! error TS2352: Types of property '0' are incompatible. -!!! error TS2352: Type 'C' is not assignable to type 'A'. -!!! error TS2352: Property 'a' is missing in type 'C'. +!!! error TS2323: Type '[C, D]' is not comparable with type '[A, I]'. +!!! error TS2323: Types of property '0' are incompatible. +!!! error TS2323: Type 'C' is not comparable with type 'A'. +!!! error TS2323: Property 'a' is missing in type 'C'. var array1 = numStrTuple; ~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'. diff --git a/tests/baselines/reference/contextualTyping39.errors.txt b/tests/baselines/reference/contextualTyping39.errors.txt index e43624fbead37..844f302cb5919 100644 --- a/tests/baselines/reference/contextualTyping39.errors.txt +++ b/tests/baselines/reference/contextualTyping39.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/contextualTyping39.ts(1,11): error TS2352: Neither type '() => string' nor type '() => number' is assignable to the other. - Type 'string' is not assignable to type 'number'. +tests/cases/compiler/contextualTyping39.ts(1,11): error TS2323: Type '() => string' is not comparable with type '() => number'. + Type 'string' is not comparable with type 'number'. ==== tests/cases/compiler/contextualTyping39.ts (1 errors) ==== var foo = <{ (): number; }> function() { return "err"; }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '() => string' nor type '() => number' is assignable to the other. -!!! error TS2352: Type 'string' is not assignable to type 'number'. \ No newline at end of file +!!! error TS2323: Type '() => string' is not comparable with type '() => number'. +!!! error TS2323: Type 'string' is not comparable with type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping41.errors.txt b/tests/baselines/reference/contextualTyping41.errors.txt index 1ed6da1b78262..2f1ac620b7ad4 100644 --- a/tests/baselines/reference/contextualTyping41.errors.txt +++ b/tests/baselines/reference/contextualTyping41.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/contextualTyping41.ts(1,11): error TS2352: Neither type '() => string' nor type '{ (): number; (i: number): number; }' is assignable to the other. - Type 'string' is not assignable to type 'number'. +tests/cases/compiler/contextualTyping41.ts(1,11): error TS2323: Type '() => string' is not comparable with type '{ (): number; (i: number): number; }'. + Type 'string' is not comparable with type 'number'. ==== tests/cases/compiler/contextualTyping41.ts (1 errors) ==== var foo = <{():number; (i:number):number; }> (function(){return "err";}); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '() => string' nor type '{ (): number; (i: number): number; }' is assignable to the other. -!!! error TS2352: Type 'string' is not assignable to type 'number'. \ No newline at end of file +!!! error TS2323: Type '() => string' is not comparable with type '{ (): number; (i: number): number; }'. +!!! error TS2323: Type 'string' is not comparable with type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/defaultArgsInFunctionExpressions.errors.txt b/tests/baselines/reference/defaultArgsInFunctionExpressions.errors.txt index 156fdcc4c7a2d..8285101720767 100644 --- a/tests/baselines/reference/defaultArgsInFunctionExpressions.errors.txt +++ b/tests/baselines/reference/defaultArgsInFunctionExpressions.errors.txt @@ -2,9 +2,9 @@ tests/cases/compiler/defaultArgsInFunctionExpressions.ts(4,19): error TS2345: Ar tests/cases/compiler/defaultArgsInFunctionExpressions.ts(5,1): error TS2322: Type 'number' is not assignable to type 'string'. tests/cases/compiler/defaultArgsInFunctionExpressions.ts(8,20): error TS2322: Type 'number' is not assignable to type 'string'. tests/cases/compiler/defaultArgsInFunctionExpressions.ts(11,1): error TS2322: Type 'string' is not assignable to type 'number'. -tests/cases/compiler/defaultArgsInFunctionExpressions.ts(14,51): error TS2352: Neither type 'string' nor type 'number' is assignable to the other. +tests/cases/compiler/defaultArgsInFunctionExpressions.ts(14,51): error TS2323: Type 'string' is not comparable with type 'number'. tests/cases/compiler/defaultArgsInFunctionExpressions.ts(17,41): error TS2322: Type 'string' is not assignable to type 'number'. -tests/cases/compiler/defaultArgsInFunctionExpressions.ts(20,62): error TS2352: Neither type 'string' nor type 'number' is assignable to the other. +tests/cases/compiler/defaultArgsInFunctionExpressions.ts(20,62): error TS2323: Type 'string' is not comparable with type 'number'. tests/cases/compiler/defaultArgsInFunctionExpressions.ts(28,15): error TS2304: Cannot find name 'T'. @@ -32,7 +32,7 @@ tests/cases/compiler/defaultArgsInFunctionExpressions.ts(28,15): error TS2304: C // Contextually type the default arg with the type annotation var f3 = function (a: (s: string) => any = (s) => s) { }; ~~~~~~~~~ -!!! error TS2352: Neither type 'string' nor type 'number' is assignable to the other. +!!! error TS2323: Type 'string' is not comparable with type 'number'. // Type check using the function's contextual type var f4: (a: number) => void = function (a = "") { }; @@ -42,7 +42,7 @@ tests/cases/compiler/defaultArgsInFunctionExpressions.ts(28,15): error TS2304: C // Contextually type the default arg using the function's contextual type var f5: (a: (s: string) => any) => void = function (a = s => s) { }; ~~~~~~~~~ -!!! error TS2352: Neither type 'string' nor type 'number' is assignable to the other. +!!! error TS2323: Type 'string' is not comparable with type 'number'. // Instantiated module module T { } diff --git a/tests/baselines/reference/fuzzy.errors.txt b/tests/baselines/reference/fuzzy.errors.txt index 72ac4c816f9f7..f79bc817a101a 100644 --- a/tests/baselines/reference/fuzzy.errors.txt +++ b/tests/baselines/reference/fuzzy.errors.txt @@ -4,7 +4,7 @@ tests/cases/compiler/fuzzy.ts(21,20): error TS2322: Type '{ anything: number; on Types of property 'oneI' are incompatible. Type 'this' is not assignable to type 'I'. Type 'C' is not assignable to type 'I'. -tests/cases/compiler/fuzzy.ts(25,20): error TS2352: Neither type '{ oneI: this; }' nor type 'R' is assignable to the other. +tests/cases/compiler/fuzzy.ts(25,20): error TS2323: Type '{ oneI: this; }' is not comparable with type 'R'. Property 'anything' is missing in type '{ oneI: this; }'. @@ -43,8 +43,8 @@ tests/cases/compiler/fuzzy.ts(25,20): error TS2352: Neither type '{ oneI: this; worksToo():R { return ({ oneI: this }); ~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '{ oneI: this; }' nor type 'R' is assignable to the other. -!!! error TS2352: Property 'anything' is missing in type '{ oneI: this; }'. +!!! error TS2323: Type '{ oneI: this; }' is not comparable with type 'R'. +!!! error TS2323: Property 'anything' is missing in type '{ oneI: this; }'. } } } diff --git a/tests/baselines/reference/genericTypeAssertions1.errors.txt b/tests/baselines/reference/genericTypeAssertions1.errors.txt index 5479c5f948eae..1e4439ce2ae2e 100644 --- a/tests/baselines/reference/genericTypeAssertions1.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions1.errors.txt @@ -2,8 +2,8 @@ tests/cases/compiler/genericTypeAssertions1.ts(3,5): error TS2322: Type 'A>' is not assignable to type 'A'. Type 'A' is not assignable to type 'number'. -tests/cases/compiler/genericTypeAssertions1.ts(4,21): error TS2352: Neither type 'A' nor type 'A>' is assignable to the other. - Type 'number' is not assignable to type 'A'. +tests/cases/compiler/genericTypeAssertions1.ts(4,21): error TS2323: Type 'A' is not comparable with type 'A>'. + Type 'number' is not comparable with type 'A'. ==== tests/cases/compiler/genericTypeAssertions1.ts (3 errors) ==== @@ -18,5 +18,5 @@ tests/cases/compiler/genericTypeAssertions1.ts(4,21): error TS2352: Neither type !!! error TS2322: Type 'A>' is not assignable to type 'A'. !!! error TS2322: Type 'A' is not assignable to type 'number'. ~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type 'A' nor type 'A>' is assignable to the other. -!!! error TS2352: Type 'number' is not assignable to type 'A'. \ No newline at end of file +!!! error TS2323: Type 'A' is not comparable with type 'A>'. +!!! error TS2323: Type 'number' is not comparable with type 'A'. \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAssertions2.errors.txt b/tests/baselines/reference/genericTypeAssertions2.errors.txt index eda4c83646cde..ce20955ec1a03 100644 --- a/tests/baselines/reference/genericTypeAssertions2.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions2.errors.txt @@ -5,7 +5,7 @@ tests/cases/compiler/genericTypeAssertions2.ts(10,5): error TS2322: Type 'B' is not assignable to type 'B'. Property 'bar' is missing in type 'A'. -tests/cases/compiler/genericTypeAssertions2.ts(13,21): error TS2352: Neither type 'undefined[]' nor type 'A' is assignable to the other. +tests/cases/compiler/genericTypeAssertions2.ts(13,21): error TS2323: Type 'undefined[]' is not comparable with type 'A'. Property 'foo' is missing in type 'undefined[]'. @@ -33,5 +33,5 @@ tests/cases/compiler/genericTypeAssertions2.ts(13,21): error TS2352: Neither typ var r4: A = >new A(); var r5: A = >[]; // error ~~~~~~~~~~~~~ -!!! error TS2352: Neither type 'undefined[]' nor type 'A' is assignable to the other. -!!! error TS2352: Property 'foo' is missing in type 'undefined[]'. \ No newline at end of file +!!! error TS2323: Type 'undefined[]' is not comparable with type 'A'. +!!! error TS2323: Property 'foo' is missing in type 'undefined[]'. \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAssertions4.errors.txt b/tests/baselines/reference/genericTypeAssertions4.errors.txt index 055de774b3921..3456b233f67dd 100644 --- a/tests/baselines/reference/genericTypeAssertions4.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions4.errors.txt @@ -1,8 +1,8 @@ tests/cases/compiler/genericTypeAssertions4.ts(19,5): error TS2322: Type 'A' is not assignable to type 'T'. tests/cases/compiler/genericTypeAssertions4.ts(20,5): error TS2322: Type 'B' is not assignable to type 'T'. tests/cases/compiler/genericTypeAssertions4.ts(21,5): error TS2322: Type 'C' is not assignable to type 'T'. -tests/cases/compiler/genericTypeAssertions4.ts(23,9): error TS2352: Neither type 'B' nor type 'T' is assignable to the other. -tests/cases/compiler/genericTypeAssertions4.ts(24,9): error TS2352: Neither type 'C' nor type 'T' is assignable to the other. +tests/cases/compiler/genericTypeAssertions4.ts(23,9): error TS2323: Type 'B' is not comparable with type 'T'. +tests/cases/compiler/genericTypeAssertions4.ts(24,9): error TS2323: Type 'C' is not comparable with type 'T'. ==== tests/cases/compiler/genericTypeAssertions4.ts (5 errors) ==== @@ -36,8 +36,8 @@ tests/cases/compiler/genericTypeAssertions4.ts(24,9): error TS2352: Neither type y = a; y = b; // error: cannot convert B to T ~~~~ -!!! error TS2352: Neither type 'B' nor type 'T' is assignable to the other. +!!! error TS2323: Type 'B' is not comparable with type 'T'. y = c; // error: cannot convert C to T ~~~~ -!!! error TS2352: Neither type 'C' nor type 'T' is assignable to the other. +!!! error TS2323: Type 'C' is not comparable with type 'T'. } \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAssertions5.errors.txt b/tests/baselines/reference/genericTypeAssertions5.errors.txt index e315a7f122ab9..b621decb06219 100644 --- a/tests/baselines/reference/genericTypeAssertions5.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions5.errors.txt @@ -1,8 +1,8 @@ tests/cases/compiler/genericTypeAssertions5.ts(19,5): error TS2322: Type 'A' is not assignable to type 'T'. tests/cases/compiler/genericTypeAssertions5.ts(20,5): error TS2322: Type 'B' is not assignable to type 'T'. tests/cases/compiler/genericTypeAssertions5.ts(21,5): error TS2322: Type 'C' is not assignable to type 'T'. -tests/cases/compiler/genericTypeAssertions5.ts(23,9): error TS2352: Neither type 'B' nor type 'T' is assignable to the other. -tests/cases/compiler/genericTypeAssertions5.ts(24,9): error TS2352: Neither type 'C' nor type 'T' is assignable to the other. +tests/cases/compiler/genericTypeAssertions5.ts(23,9): error TS2323: Type 'B' is not comparable with type 'T'. +tests/cases/compiler/genericTypeAssertions5.ts(24,9): error TS2323: Type 'C' is not comparable with type 'T'. ==== tests/cases/compiler/genericTypeAssertions5.ts (5 errors) ==== @@ -36,8 +36,8 @@ tests/cases/compiler/genericTypeAssertions5.ts(24,9): error TS2352: Neither type y = a; y = b; // error: cannot convert B to T ~~~~ -!!! error TS2352: Neither type 'B' nor type 'T' is assignable to the other. +!!! error TS2323: Type 'B' is not comparable with type 'T'. y = c; // error: cannot convert C to T ~~~~ -!!! error TS2352: Neither type 'C' nor type 'T' is assignable to the other. +!!! error TS2323: Type 'C' is not comparable with type 'T'. } \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAssertions6.errors.txt b/tests/baselines/reference/genericTypeAssertions6.errors.txt index 29ca99ecb1adc..3637a5cbb5bb8 100644 --- a/tests/baselines/reference/genericTypeAssertions6.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/compiler/genericTypeAssertions6.ts(8,13): error TS2352: Neither type 'U' nor type 'T' is assignable to the other. -tests/cases/compiler/genericTypeAssertions6.ts(9,13): error TS2352: Neither type 'T' nor type 'U' is assignable to the other. -tests/cases/compiler/genericTypeAssertions6.ts(19,17): error TS2352: Neither type 'U' nor type 'T' is assignable to the other. - Type 'Date' is not assignable to type 'T'. +tests/cases/compiler/genericTypeAssertions6.ts(8,13): error TS2323: Type 'U' is not comparable with type 'T'. +tests/cases/compiler/genericTypeAssertions6.ts(9,13): error TS2323: Type 'T' is not comparable with type 'U'. +tests/cases/compiler/genericTypeAssertions6.ts(19,17): error TS2323: Type 'U' is not comparable with type 'T'. + Type 'Date' is not comparable with type 'T'. ==== tests/cases/compiler/genericTypeAssertions6.ts (3 errors) ==== @@ -14,10 +14,10 @@ tests/cases/compiler/genericTypeAssertions6.ts(19,17): error TS2352: Neither typ f(x: T, y: U) { x = y; ~~~~ -!!! error TS2352: Neither type 'U' nor type 'T' is assignable to the other. +!!! error TS2323: Type 'U' is not comparable with type 'T'. y = x; ~~~~ -!!! error TS2352: Neither type 'T' nor type 'U' is assignable to the other. +!!! error TS2323: Type 'T' is not comparable with type 'U'. } } @@ -29,8 +29,8 @@ tests/cases/compiler/genericTypeAssertions6.ts(19,17): error TS2352: Neither typ var d = new Date(); var e = new Date(); ~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type 'U' nor type 'T' is assignable to the other. -!!! error TS2352: Type 'Date' is not assignable to type 'T'. +!!! error TS2323: Type 'U' is not comparable with type 'T'. +!!! error TS2323: Type 'Date' is not comparable with type 'T'. } } diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index e48d1b1dc7303..defcc276844ae 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -61,7 +61,7 @@ tests/cases/compiler/intTypeCheck.ts(176,22): error TS2304: Cannot find name 'i6 tests/cases/compiler/intTypeCheck.ts(177,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(182,5): error TS2322: Type '{}' is not assignable to type 'i7'. tests/cases/compiler/intTypeCheck.ts(183,5): error TS2322: Type 'Object' is not assignable to type 'i7'. -tests/cases/compiler/intTypeCheck.ts(185,17): error TS2352: Neither type 'Base' nor type 'i7' is assignable to the other. +tests/cases/compiler/intTypeCheck.ts(185,17): error TS2323: Type 'Base' is not comparable with type 'i7'. tests/cases/compiler/intTypeCheck.ts(187,5): error TS2322: Type '() => void' is not assignable to type 'i7'. tests/cases/compiler/intTypeCheck.ts(190,5): error TS2322: Type 'boolean' is not assignable to type 'i7'. tests/cases/compiler/intTypeCheck.ts(190,21): error TS1109: Expression expected. @@ -377,7 +377,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj69: i7 = new obj66; var obj70: i7 = new Base; ~~~~~~~~~~~~ -!!! error TS2352: Neither type 'Base' nor type 'i7' is assignable to the other. +!!! error TS2323: Type 'Base' is not comparable with type 'i7'. var obj71: i7 = null; var obj72: i7 = function () { }; ~~~~~ diff --git a/tests/baselines/reference/literals-negative.errors.txt b/tests/baselines/reference/literals-negative.errors.txt index d783e5dfa0212..f2a56614cbc7f 100644 --- a/tests/baselines/reference/literals-negative.errors.txt +++ b/tests/baselines/reference/literals-negative.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/literals-negative.ts(5,9): error TS2352: Neither type 'number' nor type 'boolean' is assignable to the other. +tests/cases/compiler/literals-negative.ts(5,9): error TS2323: Type 'number' is not comparable with type 'boolean'. ==== tests/cases/compiler/literals-negative.ts (1 errors) ==== @@ -8,7 +8,7 @@ tests/cases/compiler/literals-negative.ts(5,9): error TS2352: Neither type 'numb var s = (null); var b = (n); ~~~~~~~~~~~~ -!!! error TS2352: Neither type 'number' nor type 'boolean' is assignable to the other. +!!! error TS2323: Type 'number' is not comparable with type 'boolean'. function isVoid() : void { } diff --git a/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt b/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt index 66a7773ab4993..333a940cc376d 100644 --- a/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt +++ b/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/noImplicitAnyInCastExpression.ts(16,2): error TS2352: Neither type '{ c: null; }' nor type 'IFoo' is assignable to the other. +tests/cases/compiler/noImplicitAnyInCastExpression.ts(16,2): error TS2323: Type '{ c: null; }' is not comparable with type 'IFoo'. Property 'a' is missing in type '{ c: null; }'. @@ -20,5 +20,5 @@ tests/cases/compiler/noImplicitAnyInCastExpression.ts(16,2): error TS2352: Neith // Neither types is assignable to each other ({ c: null }); ~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '{ c: null; }' nor type 'IFoo' is assignable to the other. -!!! error TS2352: Property 'a' is missing in type '{ c: null; }'. \ No newline at end of file +!!! error TS2323: Type '{ c: null; }' is not comparable with type 'IFoo'. +!!! error TS2323: Property 'a' is missing in type '{ c: null; }'. \ No newline at end of file diff --git a/tests/baselines/reference/objectTypesIdentityWithPrivates3.errors.txt b/tests/baselines/reference/objectTypesIdentityWithPrivates3.errors.txt index 9cbaa7300221d..6bd4dfd054471 100644 --- a/tests/baselines/reference/objectTypesIdentityWithPrivates3.errors.txt +++ b/tests/baselines/reference/objectTypesIdentityWithPrivates3.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3.ts(25,1): error TS2352: Neither type 'C3' nor type 'C4' is assignable to the other. +tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3.ts(25,1): error TS2323: Type 'C3' is not comparable with type 'C4'. Property 'y' is missing in type 'C3'. @@ -29,5 +29,5 @@ tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectType var c3: C3; c3; // Should fail (private x originates in the same declaration, but different types) ~~~~~~ -!!! error TS2352: Neither type 'C3' nor type 'C4' is assignable to the other. -!!! error TS2352: Property 'y' is missing in type 'C3'. \ No newline at end of file +!!! error TS2323: Type 'C3' is not comparable with type 'C4'. +!!! error TS2323: Property 'y' is missing in type 'C3'. \ No newline at end of file diff --git a/tests/baselines/reference/switchAssignmentCompat.errors.txt b/tests/baselines/reference/switchAssignmentCompat.errors.txt index 6a2755365ab21..cdfcc423f038c 100644 --- a/tests/baselines/reference/switchAssignmentCompat.errors.txt +++ b/tests/baselines/reference/switchAssignmentCompat.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/switchAssignmentCompat.ts(4,10): error TS2322: Type 'typeof Foo' is not assignable to type 'number'. +tests/cases/compiler/switchAssignmentCompat.ts(4,10): error TS2323: Type 'typeof Foo' is not comparable with type 'number'. ==== tests/cases/compiler/switchAssignmentCompat.ts (1 errors) ==== @@ -7,6 +7,6 @@ tests/cases/compiler/switchAssignmentCompat.ts(4,10): error TS2322: Type 'typeof switch (0) { case Foo: break; // Error expected ~~~ -!!! error TS2322: Type 'typeof Foo' is not assignable to type 'number'. +!!! error TS2323: Type 'typeof Foo' is not comparable with type 'number'. } \ No newline at end of file diff --git a/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt b/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt index 967a59071af01..417d4394bd849 100644 --- a/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt +++ b/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts(19,10): error TS2322: Type 'number & boolean' is not assignable to type 'string & number'. - Type 'number & boolean' is not assignable to type 'string'. - Type 'boolean' is not assignable to type 'string'. -tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts(23,10): error TS2322: Type 'boolean' is not assignable to type 'string & number'. - Type 'boolean' is not assignable to type 'string'. +tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts(19,10): error TS2323: Type 'number & boolean' is not comparable with type 'string & number'. + Type 'number & boolean' is not comparable with type 'string'. + Type 'boolean' is not comparable with type 'string'. +tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts(23,10): error TS2323: Type 'boolean' is not comparable with type 'string & number'. + Type 'boolean' is not comparable with type 'string'. ==== tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts (2 errors) ==== @@ -26,15 +26,15 @@ tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithInterse // Overlap in constituents case numAndBool: ~~~~~~~~~~ -!!! error TS2322: Type 'number & boolean' is not assignable to type 'string & number'. -!!! error TS2322: Type 'number & boolean' is not assignable to type 'string'. -!!! error TS2322: Type 'boolean' is not assignable to type 'string'. +!!! error TS2323: Type 'number & boolean' is not comparable with type 'string & number'. +!!! error TS2323: Type 'number & boolean' is not comparable with type 'string'. +!!! error TS2323: Type 'boolean' is not comparable with type 'string'. 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 'string'. +!!! error TS2323: Type 'boolean' is not comparable with type 'string & number'. +!!! error TS2323: Type 'boolean' is not comparable with type 'string'. break; } \ No newline at end of file diff --git a/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt b/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt index 66f01cc1d34b3..3fbcb4c4658b7 100644 --- a/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt +++ b/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/types/typeRelationships/comparable/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/comparable/switchCaseWithUnionTypes01.ts(23,10): error TS2323: Type 'boolean' is not comparable with type 'string | number'. + Type 'boolean' is not comparable with type 'number'. ==== tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithUnionTypes01.ts (1 errors) ==== @@ -27,7 +27,7 @@ tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithUnionTy // 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'. +!!! error TS2323: Type 'boolean' is not comparable with type 'string | number'. +!!! error TS2323: Type 'boolean' is not comparable with type 'number'. break; } \ No newline at end of file diff --git a/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt b/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt index de739af007d9b..c3009179995ac 100644 --- a/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt +++ b/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(4,10): error TS2322: Type 'typeof Foo' is not assignable to type 'number'. -tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(5,10): error TS2322: Type 'string' is not assignable to type 'number'. -tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2322: Type 'boolean' is not assignable to type 'number'. +tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(4,10): error TS2323: Type 'typeof Foo' is not comparable with type 'number'. +tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(5,10): error TS2323: Type 'string' is not comparable with type 'number'. +tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2323: Type 'boolean' is not comparable with type 'number'. ==== tests/cases/compiler/switchCasesExpressionTypeMismatch.ts (3 errors) ==== @@ -9,14 +9,14 @@ tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2322: T switch (0) { case Foo: break; // Error ~~~ -!!! error TS2322: Type 'typeof Foo' is not assignable to type 'number'. +!!! error TS2323: Type 'typeof Foo' is not comparable with type 'number'. case "sss": break; // Error ~~~~~ -!!! error TS2322: Type 'string' is not assignable to type 'number'. +!!! error TS2323: Type 'string' is not comparable with type 'number'. case 123: break; // No Error case true: break; // Error ~~~~ -!!! error TS2322: Type 'boolean' is not assignable to type 'number'. +!!! error TS2323: Type 'boolean' is not comparable with type 'number'. } var s: any = 0; diff --git a/tests/baselines/reference/switchStatements.errors.txt b/tests/baselines/reference/switchStatements.errors.txt index c99b0eba909a1..eddc9eaa83341 100644 --- a/tests/baselines/reference/switchStatements.errors.txt +++ b/tests/baselines/reference/switchStatements.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/statements/switchStatements/switchStatements.ts(35,20): error TS2322: Type '{ id: number; name: string; }' is not assignable to type 'C'. +tests/cases/conformance/statements/switchStatements/switchStatements.ts(35,20): error TS2323: Type '{ id: number; name: string; }' is not comparable with type 'C'. Object literal may only specify known properties, and 'name' does not exist in type 'C'. @@ -39,8 +39,8 @@ tests/cases/conformance/statements/switchStatements/switchStatements.ts(35,20): case new D(): case { id: 12, name: '' }: ~~~~~~~~ -!!! error TS2322: Type '{ id: number; name: string; }' is not assignable to type 'C'. -!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type 'C'. +!!! error TS2323: Type '{ id: number; name: string; }' is not comparable with type 'C'. +!!! error TS2323: Object literal may only specify known properties, and 'name' does not exist in type 'C'. case new C(): } diff --git a/tests/baselines/reference/typeAssertions.errors.txt b/tests/baselines/reference/typeAssertions.errors.txt index a2ad28801c8cd..1e9e45171f60f 100644 --- a/tests/baselines/reference/typeAssertions.errors.txt +++ b/tests/baselines/reference/typeAssertions.errors.txt @@ -1,11 +1,11 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(5,5): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(31,12): error TS2352: Neither type 'SomeOther' nor type 'SomeBase' is assignable to the other. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(31,12): error TS2323: Type 'SomeOther' is not comparable with type 'SomeBase'. Property 'p' is missing in type 'SomeOther'. -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(35,15): error TS2352: Neither type 'SomeOther' nor type 'SomeDerived' is assignable to the other. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(35,15): error TS2323: Type 'SomeOther' is not comparable with type 'SomeDerived'. Property 'x' is missing in type 'SomeOther'. -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(37,13): error TS2352: Neither type 'SomeDerived' nor type 'SomeOther' is assignable to the other. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(37,13): error TS2323: Type 'SomeDerived' is not comparable with type 'SomeOther'. Property 'q' is missing in type 'SomeDerived'. -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(38,13): error TS2352: Neither type 'SomeBase' nor type 'SomeOther' is assignable to the other. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(38,13): error TS2323: Type 'SomeBase' is not comparable with type 'SomeOther'. Property 'q' is missing in type 'SomeBase'. @@ -44,24 +44,24 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(38,13): err someBase = someBase; someBase = someOther; // Error ~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type 'SomeOther' nor type 'SomeBase' is assignable to the other. -!!! error TS2352: Property 'p' is missing in type 'SomeOther'. +!!! error TS2323: Type 'SomeOther' is not comparable with type 'SomeBase'. +!!! error TS2323: Property 'p' is missing in type 'SomeOther'. someDerived = someDerived; someDerived = someBase; someDerived = someOther; // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type 'SomeOther' nor type 'SomeDerived' is assignable to the other. -!!! error TS2352: Property 'x' is missing in type 'SomeOther'. +!!! error TS2323: Type 'SomeOther' is not comparable with type 'SomeDerived'. +!!! error TS2323: Property 'x' is missing in type 'SomeOther'. someOther = someDerived; // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type 'SomeDerived' nor type 'SomeOther' is assignable to the other. -!!! error TS2352: Property 'q' is missing in type 'SomeDerived'. +!!! error TS2323: Type 'SomeDerived' is not comparable with type 'SomeOther'. +!!! error TS2323: Property 'q' is missing in type 'SomeDerived'. someOther = someBase; // Error ~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type 'SomeBase' nor type 'SomeOther' is assignable to the other. -!!! error TS2352: Property 'q' is missing in type 'SomeBase'. +!!! error TS2323: Type 'SomeBase' is not comparable with type 'SomeOther'. +!!! error TS2323: Property 'q' is missing in type 'SomeBase'. someOther = someOther; diff --git a/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt b/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt index 162e55a225eea..1b0cd98533d3d 100644 --- a/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt +++ b/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts(17,9): error TS2352: Neither type 'I2' nor type 'I1 & I3' is assignable to the other. - Type 'I2' is not assignable to type 'I3'. +tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts(17,9): error TS2323: Type 'I2' is not comparable with type 'I1 & I3'. + Type 'I2' is not comparable with type 'I3'. Property 'p3' is missing in type 'I2'. -tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts(18,9): error TS2352: Neither type 'I2' nor type 'I3' is assignable to the other. +tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts(18,9): error TS2323: Type 'I2' is not comparable with type 'I3'. ==== tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts (2 errors) ==== @@ -23,12 +23,12 @@ tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithInt var a = z; ~~~~~~~~~~ -!!! error TS2352: Neither type 'I2' nor type 'I1 & I3' is assignable to the other. -!!! error TS2352: Type 'I2' is not assignable to type 'I3'. -!!! error TS2352: Property 'p3' is missing in type 'I2'. +!!! error TS2323: Type 'I2' is not comparable with type 'I1 & I3'. +!!! error TS2323: Type 'I2' is not comparable with type 'I3'. +!!! error TS2323: Property 'p3' is missing in type 'I2'. var b = z; ~~~~~ -!!! error TS2352: Neither type 'I2' nor type 'I3' is assignable to the other. +!!! error TS2323: Type 'I2' is not comparable with type 'I3'. var c = z; var d = y; \ No newline at end of file diff --git a/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt b/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt index 68ab174ff9807..21d1bccdd5d95 100644 --- a/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt +++ b/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithUnionTypes01.ts(14,9): error TS2352: Neither type 'I1' nor type 'number' is assignable to the other. +tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithUnionTypes01.ts(14,9): error TS2323: Type 'I1' is not comparable with type 'number'. ==== tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithUnionTypes01.ts (1 errors) ==== @@ -17,7 +17,7 @@ tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithUni var a = z; var b = z; ~~~~~~~~~ -!!! error TS2352: Neither type 'I1' nor type 'number' is assignable to the other. +!!! error TS2323: Type 'I1' is not comparable with type 'number'. var c = z; var d = y; \ No newline at end of file From 80a50aa104054df7846d244bfbc5ed1ecfa408ac Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 3 Nov 2015 17:39:53 -0800 Subject: [PATCH 16/22] Appease the almighty linter. --- src/compiler/checker.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a804cacb7de11..9d069a547d970 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4832,13 +4832,13 @@ namespace ts { sourceType = typeToString(source, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType); targetType = typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType); } - + if (!message) { message = relation === comparableRelation ? Diagnostics.Type_0_is_not_comparable_with_type_1 : - Diagnostics.Type_0_is_not_assignable_to_type_1 + Diagnostics.Type_0_is_not_assignable_to_type_1; } - + reportError(message, sourceType, targetType); } From 42c49cea0d1b393ab57bf748ae1c3bb42e00ca57 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 4 Nov 2015 13:05:46 -0800 Subject: [PATCH 17/22] Style. --- src/compiler/checker.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9d069a547d970..f16722b7c5785 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4882,13 +4882,13 @@ namespace ts { let saveErrorInfo = errorInfo; - // Note that the "each" checks must precede the "some" checks to produce the correct results + // Note that these checks are specifically ordered to produce correct results. if (source.flags & TypeFlags.Union) { if (relation === comparableRelation) { result = someTypeRelatedToType(source as UnionType, target, reportErrors); } else { - result = eachTypeRelatedToType(source, target, reportErrors); + result = eachTypeRelatedToType(source as UnionType, target, reportErrors); } if (result) { @@ -4896,25 +4896,25 @@ namespace ts { } } else if (target.flags & TypeFlags.Intersection) { - result = typeRelatedToEachType(source, target, reportErrors); + result = typeRelatedToEachType(source, target as IntersectionType, reportErrors); if (result) { return result; } } else { - // It is necessary to try "some" checks on both sides because there may be nested "each" checks + // It is necessary to try these "some" checks on both sides because there may be nested "each" checks // on either side that need to be prioritized. For example, A | B = (A | B) & (C | D) or // A & B = (A & B) | (C & D). if (source.flags & TypeFlags.Intersection) { // If target is a union type then the check following this one will report errors, // so we'll suppress any errors we could run into here. - if (result = someTypeRelatedToType(source, target, reportErrors && !(target.flags & TypeFlags.Union))) { + if (result = someTypeRelatedToType(source as IntersectionType, target, reportErrors && !(target.flags & TypeFlags.Union))) { return result; } } if (target.flags & TypeFlags.Union) { - if (result = typeRelatedToSomeType(source, target, reportErrors)) { + if (result = typeRelatedToSomeType(source, target as UnionType, reportErrors)) { return result; } } @@ -12727,6 +12727,7 @@ namespace ts { let caseClause = clause; // TypeScript 1.0 spec (April 2014): 5.9 // In a 'switch' statement, each 'case' expression must be of a type that is assignable to or from the type of the 'switch' expression. + // TODO (drosen): this needs to be amended to reflect the "comparable" relationship. let caseType = checkExpression(caseClause.expression); if (!isTypeComparableTo(expressionType, caseType)) { From 6c8c1223f29bbd657cb042fef80f0fa0ccf39226 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 4 Nov 2015 13:19:15 -0800 Subject: [PATCH 18/22] 'with' to 'to' --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f16722b7c5785..1d859cee660f7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4835,7 +4835,7 @@ namespace ts { if (!message) { message = relation === comparableRelation ? - Diagnostics.Type_0_is_not_comparable_with_type_1 : + Diagnostics.Type_0_is_not_comparable_to_type_1 : Diagnostics.Type_0_is_not_assignable_to_type_1; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 4f1b48699181c..c295a8281757a 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -888,7 +888,7 @@ "category": "Error", "code": 2322 }, - "Type '{0}' is not comparable with type '{1}'.": { + "Type '{0}' is not comparable to type '{1}'.": { "category": "Error", "code": 2323 }, From f6eacb9606bd983e91d18719d4b06a357c7fa837 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 4 Nov 2015 13:19:56 -0800 Subject: [PATCH 19/22] Accepted baselines. --- .../baselines/reference/arrayCast.errors.txt | 8 ++++---- .../reference/asOperator2.errors.txt | 4 ++-- .../asOperatorContextualType.errors.txt | 8 ++++---- .../reference/asOperatorNames.errors.txt | 4 ++-- .../reference/castingTuple.errors.txt | 16 +++++++-------- .../reference/contextualTyping39.errors.txt | 8 ++++---- .../reference/contextualTyping41.errors.txt | 8 ++++---- ...efaultArgsInFunctionExpressions.errors.txt | 8 ++++---- tests/baselines/reference/fuzzy.errors.txt | 4 ++-- .../genericTypeAssertions1.errors.txt | 8 ++++---- .../genericTypeAssertions2.errors.txt | 4 ++-- .../genericTypeAssertions4.errors.txt | 8 ++++---- .../genericTypeAssertions5.errors.txt | 8 ++++---- .../genericTypeAssertions6.errors.txt | 16 +++++++-------- .../reference/intTypeCheck.errors.txt | 4 ++-- .../reference/literals-negative.errors.txt | 4 ++-- .../noImplicitAnyInCastExpression.errors.txt | 4 ++-- ...bjectTypesIdentityWithPrivates3.errors.txt | 4 ++-- .../switchAssignmentCompat.errors.txt | 4 ++-- ...itchCaseWithIntersectionTypes01.errors.txt | 20 +++++++++---------- .../switchCaseWithUnionTypes01.errors.txt | 8 ++++---- ...itchCasesExpressionTypeMismatch.errors.txt | 12 +++++------ .../reference/switchStatements.errors.txt | 4 ++-- .../reference/typeAssertions.errors.txt | 16 +++++++-------- ...sertionsWithIntersectionTypes01.errors.txt | 12 +++++------ .../typeAssertionsWithUnionTypes01.errors.txt | 4 ++-- 26 files changed, 104 insertions(+), 104 deletions(-) diff --git a/tests/baselines/reference/arrayCast.errors.txt b/tests/baselines/reference/arrayCast.errors.txt index c73f3ce879cf2..bb895475a18e9 100644 --- a/tests/baselines/reference/arrayCast.errors.txt +++ b/tests/baselines/reference/arrayCast.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/arrayCast.ts(3,23): error TS2323: Type '{ foo: string; }[]' is not comparable with type '{ id: number; }[]'. - Type '{ foo: string; }' is not comparable with type '{ id: number; }'. +tests/cases/compiler/arrayCast.ts(3,23): error TS2323: Type '{ foo: string; }[]' is not comparable to type '{ id: number; }[]'. + Type '{ foo: string; }' is not comparable to type '{ id: number; }'. Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'. @@ -8,8 +8,8 @@ tests/cases/compiler/arrayCast.ts(3,23): error TS2323: Type '{ foo: string; }[]' // has type { foo: string }[], which is not assignable to { id: number }[]. <{ id: number; }[]>[{ foo: "s" }]; ~~~~~~~~ -!!! error TS2323: Type '{ foo: string; }[]' is not comparable with type '{ id: number; }[]'. -!!! error TS2323: Type '{ foo: string; }' is not comparable with type '{ id: number; }'. +!!! error TS2323: Type '{ foo: string; }[]' is not comparable to type '{ id: number; }[]'. +!!! error TS2323: Type '{ foo: string; }' is not comparable to type '{ id: number; }'. !!! error TS2323: Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'. // Should succeed, as the {} element causes the type of the array to be {}[] diff --git a/tests/baselines/reference/asOperator2.errors.txt b/tests/baselines/reference/asOperator2.errors.txt index d3eb568d79a88..0930191aae190 100644 --- a/tests/baselines/reference/asOperator2.errors.txt +++ b/tests/baselines/reference/asOperator2.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/expressions/asOperator/asOperator2.ts(1,9): error TS2323: Type 'number' is not comparable with type 'string'. +tests/cases/conformance/expressions/asOperator/asOperator2.ts(1,9): error TS2323: Type 'number' is not comparable to type 'string'. ==== tests/cases/conformance/expressions/asOperator/asOperator2.ts (1 errors) ==== var x = 23 as string; ~~~~~~~~~~~~ -!!! error TS2323: Type 'number' is not comparable with type 'string'. +!!! error TS2323: Type 'number' is not comparable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/asOperatorContextualType.errors.txt b/tests/baselines/reference/asOperatorContextualType.errors.txt index a2ea2a7f83e73..1a6cf43827c78 100644 --- a/tests/baselines/reference/asOperatorContextualType.errors.txt +++ b/tests/baselines/reference/asOperatorContextualType.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/expressions/asOperator/asOperatorContextualType.ts(2,9): error TS2323: Type '(v: number) => number' is not comparable with type '(x: number) => string'. - Type 'number' is not comparable with type 'string'. +tests/cases/conformance/expressions/asOperator/asOperatorContextualType.ts(2,9): error TS2323: Type '(v: number) => number' is not comparable to type '(x: number) => string'. + Type 'number' is not comparable to type 'string'. ==== tests/cases/conformance/expressions/asOperator/asOperatorContextualType.ts (1 errors) ==== // should error var x = (v => v) as (x: number) => string; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type '(v: number) => number' is not comparable with type '(x: number) => string'. -!!! error TS2323: Type 'number' is not comparable with type 'string'. \ No newline at end of file +!!! error TS2323: Type '(v: number) => number' is not comparable to type '(x: number) => string'. +!!! error TS2323: Type 'number' is not comparable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/asOperatorNames.errors.txt b/tests/baselines/reference/asOperatorNames.errors.txt index 61847f5dba15f..f4ef8a64e2ba6 100644 --- a/tests/baselines/reference/asOperatorNames.errors.txt +++ b/tests/baselines/reference/asOperatorNames.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/expressions/asOperator/asOperatorNames.ts(2,9): error TS2323: Type 'number' is not comparable with type 'string'. +tests/cases/conformance/expressions/asOperator/asOperatorNames.ts(2,9): error TS2323: Type 'number' is not comparable to type 'string'. ==== tests/cases/conformance/expressions/asOperator/asOperatorNames.ts (1 errors) ==== var a = 20; var b = a as string; ~~~~~~~~~~~ -!!! error TS2323: Type 'number' is not comparable with type 'string'. +!!! error TS2323: Type 'number' is not comparable to type 'string'. var as = "hello"; var as1 = as as string; \ No newline at end of file diff --git a/tests/baselines/reference/castingTuple.errors.txt b/tests/baselines/reference/castingTuple.errors.txt index 04caf8e22c593..4430c932bfceb 100644 --- a/tests/baselines/reference/castingTuple.errors.txt +++ b/tests/baselines/reference/castingTuple.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/types/tuple/castingTuple.ts(28,10): error TS2323: Type '[number, string]' is not comparable with type '[number, number]'. +tests/cases/conformance/types/tuple/castingTuple.ts(28,10): error TS2323: Type '[number, string]' is not comparable to type '[number, number]'. Types of property '1' are incompatible. - Type 'string' is not comparable with type 'number'. -tests/cases/conformance/types/tuple/castingTuple.ts(29,10): error TS2323: Type '[C, D]' is not comparable with type '[A, I]'. + Type 'string' is not comparable to type 'number'. +tests/cases/conformance/types/tuple/castingTuple.ts(29,10): error TS2323: Type '[C, D]' is not comparable to type '[A, I]'. Types of property '0' are incompatible. - Type 'C' is not comparable with type 'A'. + Type 'C' is not comparable to type 'A'. Property 'a' is missing in type 'C'. tests/cases/conformance/types/tuple/castingTuple.ts(30,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'. tests/cases/conformance/types/tuple/castingTuple.ts(31,1): error TS2304: Cannot find name 't4'. @@ -39,14 +39,14 @@ tests/cases/conformance/types/tuple/castingTuple.ts(31,1): error TS2304: Cannot // error var t3 = <[number, number]>numStrTuple; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type '[number, string]' is not comparable with type '[number, number]'. +!!! error TS2323: Type '[number, string]' is not comparable to type '[number, number]'. !!! error TS2323: Types of property '1' are incompatible. -!!! error TS2323: Type 'string' is not comparable with type 'number'. +!!! error TS2323: Type 'string' is not comparable to type 'number'. var t9 = <[A, I]>classCDTuple; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type '[C, D]' is not comparable with type '[A, I]'. +!!! error TS2323: Type '[C, D]' is not comparable to type '[A, I]'. !!! error TS2323: Types of property '0' are incompatible. -!!! error TS2323: Type 'C' is not comparable with type 'A'. +!!! error TS2323: Type 'C' is not comparable to type 'A'. !!! error TS2323: Property 'a' is missing in type 'C'. var array1 = numStrTuple; ~~~~~~ diff --git a/tests/baselines/reference/contextualTyping39.errors.txt b/tests/baselines/reference/contextualTyping39.errors.txt index 844f302cb5919..bb797c6a43ece 100644 --- a/tests/baselines/reference/contextualTyping39.errors.txt +++ b/tests/baselines/reference/contextualTyping39.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/contextualTyping39.ts(1,11): error TS2323: Type '() => string' is not comparable with type '() => number'. - Type 'string' is not comparable with type 'number'. +tests/cases/compiler/contextualTyping39.ts(1,11): error TS2323: Type '() => string' is not comparable to type '() => number'. + Type 'string' is not comparable to type 'number'. ==== tests/cases/compiler/contextualTyping39.ts (1 errors) ==== var foo = <{ (): number; }> function() { return "err"; }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type '() => string' is not comparable with type '() => number'. -!!! error TS2323: Type 'string' is not comparable with type 'number'. \ No newline at end of file +!!! error TS2323: Type '() => string' is not comparable to type '() => number'. +!!! error TS2323: Type 'string' is not comparable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping41.errors.txt b/tests/baselines/reference/contextualTyping41.errors.txt index 2f1ac620b7ad4..e3261e1184350 100644 --- a/tests/baselines/reference/contextualTyping41.errors.txt +++ b/tests/baselines/reference/contextualTyping41.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/contextualTyping41.ts(1,11): error TS2323: Type '() => string' is not comparable with type '{ (): number; (i: number): number; }'. - Type 'string' is not comparable with type 'number'. +tests/cases/compiler/contextualTyping41.ts(1,11): error TS2323: Type '() => string' is not comparable to type '{ (): number; (i: number): number; }'. + Type 'string' is not comparable to type 'number'. ==== tests/cases/compiler/contextualTyping41.ts (1 errors) ==== var foo = <{():number; (i:number):number; }> (function(){return "err";}); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type '() => string' is not comparable with type '{ (): number; (i: number): number; }'. -!!! error TS2323: Type 'string' is not comparable with type 'number'. \ No newline at end of file +!!! error TS2323: Type '() => string' is not comparable to type '{ (): number; (i: number): number; }'. +!!! error TS2323: Type 'string' is not comparable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/defaultArgsInFunctionExpressions.errors.txt b/tests/baselines/reference/defaultArgsInFunctionExpressions.errors.txt index 8285101720767..7b7166843c39d 100644 --- a/tests/baselines/reference/defaultArgsInFunctionExpressions.errors.txt +++ b/tests/baselines/reference/defaultArgsInFunctionExpressions.errors.txt @@ -2,9 +2,9 @@ tests/cases/compiler/defaultArgsInFunctionExpressions.ts(4,19): error TS2345: Ar tests/cases/compiler/defaultArgsInFunctionExpressions.ts(5,1): error TS2322: Type 'number' is not assignable to type 'string'. tests/cases/compiler/defaultArgsInFunctionExpressions.ts(8,20): error TS2322: Type 'number' is not assignable to type 'string'. tests/cases/compiler/defaultArgsInFunctionExpressions.ts(11,1): error TS2322: Type 'string' is not assignable to type 'number'. -tests/cases/compiler/defaultArgsInFunctionExpressions.ts(14,51): error TS2323: Type 'string' is not comparable with type 'number'. +tests/cases/compiler/defaultArgsInFunctionExpressions.ts(14,51): error TS2323: Type 'string' is not comparable to type 'number'. tests/cases/compiler/defaultArgsInFunctionExpressions.ts(17,41): error TS2322: Type 'string' is not assignable to type 'number'. -tests/cases/compiler/defaultArgsInFunctionExpressions.ts(20,62): error TS2323: Type 'string' is not comparable with type 'number'. +tests/cases/compiler/defaultArgsInFunctionExpressions.ts(20,62): error TS2323: Type 'string' is not comparable to type 'number'. tests/cases/compiler/defaultArgsInFunctionExpressions.ts(28,15): error TS2304: Cannot find name 'T'. @@ -32,7 +32,7 @@ tests/cases/compiler/defaultArgsInFunctionExpressions.ts(28,15): error TS2304: C // Contextually type the default arg with the type annotation var f3 = function (a: (s: string) => any = (s) => s) { }; ~~~~~~~~~ -!!! error TS2323: Type 'string' is not comparable with type 'number'. +!!! error TS2323: Type 'string' is not comparable to type 'number'. // Type check using the function's contextual type var f4: (a: number) => void = function (a = "") { }; @@ -42,7 +42,7 @@ tests/cases/compiler/defaultArgsInFunctionExpressions.ts(28,15): error TS2304: C // Contextually type the default arg using the function's contextual type var f5: (a: (s: string) => any) => void = function (a = s => s) { }; ~~~~~~~~~ -!!! error TS2323: Type 'string' is not comparable with type 'number'. +!!! error TS2323: Type 'string' is not comparable to type 'number'. // Instantiated module module T { } diff --git a/tests/baselines/reference/fuzzy.errors.txt b/tests/baselines/reference/fuzzy.errors.txt index f79bc817a101a..f39b520759c94 100644 --- a/tests/baselines/reference/fuzzy.errors.txt +++ b/tests/baselines/reference/fuzzy.errors.txt @@ -4,7 +4,7 @@ tests/cases/compiler/fuzzy.ts(21,20): error TS2322: Type '{ anything: number; on Types of property 'oneI' are incompatible. Type 'this' is not assignable to type 'I'. Type 'C' is not assignable to type 'I'. -tests/cases/compiler/fuzzy.ts(25,20): error TS2323: Type '{ oneI: this; }' is not comparable with type 'R'. +tests/cases/compiler/fuzzy.ts(25,20): error TS2323: Type '{ oneI: this; }' is not comparable to type 'R'. Property 'anything' is missing in type '{ oneI: this; }'. @@ -43,7 +43,7 @@ tests/cases/compiler/fuzzy.ts(25,20): error TS2323: Type '{ oneI: this; }' is no worksToo():R { return ({ oneI: this }); ~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type '{ oneI: this; }' is not comparable with type 'R'. +!!! error TS2323: Type '{ oneI: this; }' is not comparable to type 'R'. !!! error TS2323: Property 'anything' is missing in type '{ oneI: this; }'. } } diff --git a/tests/baselines/reference/genericTypeAssertions1.errors.txt b/tests/baselines/reference/genericTypeAssertions1.errors.txt index 1e4439ce2ae2e..3e0157f98637b 100644 --- a/tests/baselines/reference/genericTypeAssertions1.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions1.errors.txt @@ -2,8 +2,8 @@ tests/cases/compiler/genericTypeAssertions1.ts(3,5): error TS2322: Type 'A>' is not assignable to type 'A'. Type 'A' is not assignable to type 'number'. -tests/cases/compiler/genericTypeAssertions1.ts(4,21): error TS2323: Type 'A' is not comparable with type 'A>'. - Type 'number' is not comparable with type 'A'. +tests/cases/compiler/genericTypeAssertions1.ts(4,21): error TS2323: Type 'A' is not comparable to type 'A>'. + Type 'number' is not comparable to type 'A'. ==== tests/cases/compiler/genericTypeAssertions1.ts (3 errors) ==== @@ -18,5 +18,5 @@ tests/cases/compiler/genericTypeAssertions1.ts(4,21): error TS2323: Type 'A>' is not assignable to type 'A'. !!! error TS2322: Type 'A' is not assignable to type 'number'. ~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type 'A' is not comparable with type 'A>'. -!!! error TS2323: Type 'number' is not comparable with type 'A'. \ No newline at end of file +!!! error TS2323: Type 'A' is not comparable to type 'A>'. +!!! error TS2323: Type 'number' is not comparable to type 'A'. \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAssertions2.errors.txt b/tests/baselines/reference/genericTypeAssertions2.errors.txt index ce20955ec1a03..908255b1d3399 100644 --- a/tests/baselines/reference/genericTypeAssertions2.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions2.errors.txt @@ -5,7 +5,7 @@ tests/cases/compiler/genericTypeAssertions2.ts(10,5): error TS2322: Type 'B' is not assignable to type 'B'. Property 'bar' is missing in type 'A'. -tests/cases/compiler/genericTypeAssertions2.ts(13,21): error TS2323: Type 'undefined[]' is not comparable with type 'A'. +tests/cases/compiler/genericTypeAssertions2.ts(13,21): error TS2323: Type 'undefined[]' is not comparable to type 'A'. Property 'foo' is missing in type 'undefined[]'. @@ -33,5 +33,5 @@ tests/cases/compiler/genericTypeAssertions2.ts(13,21): error TS2323: Type 'undef var r4: A = >new A(); var r5: A = >[]; // error ~~~~~~~~~~~~~ -!!! error TS2323: Type 'undefined[]' is not comparable with type 'A'. +!!! error TS2323: Type 'undefined[]' is not comparable to type 'A'. !!! error TS2323: Property 'foo' is missing in type 'undefined[]'. \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAssertions4.errors.txt b/tests/baselines/reference/genericTypeAssertions4.errors.txt index 3456b233f67dd..cffacb6b0dc4c 100644 --- a/tests/baselines/reference/genericTypeAssertions4.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions4.errors.txt @@ -1,8 +1,8 @@ tests/cases/compiler/genericTypeAssertions4.ts(19,5): error TS2322: Type 'A' is not assignable to type 'T'. tests/cases/compiler/genericTypeAssertions4.ts(20,5): error TS2322: Type 'B' is not assignable to type 'T'. tests/cases/compiler/genericTypeAssertions4.ts(21,5): error TS2322: Type 'C' is not assignable to type 'T'. -tests/cases/compiler/genericTypeAssertions4.ts(23,9): error TS2323: Type 'B' is not comparable with type 'T'. -tests/cases/compiler/genericTypeAssertions4.ts(24,9): error TS2323: Type 'C' is not comparable with type 'T'. +tests/cases/compiler/genericTypeAssertions4.ts(23,9): error TS2323: Type 'B' is not comparable to type 'T'. +tests/cases/compiler/genericTypeAssertions4.ts(24,9): error TS2323: Type 'C' is not comparable to type 'T'. ==== tests/cases/compiler/genericTypeAssertions4.ts (5 errors) ==== @@ -36,8 +36,8 @@ tests/cases/compiler/genericTypeAssertions4.ts(24,9): error TS2323: Type 'C' is y = a; y = b; // error: cannot convert B to T ~~~~ -!!! error TS2323: Type 'B' is not comparable with type 'T'. +!!! error TS2323: Type 'B' is not comparable to type 'T'. y = c; // error: cannot convert C to T ~~~~ -!!! error TS2323: Type 'C' is not comparable with type 'T'. +!!! error TS2323: Type 'C' is not comparable to type 'T'. } \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAssertions5.errors.txt b/tests/baselines/reference/genericTypeAssertions5.errors.txt index b621decb06219..f7f2be41825f6 100644 --- a/tests/baselines/reference/genericTypeAssertions5.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions5.errors.txt @@ -1,8 +1,8 @@ tests/cases/compiler/genericTypeAssertions5.ts(19,5): error TS2322: Type 'A' is not assignable to type 'T'. tests/cases/compiler/genericTypeAssertions5.ts(20,5): error TS2322: Type 'B' is not assignable to type 'T'. tests/cases/compiler/genericTypeAssertions5.ts(21,5): error TS2322: Type 'C' is not assignable to type 'T'. -tests/cases/compiler/genericTypeAssertions5.ts(23,9): error TS2323: Type 'B' is not comparable with type 'T'. -tests/cases/compiler/genericTypeAssertions5.ts(24,9): error TS2323: Type 'C' is not comparable with type 'T'. +tests/cases/compiler/genericTypeAssertions5.ts(23,9): error TS2323: Type 'B' is not comparable to type 'T'. +tests/cases/compiler/genericTypeAssertions5.ts(24,9): error TS2323: Type 'C' is not comparable to type 'T'. ==== tests/cases/compiler/genericTypeAssertions5.ts (5 errors) ==== @@ -36,8 +36,8 @@ tests/cases/compiler/genericTypeAssertions5.ts(24,9): error TS2323: Type 'C' is y = a; y = b; // error: cannot convert B to T ~~~~ -!!! error TS2323: Type 'B' is not comparable with type 'T'. +!!! error TS2323: Type 'B' is not comparable to type 'T'. y = c; // error: cannot convert C to T ~~~~ -!!! error TS2323: Type 'C' is not comparable with type 'T'. +!!! error TS2323: Type 'C' is not comparable to type 'T'. } \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAssertions6.errors.txt b/tests/baselines/reference/genericTypeAssertions6.errors.txt index 3637a5cbb5bb8..4ea7d3602ebd8 100644 --- a/tests/baselines/reference/genericTypeAssertions6.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/compiler/genericTypeAssertions6.ts(8,13): error TS2323: Type 'U' is not comparable with type 'T'. -tests/cases/compiler/genericTypeAssertions6.ts(9,13): error TS2323: Type 'T' is not comparable with type 'U'. -tests/cases/compiler/genericTypeAssertions6.ts(19,17): error TS2323: Type 'U' is not comparable with type 'T'. - Type 'Date' is not comparable with type 'T'. +tests/cases/compiler/genericTypeAssertions6.ts(8,13): error TS2323: Type 'U' is not comparable to type 'T'. +tests/cases/compiler/genericTypeAssertions6.ts(9,13): error TS2323: Type 'T' is not comparable to type 'U'. +tests/cases/compiler/genericTypeAssertions6.ts(19,17): error TS2323: Type 'U' is not comparable to type 'T'. + Type 'Date' is not comparable to type 'T'. ==== tests/cases/compiler/genericTypeAssertions6.ts (3 errors) ==== @@ -14,10 +14,10 @@ tests/cases/compiler/genericTypeAssertions6.ts(19,17): error TS2323: Type 'U' is f(x: T, y: U) { x = y; ~~~~ -!!! error TS2323: Type 'U' is not comparable with type 'T'. +!!! error TS2323: Type 'U' is not comparable to type 'T'. y = x; ~~~~ -!!! error TS2323: Type 'T' is not comparable with type 'U'. +!!! error TS2323: Type 'T' is not comparable to type 'U'. } } @@ -29,8 +29,8 @@ tests/cases/compiler/genericTypeAssertions6.ts(19,17): error TS2323: Type 'U' is var d = new Date(); var e = new Date(); ~~~~~~~~~~~~~~~~ -!!! error TS2323: Type 'U' is not comparable with type 'T'. -!!! error TS2323: Type 'Date' is not comparable with type 'T'. +!!! error TS2323: Type 'U' is not comparable to type 'T'. +!!! error TS2323: Type 'Date' is not comparable to type 'T'. } } diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index defcc276844ae..175c5ea7979b7 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -61,7 +61,7 @@ tests/cases/compiler/intTypeCheck.ts(176,22): error TS2304: Cannot find name 'i6 tests/cases/compiler/intTypeCheck.ts(177,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(182,5): error TS2322: Type '{}' is not assignable to type 'i7'. tests/cases/compiler/intTypeCheck.ts(183,5): error TS2322: Type 'Object' is not assignable to type 'i7'. -tests/cases/compiler/intTypeCheck.ts(185,17): error TS2323: Type 'Base' is not comparable with type 'i7'. +tests/cases/compiler/intTypeCheck.ts(185,17): error TS2323: Type 'Base' is not comparable to type 'i7'. tests/cases/compiler/intTypeCheck.ts(187,5): error TS2322: Type '() => void' is not assignable to type 'i7'. tests/cases/compiler/intTypeCheck.ts(190,5): error TS2322: Type 'boolean' is not assignable to type 'i7'. tests/cases/compiler/intTypeCheck.ts(190,21): error TS1109: Expression expected. @@ -377,7 +377,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj69: i7 = new obj66; var obj70: i7 = new Base; ~~~~~~~~~~~~ -!!! error TS2323: Type 'Base' is not comparable with type 'i7'. +!!! error TS2323: Type 'Base' is not comparable to type 'i7'. var obj71: i7 = null; var obj72: i7 = function () { }; ~~~~~ diff --git a/tests/baselines/reference/literals-negative.errors.txt b/tests/baselines/reference/literals-negative.errors.txt index f2a56614cbc7f..40a00989717c2 100644 --- a/tests/baselines/reference/literals-negative.errors.txt +++ b/tests/baselines/reference/literals-negative.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/literals-negative.ts(5,9): error TS2323: Type 'number' is not comparable with type 'boolean'. +tests/cases/compiler/literals-negative.ts(5,9): error TS2323: Type 'number' is not comparable to type 'boolean'. ==== tests/cases/compiler/literals-negative.ts (1 errors) ==== @@ -8,7 +8,7 @@ tests/cases/compiler/literals-negative.ts(5,9): error TS2323: Type 'number' is n var s = (null); var b = (n); ~~~~~~~~~~~~ -!!! error TS2323: Type 'number' is not comparable with type 'boolean'. +!!! error TS2323: Type 'number' is not comparable to type 'boolean'. function isVoid() : void { } diff --git a/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt b/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt index 333a940cc376d..35b11dc5b6156 100644 --- a/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt +++ b/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/noImplicitAnyInCastExpression.ts(16,2): error TS2323: Type '{ c: null; }' is not comparable with type 'IFoo'. +tests/cases/compiler/noImplicitAnyInCastExpression.ts(16,2): error TS2323: Type '{ c: null; }' is not comparable to type 'IFoo'. Property 'a' is missing in type '{ c: null; }'. @@ -20,5 +20,5 @@ tests/cases/compiler/noImplicitAnyInCastExpression.ts(16,2): error TS2323: Type // Neither types is assignable to each other ({ c: null }); ~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type '{ c: null; }' is not comparable with type 'IFoo'. +!!! error TS2323: Type '{ c: null; }' is not comparable to type 'IFoo'. !!! error TS2323: Property 'a' is missing in type '{ c: null; }'. \ No newline at end of file diff --git a/tests/baselines/reference/objectTypesIdentityWithPrivates3.errors.txt b/tests/baselines/reference/objectTypesIdentityWithPrivates3.errors.txt index 6bd4dfd054471..b74518ad062ed 100644 --- a/tests/baselines/reference/objectTypesIdentityWithPrivates3.errors.txt +++ b/tests/baselines/reference/objectTypesIdentityWithPrivates3.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3.ts(25,1): error TS2323: Type 'C3' is not comparable with type 'C4'. +tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3.ts(25,1): error TS2323: Type 'C3' is not comparable to type 'C4'. Property 'y' is missing in type 'C3'. @@ -29,5 +29,5 @@ tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectType var c3: C3; c3; // Should fail (private x originates in the same declaration, but different types) ~~~~~~ -!!! error TS2323: Type 'C3' is not comparable with type 'C4'. +!!! error TS2323: Type 'C3' is not comparable to type 'C4'. !!! error TS2323: Property 'y' is missing in type 'C3'. \ No newline at end of file diff --git a/tests/baselines/reference/switchAssignmentCompat.errors.txt b/tests/baselines/reference/switchAssignmentCompat.errors.txt index cdfcc423f038c..2225c71186365 100644 --- a/tests/baselines/reference/switchAssignmentCompat.errors.txt +++ b/tests/baselines/reference/switchAssignmentCompat.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/switchAssignmentCompat.ts(4,10): error TS2323: Type 'typeof Foo' is not comparable with type 'number'. +tests/cases/compiler/switchAssignmentCompat.ts(4,10): error TS2323: 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 TS2323: Type 'typeof switch (0) { case Foo: break; // Error expected ~~~ -!!! error TS2323: Type 'typeof Foo' is not comparable with type 'number'. +!!! error TS2323: Type 'typeof Foo' is not comparable to type 'number'. } \ No newline at end of file diff --git a/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt b/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt index 417d4394bd849..30e50c2a12d85 100644 --- a/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt +++ b/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts(19,10): error TS2323: Type 'number & boolean' is not comparable with type 'string & number'. - Type 'number & boolean' is not comparable with type 'string'. - Type 'boolean' is not comparable with type 'string'. -tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts(23,10): error TS2323: Type 'boolean' is not comparable with type 'string & number'. - Type 'boolean' is not comparable with type 'string'. +tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts(19,10): error TS2323: Type 'number & boolean' is not comparable to type 'string & number'. + Type 'number & boolean' is not comparable to type 'string'. + Type 'boolean' is not comparable to type 'string'. +tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts(23,10): error TS2323: Type 'boolean' is not comparable to type 'string & number'. + Type 'boolean' is not comparable to type 'string'. ==== tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts (2 errors) ==== @@ -26,15 +26,15 @@ tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithInterse // Overlap in constituents case numAndBool: ~~~~~~~~~~ -!!! error TS2323: Type 'number & boolean' is not comparable with type 'string & number'. -!!! error TS2323: Type 'number & boolean' is not comparable with type 'string'. -!!! error TS2323: Type 'boolean' is not comparable with type 'string'. +!!! error TS2323: Type 'number & boolean' is not comparable to type 'string & number'. +!!! error TS2323: Type 'number & boolean' is not comparable to type 'string'. +!!! error TS2323: Type 'boolean' is not comparable to type 'string'. break; // No relation case bool: ~~~~ -!!! error TS2323: Type 'boolean' is not comparable with type 'string & number'. -!!! error TS2323: Type 'boolean' is not comparable with type 'string'. +!!! error TS2323: Type 'boolean' is not comparable to type 'string & number'. +!!! error TS2323: Type 'boolean' is not comparable to type 'string'. break; } \ No newline at end of file diff --git a/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt b/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt index 3fbcb4c4658b7..fe5d9175fc7c4 100644 --- a/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt +++ b/tests/baselines/reference/switchCaseWithUnionTypes01.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithUnionTypes01.ts(23,10): error TS2323: Type 'boolean' is not comparable with type 'string | number'. - Type 'boolean' is not comparable with type 'number'. +tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithUnionTypes01.ts(23,10): error TS2323: Type 'boolean' is not comparable to type 'string | number'. + Type 'boolean' is not comparable to type 'number'. ==== tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithUnionTypes01.ts (1 errors) ==== @@ -27,7 +27,7 @@ tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithUnionTy // No relation case bool: ~~~~ -!!! error TS2323: Type 'boolean' is not comparable with type 'string | number'. -!!! error TS2323: Type 'boolean' is not comparable with type 'number'. +!!! error TS2323: Type 'boolean' is not comparable to type 'string | number'. +!!! error TS2323: Type 'boolean' is not comparable to type 'number'. break; } \ No newline at end of file diff --git a/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt b/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt index c3009179995ac..81e5137546a57 100644 --- a/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt +++ b/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(4,10): error TS2323: Type 'typeof Foo' is not comparable with type 'number'. -tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(5,10): error TS2323: Type 'string' is not comparable with type 'number'. -tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2323: Type 'boolean' is not comparable with type 'number'. +tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(4,10): error TS2323: Type 'typeof Foo' is not comparable to type 'number'. +tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(5,10): error TS2323: Type 'string' is not comparable to type 'number'. +tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2323: Type 'boolean' is not comparable to type 'number'. ==== tests/cases/compiler/switchCasesExpressionTypeMismatch.ts (3 errors) ==== @@ -9,14 +9,14 @@ tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2323: T switch (0) { case Foo: break; // Error ~~~ -!!! error TS2323: Type 'typeof Foo' is not comparable with type 'number'. +!!! error TS2323: Type 'typeof Foo' is not comparable to type 'number'. case "sss": break; // Error ~~~~~ -!!! error TS2323: Type 'string' is not comparable with type 'number'. +!!! error TS2323: Type 'string' is not comparable to type 'number'. case 123: break; // No Error case true: break; // Error ~~~~ -!!! error TS2323: Type 'boolean' is not comparable with type 'number'. +!!! error TS2323: Type 'boolean' is not comparable to type 'number'. } var s: any = 0; diff --git a/tests/baselines/reference/switchStatements.errors.txt b/tests/baselines/reference/switchStatements.errors.txt index eddc9eaa83341..3ed58a6a65b0c 100644 --- a/tests/baselines/reference/switchStatements.errors.txt +++ b/tests/baselines/reference/switchStatements.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/statements/switchStatements/switchStatements.ts(35,20): error TS2323: Type '{ id: number; name: string; }' is not comparable with type 'C'. +tests/cases/conformance/statements/switchStatements/switchStatements.ts(35,20): error TS2323: Type '{ id: number; name: string; }' is not comparable to type 'C'. Object literal may only specify known properties, and 'name' does not exist in type 'C'. @@ -39,7 +39,7 @@ tests/cases/conformance/statements/switchStatements/switchStatements.ts(35,20): case new D(): case { id: 12, name: '' }: ~~~~~~~~ -!!! error TS2323: Type '{ id: number; name: string; }' is not comparable with type 'C'. +!!! error TS2323: Type '{ id: number; name: string; }' is not comparable to type 'C'. !!! error TS2323: Object literal may only specify known properties, and 'name' does not exist in type 'C'. case new C(): } diff --git a/tests/baselines/reference/typeAssertions.errors.txt b/tests/baselines/reference/typeAssertions.errors.txt index 1e9e45171f60f..da2dcbd8877fb 100644 --- a/tests/baselines/reference/typeAssertions.errors.txt +++ b/tests/baselines/reference/typeAssertions.errors.txt @@ -1,11 +1,11 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(5,5): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(31,12): error TS2323: Type 'SomeOther' is not comparable with type 'SomeBase'. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(31,12): error TS2323: Type 'SomeOther' is not comparable to type 'SomeBase'. Property 'p' is missing in type 'SomeOther'. -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(35,15): error TS2323: Type 'SomeOther' is not comparable with type 'SomeDerived'. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(35,15): error TS2323: Type 'SomeOther' is not comparable to type 'SomeDerived'. Property 'x' is missing in type 'SomeOther'. -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(37,13): error TS2323: Type 'SomeDerived' is not comparable with type 'SomeOther'. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(37,13): error TS2323: Type 'SomeDerived' is not comparable to type 'SomeOther'. Property 'q' is missing in type 'SomeDerived'. -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(38,13): error TS2323: Type 'SomeBase' is not comparable with type 'SomeOther'. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(38,13): error TS2323: Type 'SomeBase' is not comparable to type 'SomeOther'. Property 'q' is missing in type 'SomeBase'. @@ -44,23 +44,23 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(38,13): err someBase = someBase; someBase = someOther; // Error ~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type 'SomeOther' is not comparable with type 'SomeBase'. +!!! error TS2323: Type 'SomeOther' is not comparable to type 'SomeBase'. !!! error TS2323: Property 'p' is missing in type 'SomeOther'. someDerived = someDerived; someDerived = someBase; someDerived = someOther; // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type 'SomeOther' is not comparable with type 'SomeDerived'. +!!! error TS2323: Type 'SomeOther' is not comparable to type 'SomeDerived'. !!! error TS2323: Property 'x' is missing in type 'SomeOther'. someOther = someDerived; // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type 'SomeDerived' is not comparable with type 'SomeOther'. +!!! error TS2323: Type 'SomeDerived' is not comparable to type 'SomeOther'. !!! error TS2323: Property 'q' is missing in type 'SomeDerived'. someOther = someBase; // Error ~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type 'SomeBase' is not comparable with type 'SomeOther'. +!!! error TS2323: Type 'SomeBase' is not comparable to type 'SomeOther'. !!! error TS2323: Property 'q' is missing in type 'SomeBase'. someOther = someOther; diff --git a/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt b/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt index 1b0cd98533d3d..c663c6a41e49e 100644 --- a/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt +++ b/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts(17,9): error TS2323: Type 'I2' is not comparable with type 'I1 & I3'. - Type 'I2' is not comparable with type 'I3'. +tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts(17,9): error TS2323: Type 'I2' is not comparable to type 'I1 & I3'. + Type 'I2' is not comparable to type 'I3'. Property 'p3' is missing in type 'I2'. -tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts(18,9): error TS2323: Type 'I2' is not comparable with type 'I3'. +tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts(18,9): error TS2323: Type 'I2' is not comparable to type 'I3'. ==== tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts (2 errors) ==== @@ -23,12 +23,12 @@ tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithInt var a = z; ~~~~~~~~~~ -!!! error TS2323: Type 'I2' is not comparable with type 'I1 & I3'. -!!! error TS2323: Type 'I2' is not comparable with type 'I3'. +!!! error TS2323: Type 'I2' is not comparable to type 'I1 & I3'. +!!! error TS2323: Type 'I2' is not comparable to type 'I3'. !!! error TS2323: Property 'p3' is missing in type 'I2'. var b = z; ~~~~~ -!!! error TS2323: Type 'I2' is not comparable with type 'I3'. +!!! error TS2323: Type 'I2' is not comparable to type 'I3'. var c = z; var d = y; \ No newline at end of file diff --git a/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt b/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt index 21d1bccdd5d95..a25b6bbb83204 100644 --- a/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt +++ b/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithUnionTypes01.ts(14,9): error TS2323: Type 'I1' is not comparable with type 'number'. +tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithUnionTypes01.ts(14,9): error TS2323: Type 'I1' is not comparable to type 'number'. ==== tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithUnionTypes01.ts (1 errors) ==== @@ -17,7 +17,7 @@ tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithUni var a = z; var b = z; ~~~~~~~~~ -!!! error TS2323: Type 'I1' is not comparable with type 'number'. +!!! error TS2323: Type 'I1' is not comparable to type 'number'. var c = z; var d = y; \ No newline at end of file From a37b731193a543946272ad58257db8a305fce7e7 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 5 Nov 2015 15:44:51 -0800 Subject: [PATCH 20/22] Changed type assertion error message. --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticMessages.json | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1d859cee660f7..de11802cc79c7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9418,7 +9418,7 @@ namespace ts { let widenedType = getWidenedType(exprType); if (!isTypeComparableTo(targetType, widenedType)) { - checkTypeComparableTo(exprType, targetType, node); + checkTypeComparableTo(exprType, targetType, node, Diagnostics.Type_0_cannot_be_converted_to_type_1); } } return targetType; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index c295a8281757a..b5471520d259e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1000,6 +1000,10 @@ "category": "Error", "code": 2351 }, + "Type '{0}' cannot be converted to type '{1}'.": { + "category": "Error", + "code": 2352 + }, "Object literal may only specify known properties, and '{0}' does not exist in type '{1}'.": { "category": "Error", "code": 2353 From e0385a42442d7aa29c27ab66d4d55c1e77f6314a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 5 Nov 2015 15:45:12 -0800 Subject: [PATCH 21/22] Accepted baselines. --- .../baselines/reference/arrayCast.errors.txt | 8 +++---- .../reference/asOperator2.errors.txt | 4 ++-- .../asOperatorContextualType.errors.txt | 6 ++--- .../reference/asOperatorNames.errors.txt | 4 ++-- .../reference/castingTuple.errors.txt | 18 +++++++------- .../reference/contextualTyping39.errors.txt | 6 ++--- .../reference/contextualTyping41.errors.txt | 6 ++--- ...efaultArgsInFunctionExpressions.errors.txt | 8 +++---- tests/baselines/reference/fuzzy.errors.txt | 6 ++--- .../genericTypeAssertions1.errors.txt | 6 ++--- .../genericTypeAssertions2.errors.txt | 6 ++--- .../genericTypeAssertions4.errors.txt | 8 +++---- .../genericTypeAssertions5.errors.txt | 8 +++---- .../genericTypeAssertions6.errors.txt | 14 +++++------ .../reference/intTypeCheck.errors.txt | 4 ++-- .../reference/literals-negative.errors.txt | 4 ++-- .../noImplicitAnyInCastExpression.errors.txt | 6 ++--- ...bjectTypesIdentityWithPrivates3.errors.txt | 6 ++--- .../reference/typeAssertions.errors.txt | 24 +++++++++---------- ...sertionsWithIntersectionTypes01.errors.txt | 12 +++++----- .../typeAssertionsWithUnionTypes01.errors.txt | 4 ++-- 21 files changed, 84 insertions(+), 84 deletions(-) diff --git a/tests/baselines/reference/arrayCast.errors.txt b/tests/baselines/reference/arrayCast.errors.txt index bb895475a18e9..61463e5557b4c 100644 --- a/tests/baselines/reference/arrayCast.errors.txt +++ b/tests/baselines/reference/arrayCast.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/arrayCast.ts(3,23): error TS2323: Type '{ foo: string; }[]' is not comparable to type '{ id: number; }[]'. +tests/cases/compiler/arrayCast.ts(3,23): error TS2352: Type '{ foo: string; }[]' cannot be converted to type '{ id: number; }[]'. Type '{ foo: string; }' is not comparable to type '{ id: number; }'. Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'. @@ -8,9 +8,9 @@ tests/cases/compiler/arrayCast.ts(3,23): error TS2323: Type '{ foo: string; }[]' // has type { foo: string }[], which is not assignable to { id: number }[]. <{ id: number; }[]>[{ foo: "s" }]; ~~~~~~~~ -!!! error TS2323: Type '{ foo: string; }[]' is not comparable to type '{ id: number; }[]'. -!!! error TS2323: Type '{ foo: string; }' is not comparable to type '{ id: number; }'. -!!! error TS2323: Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'. +!!! error TS2352: Type '{ foo: string; }[]' cannot be converted to type '{ id: number; }[]'. +!!! error TS2352: Type '{ foo: string; }' is not comparable to type '{ id: number; }'. +!!! error TS2352: Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'. // Should succeed, as the {} element causes the type of the array to be {}[] <{ id: number; }[]>[{ foo: "s" }, {}]; \ No newline at end of file diff --git a/tests/baselines/reference/asOperator2.errors.txt b/tests/baselines/reference/asOperator2.errors.txt index 0930191aae190..92603c25cb021 100644 --- a/tests/baselines/reference/asOperator2.errors.txt +++ b/tests/baselines/reference/asOperator2.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/expressions/asOperator/asOperator2.ts(1,9): error TS2323: Type 'number' is not comparable to type 'string'. +tests/cases/conformance/expressions/asOperator/asOperator2.ts(1,9): error TS2352: Type 'number' cannot be converted to type 'string'. ==== tests/cases/conformance/expressions/asOperator/asOperator2.ts (1 errors) ==== var x = 23 as string; ~~~~~~~~~~~~ -!!! error TS2323: Type 'number' is not comparable to type 'string'. +!!! error TS2352: Type 'number' cannot be converted to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/asOperatorContextualType.errors.txt b/tests/baselines/reference/asOperatorContextualType.errors.txt index 1a6cf43827c78..9431d6123e279 100644 --- a/tests/baselines/reference/asOperatorContextualType.errors.txt +++ b/tests/baselines/reference/asOperatorContextualType.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/expressions/asOperator/asOperatorContextualType.ts(2,9): error TS2323: Type '(v: number) => number' is not comparable to type '(x: number) => string'. +tests/cases/conformance/expressions/asOperator/asOperatorContextualType.ts(2,9): error TS2352: Type '(v: number) => number' cannot be converted to type '(x: number) => string'. Type 'number' is not comparable to type 'string'. @@ -6,5 +6,5 @@ tests/cases/conformance/expressions/asOperator/asOperatorContextualType.ts(2,9): // should error var x = (v => v) as (x: number) => string; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type '(v: number) => number' is not comparable to type '(x: number) => string'. -!!! error TS2323: Type 'number' is not comparable to type 'string'. \ No newline at end of file +!!! error TS2352: Type '(v: number) => number' cannot be converted to type '(x: number) => string'. +!!! error TS2352: Type 'number' is not comparable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/asOperatorNames.errors.txt b/tests/baselines/reference/asOperatorNames.errors.txt index f4ef8a64e2ba6..4f957791a24d3 100644 --- a/tests/baselines/reference/asOperatorNames.errors.txt +++ b/tests/baselines/reference/asOperatorNames.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/expressions/asOperator/asOperatorNames.ts(2,9): error TS2323: Type 'number' is not comparable to type 'string'. +tests/cases/conformance/expressions/asOperator/asOperatorNames.ts(2,9): error TS2352: Type 'number' cannot be converted to type 'string'. ==== tests/cases/conformance/expressions/asOperator/asOperatorNames.ts (1 errors) ==== var a = 20; var b = a as string; ~~~~~~~~~~~ -!!! error TS2323: Type 'number' is not comparable to type 'string'. +!!! error TS2352: Type 'number' cannot be converted to type 'string'. var as = "hello"; var as1 = as as string; \ No newline at end of file diff --git a/tests/baselines/reference/castingTuple.errors.txt b/tests/baselines/reference/castingTuple.errors.txt index 4430c932bfceb..6d5549c6bf2ae 100644 --- a/tests/baselines/reference/castingTuple.errors.txt +++ b/tests/baselines/reference/castingTuple.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/types/tuple/castingTuple.ts(28,10): error TS2323: Type '[number, string]' is not comparable to type '[number, number]'. +tests/cases/conformance/types/tuple/castingTuple.ts(28,10): error TS2352: Type '[number, string]' cannot be converted to type '[number, number]'. Types of property '1' are incompatible. Type 'string' is not comparable to type 'number'. -tests/cases/conformance/types/tuple/castingTuple.ts(29,10): error TS2323: Type '[C, D]' is not comparable to type '[A, I]'. +tests/cases/conformance/types/tuple/castingTuple.ts(29,10): error TS2352: Type '[C, D]' cannot be converted to type '[A, I]'. Types of property '0' are incompatible. Type 'C' is not comparable to type 'A'. Property 'a' is missing in type 'C'. @@ -39,15 +39,15 @@ tests/cases/conformance/types/tuple/castingTuple.ts(31,1): error TS2304: Cannot // error var t3 = <[number, number]>numStrTuple; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type '[number, string]' is not comparable to type '[number, number]'. -!!! error TS2323: Types of property '1' are incompatible. -!!! error TS2323: Type 'string' is not comparable to type 'number'. +!!! error TS2352: Type '[number, string]' cannot be converted to type '[number, number]'. +!!! error TS2352: Types of property '1' are incompatible. +!!! error TS2352: Type 'string' is not comparable to type 'number'. var t9 = <[A, I]>classCDTuple; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type '[C, D]' is not comparable to type '[A, I]'. -!!! error TS2323: Types of property '0' are incompatible. -!!! error TS2323: Type 'C' is not comparable to type 'A'. -!!! error TS2323: Property 'a' is missing in type 'C'. +!!! error TS2352: Type '[C, D]' cannot be converted to type '[A, I]'. +!!! error TS2352: Types of property '0' are incompatible. +!!! error TS2352: Type 'C' is not comparable to type 'A'. +!!! error TS2352: Property 'a' is missing in type 'C'. var array1 = numStrTuple; ~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'. diff --git a/tests/baselines/reference/contextualTyping39.errors.txt b/tests/baselines/reference/contextualTyping39.errors.txt index bb797c6a43ece..9081480f4badf 100644 --- a/tests/baselines/reference/contextualTyping39.errors.txt +++ b/tests/baselines/reference/contextualTyping39.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/contextualTyping39.ts(1,11): error TS2323: Type '() => string' is not comparable to type '() => number'. +tests/cases/compiler/contextualTyping39.ts(1,11): error TS2352: Type '() => string' cannot be converted to type '() => number'. Type 'string' is not comparable to type 'number'. ==== tests/cases/compiler/contextualTyping39.ts (1 errors) ==== var foo = <{ (): number; }> function() { return "err"; }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type '() => string' is not comparable to type '() => number'. -!!! error TS2323: Type 'string' is not comparable to type 'number'. \ No newline at end of file +!!! error TS2352: Type '() => string' cannot be converted to type '() => number'. +!!! error TS2352: Type 'string' is not comparable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping41.errors.txt b/tests/baselines/reference/contextualTyping41.errors.txt index e3261e1184350..418d435e7fefc 100644 --- a/tests/baselines/reference/contextualTyping41.errors.txt +++ b/tests/baselines/reference/contextualTyping41.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/contextualTyping41.ts(1,11): error TS2323: Type '() => string' is not comparable to type '{ (): number; (i: number): number; }'. +tests/cases/compiler/contextualTyping41.ts(1,11): error TS2352: Type '() => string' cannot be converted to type '{ (): number; (i: number): number; }'. Type 'string' is not comparable to type 'number'. ==== tests/cases/compiler/contextualTyping41.ts (1 errors) ==== var foo = <{():number; (i:number):number; }> (function(){return "err";}); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type '() => string' is not comparable to type '{ (): number; (i: number): number; }'. -!!! error TS2323: Type 'string' is not comparable to type 'number'. \ No newline at end of file +!!! error TS2352: Type '() => string' cannot be converted to type '{ (): number; (i: number): number; }'. +!!! error TS2352: Type 'string' is not comparable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/defaultArgsInFunctionExpressions.errors.txt b/tests/baselines/reference/defaultArgsInFunctionExpressions.errors.txt index 7b7166843c39d..60a9e92bc950e 100644 --- a/tests/baselines/reference/defaultArgsInFunctionExpressions.errors.txt +++ b/tests/baselines/reference/defaultArgsInFunctionExpressions.errors.txt @@ -2,9 +2,9 @@ tests/cases/compiler/defaultArgsInFunctionExpressions.ts(4,19): error TS2345: Ar tests/cases/compiler/defaultArgsInFunctionExpressions.ts(5,1): error TS2322: Type 'number' is not assignable to type 'string'. tests/cases/compiler/defaultArgsInFunctionExpressions.ts(8,20): error TS2322: Type 'number' is not assignable to type 'string'. tests/cases/compiler/defaultArgsInFunctionExpressions.ts(11,1): error TS2322: Type 'string' is not assignable to type 'number'. -tests/cases/compiler/defaultArgsInFunctionExpressions.ts(14,51): error TS2323: Type 'string' is not comparable to type 'number'. +tests/cases/compiler/defaultArgsInFunctionExpressions.ts(14,51): error TS2352: Type 'string' cannot be converted to type 'number'. tests/cases/compiler/defaultArgsInFunctionExpressions.ts(17,41): error TS2322: Type 'string' is not assignable to type 'number'. -tests/cases/compiler/defaultArgsInFunctionExpressions.ts(20,62): error TS2323: Type 'string' is not comparable to type 'number'. +tests/cases/compiler/defaultArgsInFunctionExpressions.ts(20,62): error TS2352: Type 'string' cannot be converted to type 'number'. tests/cases/compiler/defaultArgsInFunctionExpressions.ts(28,15): error TS2304: Cannot find name 'T'. @@ -32,7 +32,7 @@ tests/cases/compiler/defaultArgsInFunctionExpressions.ts(28,15): error TS2304: C // Contextually type the default arg with the type annotation var f3 = function (a: (s: string) => any = (s) => s) { }; ~~~~~~~~~ -!!! error TS2323: Type 'string' is not comparable to type 'number'. +!!! error TS2352: Type 'string' cannot be converted to type 'number'. // Type check using the function's contextual type var f4: (a: number) => void = function (a = "") { }; @@ -42,7 +42,7 @@ tests/cases/compiler/defaultArgsInFunctionExpressions.ts(28,15): error TS2304: C // Contextually type the default arg using the function's contextual type var f5: (a: (s: string) => any) => void = function (a = s => s) { }; ~~~~~~~~~ -!!! error TS2323: Type 'string' is not comparable to type 'number'. +!!! error TS2352: Type 'string' cannot be converted to type 'number'. // Instantiated module module T { } diff --git a/tests/baselines/reference/fuzzy.errors.txt b/tests/baselines/reference/fuzzy.errors.txt index f39b520759c94..19f0ad56a5e35 100644 --- a/tests/baselines/reference/fuzzy.errors.txt +++ b/tests/baselines/reference/fuzzy.errors.txt @@ -4,7 +4,7 @@ tests/cases/compiler/fuzzy.ts(21,20): error TS2322: Type '{ anything: number; on Types of property 'oneI' are incompatible. Type 'this' is not assignable to type 'I'. Type 'C' is not assignable to type 'I'. -tests/cases/compiler/fuzzy.ts(25,20): error TS2323: Type '{ oneI: this; }' is not comparable to type 'R'. +tests/cases/compiler/fuzzy.ts(25,20): error TS2352: Type '{ oneI: this; }' cannot be converted to type 'R'. Property 'anything' is missing in type '{ oneI: this; }'. @@ -43,8 +43,8 @@ tests/cases/compiler/fuzzy.ts(25,20): error TS2323: Type '{ oneI: this; }' is no worksToo():R { return ({ oneI: this }); ~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type '{ oneI: this; }' is not comparable to type 'R'. -!!! error TS2323: Property 'anything' is missing in type '{ oneI: this; }'. +!!! error TS2352: Type '{ oneI: this; }' cannot be converted to type 'R'. +!!! error TS2352: Property 'anything' is missing in type '{ oneI: this; }'. } } } diff --git a/tests/baselines/reference/genericTypeAssertions1.errors.txt b/tests/baselines/reference/genericTypeAssertions1.errors.txt index 3e0157f98637b..aa5f14f5da858 100644 --- a/tests/baselines/reference/genericTypeAssertions1.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions1.errors.txt @@ -2,7 +2,7 @@ tests/cases/compiler/genericTypeAssertions1.ts(3,5): error TS2322: Type 'A>' is not assignable to type 'A'. Type 'A' is not assignable to type 'number'. -tests/cases/compiler/genericTypeAssertions1.ts(4,21): error TS2323: Type 'A' is not comparable to type 'A>'. +tests/cases/compiler/genericTypeAssertions1.ts(4,21): error TS2352: Type 'A' cannot be converted to type 'A>'. Type 'number' is not comparable to type 'A'. @@ -18,5 +18,5 @@ tests/cases/compiler/genericTypeAssertions1.ts(4,21): error TS2323: Type 'A>' is not assignable to type 'A'. !!! error TS2322: Type 'A' is not assignable to type 'number'. ~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type 'A' is not comparable to type 'A>'. -!!! error TS2323: Type 'number' is not comparable to type 'A'. \ No newline at end of file +!!! error TS2352: Type 'A' cannot be converted to type 'A>'. +!!! error TS2352: Type 'number' is not comparable to type 'A'. \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAssertions2.errors.txt b/tests/baselines/reference/genericTypeAssertions2.errors.txt index 908255b1d3399..71848c5be028a 100644 --- a/tests/baselines/reference/genericTypeAssertions2.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions2.errors.txt @@ -5,7 +5,7 @@ tests/cases/compiler/genericTypeAssertions2.ts(10,5): error TS2322: Type 'B' is not assignable to type 'B'. Property 'bar' is missing in type 'A'. -tests/cases/compiler/genericTypeAssertions2.ts(13,21): error TS2323: Type 'undefined[]' is not comparable to type 'A'. +tests/cases/compiler/genericTypeAssertions2.ts(13,21): error TS2352: Type 'undefined[]' cannot be converted to type 'A'. Property 'foo' is missing in type 'undefined[]'. @@ -33,5 +33,5 @@ tests/cases/compiler/genericTypeAssertions2.ts(13,21): error TS2323: Type 'undef var r4: A = >new A(); var r5: A = >[]; // error ~~~~~~~~~~~~~ -!!! error TS2323: Type 'undefined[]' is not comparable to type 'A'. -!!! error TS2323: Property 'foo' is missing in type 'undefined[]'. \ No newline at end of file +!!! error TS2352: Type 'undefined[]' cannot be converted to type 'A'. +!!! error TS2352: Property 'foo' is missing in type 'undefined[]'. \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAssertions4.errors.txt b/tests/baselines/reference/genericTypeAssertions4.errors.txt index cffacb6b0dc4c..401834930f30f 100644 --- a/tests/baselines/reference/genericTypeAssertions4.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions4.errors.txt @@ -1,8 +1,8 @@ tests/cases/compiler/genericTypeAssertions4.ts(19,5): error TS2322: Type 'A' is not assignable to type 'T'. tests/cases/compiler/genericTypeAssertions4.ts(20,5): error TS2322: Type 'B' is not assignable to type 'T'. tests/cases/compiler/genericTypeAssertions4.ts(21,5): error TS2322: Type 'C' is not assignable to type 'T'. -tests/cases/compiler/genericTypeAssertions4.ts(23,9): error TS2323: Type 'B' is not comparable to type 'T'. -tests/cases/compiler/genericTypeAssertions4.ts(24,9): error TS2323: Type 'C' is not comparable to type 'T'. +tests/cases/compiler/genericTypeAssertions4.ts(23,9): error TS2352: Type 'B' cannot be converted to type 'T'. +tests/cases/compiler/genericTypeAssertions4.ts(24,9): error TS2352: Type 'C' cannot be converted to type 'T'. ==== tests/cases/compiler/genericTypeAssertions4.ts (5 errors) ==== @@ -36,8 +36,8 @@ tests/cases/compiler/genericTypeAssertions4.ts(24,9): error TS2323: Type 'C' is y = a; y = b; // error: cannot convert B to T ~~~~ -!!! error TS2323: Type 'B' is not comparable to type 'T'. +!!! error TS2352: Type 'B' cannot be converted to type 'T'. y = c; // error: cannot convert C to T ~~~~ -!!! error TS2323: Type 'C' is not comparable to type 'T'. +!!! error TS2352: Type 'C' cannot be converted to type 'T'. } \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAssertions5.errors.txt b/tests/baselines/reference/genericTypeAssertions5.errors.txt index f7f2be41825f6..45f7607336385 100644 --- a/tests/baselines/reference/genericTypeAssertions5.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions5.errors.txt @@ -1,8 +1,8 @@ tests/cases/compiler/genericTypeAssertions5.ts(19,5): error TS2322: Type 'A' is not assignable to type 'T'. tests/cases/compiler/genericTypeAssertions5.ts(20,5): error TS2322: Type 'B' is not assignable to type 'T'. tests/cases/compiler/genericTypeAssertions5.ts(21,5): error TS2322: Type 'C' is not assignable to type 'T'. -tests/cases/compiler/genericTypeAssertions5.ts(23,9): error TS2323: Type 'B' is not comparable to type 'T'. -tests/cases/compiler/genericTypeAssertions5.ts(24,9): error TS2323: Type 'C' is not comparable to type 'T'. +tests/cases/compiler/genericTypeAssertions5.ts(23,9): error TS2352: Type 'B' cannot be converted to type 'T'. +tests/cases/compiler/genericTypeAssertions5.ts(24,9): error TS2352: Type 'C' cannot be converted to type 'T'. ==== tests/cases/compiler/genericTypeAssertions5.ts (5 errors) ==== @@ -36,8 +36,8 @@ tests/cases/compiler/genericTypeAssertions5.ts(24,9): error TS2323: Type 'C' is y = a; y = b; // error: cannot convert B to T ~~~~ -!!! error TS2323: Type 'B' is not comparable to type 'T'. +!!! error TS2352: Type 'B' cannot be converted to type 'T'. y = c; // error: cannot convert C to T ~~~~ -!!! error TS2323: Type 'C' is not comparable to type 'T'. +!!! error TS2352: Type 'C' cannot be converted to type 'T'. } \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAssertions6.errors.txt b/tests/baselines/reference/genericTypeAssertions6.errors.txt index 4ea7d3602ebd8..1bda683b88a23 100644 --- a/tests/baselines/reference/genericTypeAssertions6.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions6.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/genericTypeAssertions6.ts(8,13): error TS2323: Type 'U' is not comparable to type 'T'. -tests/cases/compiler/genericTypeAssertions6.ts(9,13): error TS2323: Type 'T' is not comparable to type 'U'. -tests/cases/compiler/genericTypeAssertions6.ts(19,17): error TS2323: Type 'U' is not comparable to type 'T'. +tests/cases/compiler/genericTypeAssertions6.ts(8,13): error TS2352: Type 'U' cannot be converted to type 'T'. +tests/cases/compiler/genericTypeAssertions6.ts(9,13): error TS2352: Type 'T' cannot be converted to type 'U'. +tests/cases/compiler/genericTypeAssertions6.ts(19,17): error TS2352: Type 'U' cannot be converted to type 'T'. Type 'Date' is not comparable to type 'T'. @@ -14,10 +14,10 @@ tests/cases/compiler/genericTypeAssertions6.ts(19,17): error TS2323: Type 'U' is f(x: T, y: U) { x = y; ~~~~ -!!! error TS2323: Type 'U' is not comparable to type 'T'. +!!! error TS2352: Type 'U' cannot be converted to type 'T'. y = x; ~~~~ -!!! error TS2323: Type 'T' is not comparable to type 'U'. +!!! error TS2352: Type 'T' cannot be converted to type 'U'. } } @@ -29,8 +29,8 @@ tests/cases/compiler/genericTypeAssertions6.ts(19,17): error TS2323: Type 'U' is var d = new Date(); var e = new Date(); ~~~~~~~~~~~~~~~~ -!!! error TS2323: Type 'U' is not comparable to type 'T'. -!!! error TS2323: Type 'Date' is not comparable to type 'T'. +!!! error TS2352: Type 'U' cannot be converted to type 'T'. +!!! error TS2352: Type 'Date' is not comparable to type 'T'. } } diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index 175c5ea7979b7..29388521104ee 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -61,7 +61,7 @@ tests/cases/compiler/intTypeCheck.ts(176,22): error TS2304: Cannot find name 'i6 tests/cases/compiler/intTypeCheck.ts(177,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(182,5): error TS2322: Type '{}' is not assignable to type 'i7'. tests/cases/compiler/intTypeCheck.ts(183,5): error TS2322: Type 'Object' is not assignable to type 'i7'. -tests/cases/compiler/intTypeCheck.ts(185,17): error TS2323: Type 'Base' is not comparable to type 'i7'. +tests/cases/compiler/intTypeCheck.ts(185,17): error TS2352: Type 'Base' cannot be converted to type 'i7'. tests/cases/compiler/intTypeCheck.ts(187,5): error TS2322: Type '() => void' is not assignable to type 'i7'. tests/cases/compiler/intTypeCheck.ts(190,5): error TS2322: Type 'boolean' is not assignable to type 'i7'. tests/cases/compiler/intTypeCheck.ts(190,21): error TS1109: Expression expected. @@ -377,7 +377,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj69: i7 = new obj66; var obj70: i7 = new Base; ~~~~~~~~~~~~ -!!! error TS2323: Type 'Base' is not comparable to type 'i7'. +!!! error TS2352: Type 'Base' cannot be converted to type 'i7'. var obj71: i7 = null; var obj72: i7 = function () { }; ~~~~~ diff --git a/tests/baselines/reference/literals-negative.errors.txt b/tests/baselines/reference/literals-negative.errors.txt index 40a00989717c2..2024066d9f264 100644 --- a/tests/baselines/reference/literals-negative.errors.txt +++ b/tests/baselines/reference/literals-negative.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/literals-negative.ts(5,9): error TS2323: Type 'number' is not comparable to type 'boolean'. +tests/cases/compiler/literals-negative.ts(5,9): error TS2352: Type 'number' cannot be converted to type 'boolean'. ==== tests/cases/compiler/literals-negative.ts (1 errors) ==== @@ -8,7 +8,7 @@ tests/cases/compiler/literals-negative.ts(5,9): error TS2323: Type 'number' is n var s = (null); var b = (n); ~~~~~~~~~~~~ -!!! error TS2323: Type 'number' is not comparable to type 'boolean'. +!!! error TS2352: Type 'number' cannot be converted to type 'boolean'. function isVoid() : void { } diff --git a/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt b/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt index 35b11dc5b6156..8243a9c68ce8d 100644 --- a/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt +++ b/tests/baselines/reference/noImplicitAnyInCastExpression.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/noImplicitAnyInCastExpression.ts(16,2): error TS2323: Type '{ c: null; }' is not comparable to type 'IFoo'. +tests/cases/compiler/noImplicitAnyInCastExpression.ts(16,2): error TS2352: Type '{ c: null; }' cannot be converted to type 'IFoo'. Property 'a' is missing in type '{ c: null; }'. @@ -20,5 +20,5 @@ tests/cases/compiler/noImplicitAnyInCastExpression.ts(16,2): error TS2323: Type // Neither types is assignable to each other ({ c: null }); ~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type '{ c: null; }' is not comparable to type 'IFoo'. -!!! error TS2323: Property 'a' is missing in type '{ c: null; }'. \ No newline at end of file +!!! error TS2352: Type '{ c: null; }' cannot be converted to type 'IFoo'. +!!! error TS2352: Property 'a' is missing in type '{ c: null; }'. \ No newline at end of file diff --git a/tests/baselines/reference/objectTypesIdentityWithPrivates3.errors.txt b/tests/baselines/reference/objectTypesIdentityWithPrivates3.errors.txt index b74518ad062ed..2342065605be9 100644 --- a/tests/baselines/reference/objectTypesIdentityWithPrivates3.errors.txt +++ b/tests/baselines/reference/objectTypesIdentityWithPrivates3.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3.ts(25,1): error TS2323: Type 'C3' is not comparable to type 'C4'. +tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3.ts(25,1): error TS2352: Type 'C3' cannot be converted to type 'C4'. Property 'y' is missing in type 'C3'. @@ -29,5 +29,5 @@ tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectType var c3: C3; c3; // Should fail (private x originates in the same declaration, but different types) ~~~~~~ -!!! error TS2323: Type 'C3' is not comparable to type 'C4'. -!!! error TS2323: Property 'y' is missing in type 'C3'. \ No newline at end of file +!!! error TS2352: Type 'C3' cannot be converted to type 'C4'. +!!! error TS2352: Property 'y' is missing in type 'C3'. \ No newline at end of file diff --git a/tests/baselines/reference/typeAssertions.errors.txt b/tests/baselines/reference/typeAssertions.errors.txt index da2dcbd8877fb..baabc272bf392 100644 --- a/tests/baselines/reference/typeAssertions.errors.txt +++ b/tests/baselines/reference/typeAssertions.errors.txt @@ -1,11 +1,11 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(5,5): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(31,12): error TS2323: Type 'SomeOther' is not comparable to type 'SomeBase'. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(31,12): error TS2352: Type 'SomeOther' cannot be converted to type 'SomeBase'. Property 'p' is missing in type 'SomeOther'. -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(35,15): error TS2323: Type 'SomeOther' is not comparable to type 'SomeDerived'. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(35,15): error TS2352: Type 'SomeOther' cannot be converted to type 'SomeDerived'. Property 'x' is missing in type 'SomeOther'. -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(37,13): error TS2323: Type 'SomeDerived' is not comparable to type 'SomeOther'. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(37,13): error TS2352: Type 'SomeDerived' cannot be converted to type 'SomeOther'. Property 'q' is missing in type 'SomeDerived'. -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(38,13): error TS2323: Type 'SomeBase' is not comparable to type 'SomeOther'. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(38,13): error TS2352: Type 'SomeBase' cannot be converted to type 'SomeOther'. Property 'q' is missing in type 'SomeBase'. @@ -44,24 +44,24 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(38,13): err someBase = someBase; someBase = someOther; // Error ~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type 'SomeOther' is not comparable to type 'SomeBase'. -!!! error TS2323: Property 'p' is missing in type 'SomeOther'. +!!! error TS2352: Type 'SomeOther' cannot be converted to type 'SomeBase'. +!!! error TS2352: Property 'p' is missing in type 'SomeOther'. someDerived = someDerived; someDerived = someBase; someDerived = someOther; // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type 'SomeOther' is not comparable to type 'SomeDerived'. -!!! error TS2323: Property 'x' is missing in type 'SomeOther'. +!!! error TS2352: Type 'SomeOther' cannot be converted to type 'SomeDerived'. +!!! error TS2352: Property 'x' is missing in type 'SomeOther'. someOther = someDerived; // Error ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type 'SomeDerived' is not comparable to type 'SomeOther'. -!!! error TS2323: Property 'q' is missing in type 'SomeDerived'. +!!! error TS2352: Type 'SomeDerived' cannot be converted to type 'SomeOther'. +!!! error TS2352: Property 'q' is missing in type 'SomeDerived'. someOther = someBase; // Error ~~~~~~~~~~~~~~~~~~~ -!!! error TS2323: Type 'SomeBase' is not comparable to type 'SomeOther'. -!!! error TS2323: Property 'q' is missing in type 'SomeBase'. +!!! error TS2352: Type 'SomeBase' cannot be converted to type 'SomeOther'. +!!! error TS2352: Property 'q' is missing in type 'SomeBase'. someOther = someOther; diff --git a/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt b/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt index c663c6a41e49e..42ed640e8fc29 100644 --- a/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt +++ b/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts(17,9): error TS2323: Type 'I2' is not comparable to type 'I1 & I3'. +tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts(17,9): error TS2352: Type 'I2' cannot be converted to type 'I1 & I3'. Type 'I2' is not comparable to type 'I3'. Property 'p3' is missing in type 'I2'. -tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts(18,9): error TS2323: Type 'I2' is not comparable to type 'I3'. +tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts(18,9): error TS2352: Type 'I2' cannot be converted to type 'I3'. ==== tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts (2 errors) ==== @@ -23,12 +23,12 @@ tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithInt var a = z; ~~~~~~~~~~ -!!! error TS2323: Type 'I2' is not comparable to type 'I1 & I3'. -!!! error TS2323: Type 'I2' is not comparable to type 'I3'. -!!! error TS2323: Property 'p3' is missing in type 'I2'. +!!! error TS2352: Type 'I2' cannot be converted to type 'I1 & I3'. +!!! error TS2352: Type 'I2' is not comparable to type 'I3'. +!!! error TS2352: Property 'p3' is missing in type 'I2'. var b = z; ~~~~~ -!!! error TS2323: Type 'I2' is not comparable to type 'I3'. +!!! error TS2352: Type 'I2' cannot be converted to type 'I3'. var c = z; var d = y; \ No newline at end of file diff --git a/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt b/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt index a25b6bbb83204..7bc2a9df9b3ad 100644 --- a/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt +++ b/tests/baselines/reference/typeAssertionsWithUnionTypes01.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithUnionTypes01.ts(14,9): error TS2323: Type 'I1' is not comparable to type 'number'. +tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithUnionTypes01.ts(14,9): error TS2352: Type 'I1' cannot be converted to type 'number'. ==== tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithUnionTypes01.ts (1 errors) ==== @@ -17,7 +17,7 @@ tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithUni var a = z; var b = z; ~~~~~~~~~ -!!! error TS2323: Type 'I1' is not comparable to type 'number'. +!!! error TS2352: Type 'I1' cannot be converted to type 'number'. var c = z; var d = y; \ No newline at end of file From 3cc64cbd296dfde5444279d2d5c37df58f709183 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 30 Mar 2016 01:03:32 -0700 Subject: [PATCH 22/22] Undo comment override from merge. --- src/compiler/checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 76f32b2fece77..775e4a083996f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14478,8 +14478,8 @@ namespace ts { if (produceDiagnostics && clause.kind === SyntaxKind.CaseClause) { const caseClause = clause; // TypeScript 1.0 spec (April 2014): 5.9 - // In a 'switch' statement, each 'case' expression must be of a type that is assignable to or from the type of the 'switch' expression. - // TODO (drosen): this needs to be amended to reflect the "comparable" relationship. + // In a 'switch' statement, each 'case' expression must be of a type that is comparable + // to or from the type of the 'switch' expression. const caseType = checkExpression(caseClause.expression); if (!isTypeComparableTo(expressionType, caseType)) { // expressionType is not comparable to caseType, try the reversed check and report errors if it fails