mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #5517 from Microsoft/comparableRelation
Introduce the "comparable" relation
This commit is contained in:
+34
-15
@@ -5397,6 +5397,10 @@ 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);
|
||||
}
|
||||
@@ -5409,6 +5413,10 @@ 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);
|
||||
}
|
||||
@@ -5619,7 +5627,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_to_type_1 :
|
||||
Diagnostics.Type_0_is_not_assignable_to_type_1;
|
||||
}
|
||||
|
||||
reportError(message, sourceType, targetType);
|
||||
}
|
||||
|
||||
// Compare two types and return
|
||||
@@ -5648,10 +5663,12 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
if (source.flags & TypeFlags.StringLiteral && target === stringType) return Ternary.True;
|
||||
|
||||
if (relation === assignableRelation || relation === comparableRelation) {
|
||||
if (isTypeAny(source)) return Ternary.True;
|
||||
if (source === numberType && target.flags & TypeFlags.Enum) return Ternary.True;
|
||||
}
|
||||
|
||||
if (source.flags & TypeFlags.Boolean && target.flags & TypeFlags.Boolean) {
|
||||
return Ternary.True;
|
||||
}
|
||||
@@ -5674,26 +5691,28 @@ namespace ts {
|
||||
|
||||
const 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) {
|
||||
if (result = someTypeRelatedToType(<UnionType>source, target, reportErrors)) {
|
||||
return result;
|
||||
}
|
||||
result = someTypeRelatedToType(source as UnionType, target, reportErrors);
|
||||
}
|
||||
else {
|
||||
if (result = eachTypeRelatedToType(<UnionType>source, target, reportErrors)) {
|
||||
return result;
|
||||
}
|
||||
result = eachTypeRelatedToType(source as UnionType, target, reportErrors);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else if (target.flags & TypeFlags.Intersection) {
|
||||
if (result = typeRelatedToEachType(source, <IntersectionType>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) {
|
||||
@@ -5775,8 +5794,8 @@ namespace ts {
|
||||
}
|
||||
if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union ||
|
||||
source.flags & TypeFlags.Intersection && target.flags & TypeFlags.Intersection) {
|
||||
if (result = eachTypeRelatedToSomeType(<UnionOrIntersectionType>source, <UnionOrIntersectionType>target)) {
|
||||
if (result &= eachTypeRelatedToSomeType(<UnionOrIntersectionType>target, <UnionOrIntersectionType>source)) {
|
||||
if (result = eachTypeRelatedToSomeType(<UnionOrIntersectionType>source, <UnionOrIntersectionType>target, /*reportErrors*/ false)) {
|
||||
if (result &= eachTypeRelatedToSomeType(<UnionOrIntersectionType>target, <UnionOrIntersectionType>source, /*reportErrors*/ false)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -5827,7 +5846,7 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function eachTypeRelatedToSomeType(source: UnionOrIntersectionType, target: UnionOrIntersectionType): Ternary {
|
||||
function eachTypeRelatedToSomeType(source: UnionOrIntersectionType, target: UnionOrIntersectionType, reportErrors: boolean): Ternary {
|
||||
let result = Ternary.True;
|
||||
const sourceTypes = source.types;
|
||||
for (const sourceType of sourceTypes) {
|
||||
@@ -11015,7 +11034,7 @@ namespace ts {
|
||||
if (produceDiagnostics && targetType !== unknownType) {
|
||||
const 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, Diagnostics.Type_0_cannot_be_converted_to_type_1);
|
||||
}
|
||||
}
|
||||
return targetType;
|
||||
@@ -14458,7 +14477,7 @@ namespace ts {
|
||||
|
||||
if (produceDiagnostics && clause.kind === SyntaxKind.CaseClause) {
|
||||
const caseClause = <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 comparable
|
||||
// to or from the type of the 'switch' expression.
|
||||
const caseType = checkExpression(caseClause.expression);
|
||||
|
||||
@@ -1047,7 +1047,7 @@
|
||||
"category": "Error",
|
||||
"code": 2351
|
||||
},
|
||||
"Neither type '{0}' nor type '{1}' is assignable to the other.": {
|
||||
"Type '{0}' cannot be converted to type '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 2352
|
||||
},
|
||||
@@ -1875,6 +1875,10 @@
|
||||
"category": "Error",
|
||||
"code": 2677
|
||||
},
|
||||
"Type '{0}' is not comparable to type '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 2678
|
||||
},
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4000
|
||||
|
||||
@@ -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 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,8 +8,8 @@ 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: 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 {}[]
|
||||
|
||||
@@ -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 TS2352: Type 'number' cannot be converted to 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 TS2352: Type 'number' cannot be converted to type 'string'.
|
||||
|
||||
@@ -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 TS2352: Type '(v: number) => number' cannot be converted 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 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'.
|
||||
!!! error TS2352: Type '(v: number) => number' cannot be converted to type '(x: number) => string'.
|
||||
!!! error TS2352: Type 'number' is not comparable to type 'string'.
|
||||
@@ -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 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 TS2352: Neither type 'number' nor type 'string' is assignable to the other.
|
||||
!!! error TS2352: Type 'number' cannot be converted to type 'string'.
|
||||
var as = "hello";
|
||||
var as1 = as as string;
|
||||
|
||||
@@ -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 TS2352: Type '[number, string]' cannot be converted to 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 to type 'number'.
|
||||
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 assignable to 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 TS2352: Neither type '[number, string]' nor type '[number, number]' is assignable to the other.
|
||||
!!! 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 assignable to type 'number'.
|
||||
!!! error TS2352: Type 'string' is not comparable to type 'number'.
|
||||
var t9 = <[A, I]>classCDTuple;
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2352: Neither type '[C, D]' nor type '[A, I]' is assignable to the other.
|
||||
!!! 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 assignable to type 'A'.
|
||||
!!! error TS2352: Type 'C' is not comparable to type 'A'.
|
||||
!!! error TS2352: Property 'a' is missing in type 'C'.
|
||||
var array1 = <number[]>numStrTuple;
|
||||
~~~~~~
|
||||
|
||||
@@ -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 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 TS2352: Neither type '() => string' nor type '() => number' is assignable to the other.
|
||||
!!! error TS2352: Type 'string' is not assignable to type 'number'.
|
||||
!!! error TS2352: Type '() => string' cannot be converted to type '() => number'.
|
||||
!!! error TS2352: Type 'string' is not comparable to type 'number'.
|
||||
@@ -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 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 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'.
|
||||
!!! error TS2352: Type '() => string' cannot be converted to type '{ (): number; (i: number): number; }'.
|
||||
!!! error TS2352: Type 'string' is not comparable to type 'number'.
|
||||
@@ -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 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 TS2352: Neither type 'string' nor type 'number' is assignable to the other.
|
||||
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) => <number>s) { };
|
||||
~~~~~~~~~
|
||||
!!! error TS2352: Neither type 'string' nor type 'number' is assignable to the other.
|
||||
!!! 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 => <number>s) { };
|
||||
~~~~~~~~~
|
||||
!!! error TS2352: Neither type 'string' nor type 'number' is assignable to the other.
|
||||
!!! error TS2352: Type 'string' cannot be converted to type 'number'.
|
||||
|
||||
// Instantiated module
|
||||
module T { }
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
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/comparable/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'.
|
||||
}
|
||||
@@ -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) {
|
||||
}
|
||||
@@ -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) {
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
=== tests/cases/conformance/types/typeRelationships/comparable/equalityWithUnionTypes01.ts ===
|
||||
interface I1 {
|
||||
>I1 : Symbol(I1, Decl(equalityWithUnionTypes01.ts, 0, 0))
|
||||
|
||||
p1: number
|
||||
>p1 : Symbol(I1.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(I2.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))
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
=== tests/cases/conformance/types/typeRelationships/comparable/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
|
||||
}
|
||||
@@ -5,7 +5,7 @@ tests/cases/compiler/fuzzy.ts(21,20): error TS2322: Type '{ anything: number; on
|
||||
Type 'this' is not assignable to type 'I'.
|
||||
Type 'C' is not assignable to type 'I'.
|
||||
Property 'alsoWorks' is missing in type 'C'.
|
||||
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 TS2352: Type '{ oneI: this; }' cannot be converted to type 'R'.
|
||||
Property 'anything' is missing in type '{ oneI: this; }'.
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ tests/cases/compiler/fuzzy.ts(25,20): error TS2352: Neither type '{ oneI: this;
|
||||
worksToo():R {
|
||||
return <R>({ oneI: this });
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2352: Neither type '{ oneI: this; }' nor type 'R' is assignable to the other.
|
||||
!!! error TS2352: Type '{ oneI: this; }' cannot be converted to type 'R'.
|
||||
!!! error TS2352: Property 'anything' is missing in type '{ oneI: this; }'.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ tests/cases/compiler/genericTypeAssertions1.ts(3,5): error TS2322: Type 'A<numbe
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/compiler/genericTypeAssertions1.ts(4,5): error TS2322: Type 'A<A<number>>' is not assignable to type 'A<number>'.
|
||||
Type 'A<number>' is not assignable to type 'number'.
|
||||
tests/cases/compiler/genericTypeAssertions1.ts(4,21): error TS2352: Neither type 'A<number>' nor type 'A<A<number>>' is assignable to the other.
|
||||
Type 'number' is not assignable to type 'A<number>'.
|
||||
tests/cases/compiler/genericTypeAssertions1.ts(4,21): error TS2352: Type 'A<number>' cannot be converted to type 'A<A<number>>'.
|
||||
Type 'number' is not comparable to type 'A<number>'.
|
||||
|
||||
|
||||
==== 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<A<number>>' is not assignable to type 'A<number>'.
|
||||
!!! error TS2322: Type 'A<number>' is not assignable to type 'number'.
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2352: Neither type 'A<number>' nor type 'A<A<number>>' is assignable to the other.
|
||||
!!! error TS2352: Type 'number' is not assignable to type 'A<number>'.
|
||||
!!! error TS2352: Type 'A<number>' cannot be converted to type 'A<A<number>>'.
|
||||
!!! error TS2352: Type 'number' is not comparable to type 'A<number>'.
|
||||
@@ -5,7 +5,7 @@ tests/cases/compiler/genericTypeAssertions2.ts(10,5): error TS2322: Type 'B<stri
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/compiler/genericTypeAssertions2.ts(11,5): error TS2322: Type 'A<number>' is not assignable to type 'B<number>'.
|
||||
Property 'bar' is missing in type 'A<number>'.
|
||||
tests/cases/compiler/genericTypeAssertions2.ts(13,21): error TS2352: Neither type 'undefined[]' nor type 'A<number>' is assignable to the other.
|
||||
tests/cases/compiler/genericTypeAssertions2.ts(13,21): error TS2352: Type 'undefined[]' cannot be converted to type 'A<number>'.
|
||||
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<number> = <A<number>>new A();
|
||||
var r5: A<number> = <A<number>>[]; // error
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2352: Neither type 'undefined[]' nor type 'A<number>' is assignable to the other.
|
||||
!!! error TS2352: Type 'undefined[]' cannot be converted to type 'A<number>'.
|
||||
!!! error TS2352: Property 'foo' is missing in type 'undefined[]'.
|
||||
@@ -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 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 TS2352: Neither type
|
||||
y = <T>a;
|
||||
y = <T>b; // error: cannot convert B to T
|
||||
~~~~
|
||||
!!! error TS2352: Neither type 'B' nor type 'T' is assignable to the other.
|
||||
!!! error TS2352: Type 'B' cannot be converted to type 'T'.
|
||||
y = <T>c; // error: cannot convert C to T
|
||||
~~~~
|
||||
!!! error TS2352: Neither type 'C' nor type 'T' is assignable to the other.
|
||||
!!! error TS2352: Type 'C' cannot be converted to type 'T'.
|
||||
}
|
||||
@@ -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 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 TS2352: Neither type
|
||||
y = <T>a;
|
||||
y = <T>b; // error: cannot convert B to T
|
||||
~~~~
|
||||
!!! error TS2352: Neither type 'B' nor type 'T' is assignable to the other.
|
||||
!!! error TS2352: Type 'B' cannot be converted to type 'T'.
|
||||
y = <T>c; // error: cannot convert C to T
|
||||
~~~~
|
||||
!!! error TS2352: Neither type 'C' nor type 'T' is assignable to the other.
|
||||
!!! error TS2352: Type 'C' cannot be converted to type 'T'.
|
||||
}
|
||||
@@ -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 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'.
|
||||
|
||||
|
||||
==== 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 = <T>y;
|
||||
~~~~
|
||||
!!! error TS2352: Neither type 'U' nor type 'T' is assignable to the other.
|
||||
!!! error TS2352: Type 'U' cannot be converted to type 'T'.
|
||||
y = <U>x;
|
||||
~~~~
|
||||
!!! error TS2352: Neither type 'T' nor type 'U' is assignable to the other.
|
||||
!!! error TS2352: Type 'T' cannot be converted to type 'U'.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ tests/cases/compiler/genericTypeAssertions6.ts(19,17): error TS2352: Neither typ
|
||||
var d = <U>new Date();
|
||||
var e = <T><U>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 TS2352: Type 'U' cannot be converted to type 'T'.
|
||||
!!! error TS2352: Type 'Date' is not comparable to type 'T'.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ tests/cases/compiler/intTypeCheck.ts(182,5): error TS2322: Type '{}' is not assi
|
||||
Type '{}' provides no match for the signature 'new (): any'
|
||||
tests/cases/compiler/intTypeCheck.ts(183,5): error TS2322: Type 'Object' is not assignable to type 'i7'.
|
||||
Type 'Object' provides no match for the signature 'new (): any'
|
||||
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 TS2352: Type 'Base' cannot be converted to type 'i7'.
|
||||
Type 'Base' provides no match for the signature 'new (): any'
|
||||
tests/cases/compiler/intTypeCheck.ts(187,5): error TS2322: Type '() => void' is not assignable to type 'i7'.
|
||||
Type '() => void' provides no match for the signature 'new (): any'
|
||||
@@ -396,7 +396,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit
|
||||
var obj69: i7 = new obj66;
|
||||
var obj70: i7 = <i7>new Base;
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2352: Neither type 'Base' nor type 'i7' is assignable to the other.
|
||||
!!! error TS2352: Type 'Base' cannot be converted to type 'i7'.
|
||||
!!! error TS2352: Type 'Base' provides no match for the signature 'new (): any'
|
||||
var obj71: i7 = null;
|
||||
var obj72: i7 = function () { };
|
||||
|
||||
@@ -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 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 TS2352: Neither type 'numb
|
||||
var s = <string>(null);
|
||||
var b = <boolean>(n);
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2352: Neither type 'number' nor type 'boolean' is assignable to the other.
|
||||
!!! error TS2352: Type 'number' cannot be converted to type 'boolean'.
|
||||
|
||||
function isVoid() : void { }
|
||||
|
||||
|
||||
@@ -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 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 TS2352: Neith
|
||||
// Neither types is assignable to each other
|
||||
(<IFoo>{ c: null });
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2352: Neither type '{ c: null; }' nor type 'IFoo' is assignable to the other.
|
||||
!!! error TS2352: Type '{ c: null; }' cannot be converted to type 'IFoo'.
|
||||
!!! error TS2352: Property 'a' is missing in type '{ c: null; }'.
|
||||
@@ -1,4 +1,4 @@
|
||||
tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3.ts(25,1): error TS2352: Neither type 'C3<T2>' nor type 'C4' is assignable to the other.
|
||||
tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithPrivates3.ts(25,1): error TS2352: Type 'C3<T2>' cannot be converted to type 'C4'.
|
||||
Property 'y' is missing in type 'C3<T2>'.
|
||||
|
||||
|
||||
@@ -29,5 +29,5 @@ tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectType
|
||||
var c3: C3<T2>;
|
||||
<C4>c3; // Should fail (private x originates in the same declaration, but different types)
|
||||
~~~~~~
|
||||
!!! error TS2352: Neither type 'C3<T2>' nor type 'C4' is assignable to the other.
|
||||
!!! error TS2352: Type 'C3<T2>' cannot be converted to type 'C4'.
|
||||
!!! error TS2352: Property 'y' is missing in type 'C3<T2>'.
|
||||
@@ -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 TS2678: Type 'typeof Foo' is not comparable to type 'number'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/switchAssignmentCompat.ts (1 errors) ====
|
||||
@@ -7,6 +7,6 @@ tests/cases/compiler/switchAssignmentCompat.ts(4,10): error TS2322: Type 'typeof
|
||||
switch (0) {
|
||||
case Foo: break; // Error expected
|
||||
~~~
|
||||
!!! error TS2322: Type 'typeof Foo' is not assignable to type 'number'.
|
||||
!!! error TS2678: Type 'typeof Foo' is not comparable to type 'number'.
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts(19,10): error TS2678: Type 'number & boolean' is not comparable to type 'string & number'.
|
||||
Type 'number & boolean' is not comparable to type 'string'.
|
||||
tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts(23,10): error TS2678: 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) ====
|
||||
|
||||
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 TS2678: Type 'number & boolean' is not comparable to type 'string & number'.
|
||||
!!! error TS2678: Type 'number & boolean' is not comparable to type 'string'.
|
||||
break;
|
||||
|
||||
// No relation
|
||||
case bool:
|
||||
~~~~
|
||||
!!! error TS2678: Type 'boolean' is not comparable to type 'string & number'.
|
||||
!!! error TS2678: Type 'boolean' is not comparable to type 'string'.
|
||||
break;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithUnionTypes01.ts(23,10): error TS2678: Type 'boolean' is not comparable to type 'string | number'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithUnionTypes01.ts (1 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:
|
||||
break;
|
||||
|
||||
// No relation
|
||||
case bool:
|
||||
~~~~
|
||||
!!! error TS2678: Type 'boolean' is not comparable to type 'string | number'.
|
||||
break;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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 TS2678: Type 'typeof Foo' is not comparable to type 'number'.
|
||||
tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(5,10): error TS2678: Type 'string' is not comparable to type 'number'.
|
||||
tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2678: Type 'boolean' is not comparable to type 'number'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/switchCasesExpressionTypeMismatch.ts (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 TS2678: Type 'typeof Foo' is not comparable to type 'number'.
|
||||
case "sss": break; // Error
|
||||
~~~~~
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
!!! error TS2678: Type 'string' is not comparable to type 'number'.
|
||||
case 123: break; // No Error
|
||||
case true: break; // Error
|
||||
~~~~
|
||||
!!! error TS2322: Type 'boolean' is not assignable to type 'number'.
|
||||
!!! error TS2678: Type 'boolean' is not comparable to type 'number'.
|
||||
}
|
||||
|
||||
var s: any = 0;
|
||||
|
||||
@@ -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 TS2678: 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,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 TS2678: Type '{ id: number; name: string; }' is not comparable to type 'C'.
|
||||
!!! error TS2678: Object literal may only specify known properties, and 'name' does not exist in type 'C'.
|
||||
case new C():
|
||||
}
|
||||
|
||||
|
||||
@@ -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 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 TS2352: Neither type 'SomeOther' nor type 'SomeDerived' is assignable to the other.
|
||||
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 TS2352: Neither type 'SomeDerived' nor type 'SomeOther' is assignable to the other.
|
||||
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 TS2352: Neither type 'SomeBase' nor type 'SomeOther' is assignable to the other.
|
||||
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'.
|
||||
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,5): error TS2304: Cannot find name 'numOrStr'.
|
||||
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,14): error TS1005: '>' expected.
|
||||
@@ -58,23 +58,23 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,50): err
|
||||
someBase = <SomeBase>someBase;
|
||||
someBase = <SomeBase>someOther; // Error
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2352: Neither type 'SomeOther' nor type 'SomeBase' is assignable to the other.
|
||||
!!! error TS2352: Type 'SomeOther' cannot be converted to type 'SomeBase'.
|
||||
!!! error TS2352: Property 'p' is missing in type 'SomeOther'.
|
||||
|
||||
someDerived = <SomeDerived>someDerived;
|
||||
someDerived = <SomeDerived>someBase;
|
||||
someDerived = <SomeDerived>someOther; // Error
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2352: Neither type 'SomeOther' nor type 'SomeDerived' is assignable to the other.
|
||||
!!! error TS2352: Type 'SomeOther' cannot be converted to type 'SomeDerived'.
|
||||
!!! error TS2352: Property 'x' is missing in type 'SomeOther'.
|
||||
|
||||
someOther = <SomeOther>someDerived; // Error
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2352: Neither type 'SomeDerived' nor type 'SomeOther' is assignable to the other.
|
||||
!!! error TS2352: Type 'SomeDerived' cannot be converted to type 'SomeOther'.
|
||||
!!! error TS2352: Property 'q' is missing in type 'SomeDerived'.
|
||||
someOther = <SomeOther>someBase; // Error
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2352: Neither type 'SomeBase' nor type 'SomeOther' is assignable to the other.
|
||||
!!! error TS2352: Type 'SomeBase' cannot be converted to type 'SomeOther'.
|
||||
!!! error TS2352: Property 'q' is missing in type 'SomeBase'.
|
||||
someOther = <SomeOther>someOther;
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
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 TS2352: Type 'I2' cannot be converted to type 'I3'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/typeRelationships/comparable/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 = <I1 & I3>z;
|
||||
~~~~~~~~~~
|
||||
!!! 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 = <I3>z;
|
||||
~~~~~
|
||||
!!! error TS2352: Type 'I2' cannot be converted to type 'I3'.
|
||||
var c = <I2>z;
|
||||
var d = <I1>y;
|
||||
|
||||
@@ -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 = <I1 & I3>z;
|
||||
var b = <I3>z;
|
||||
var c = <I2>z;
|
||||
var d = <I1>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;
|
||||
@@ -0,0 +1,23 @@
|
||||
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) ====
|
||||
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 = <number | I2>z;
|
||||
var b = <number>z;
|
||||
~~~~~~~~~
|
||||
!!! error TS2352: Type 'I1' cannot be converted to type 'number'.
|
||||
var c = <I2>z;
|
||||
var d = <I1>y;
|
||||
|
||||
@@ -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 = <number | I2>z;
|
||||
var b = <number>z;
|
||||
var c = <I2>z;
|
||||
var d = <I1>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;
|
||||
+24
@@ -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) {
|
||||
}
|
||||
+20
@@ -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) {
|
||||
}
|
||||
+25
@@ -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;
|
||||
}
|
||||
+25
@@ -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;
|
||||
}
|
||||
+20
@@ -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 = <I1 & I3>z;
|
||||
var b = <I3>z;
|
||||
var c = <I2>z;
|
||||
var d = <I1>y;
|
||||
+16
@@ -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 = <number | I2>z;
|
||||
var b = <number>z;
|
||||
var c = <I2>z;
|
||||
var d = <I1>y;
|
||||
Reference in New Issue
Block a user