Merge pull request #1017 from Microsoft/fixTypeRelationCaching

Fix type relation caching
This commit is contained in:
Anders Hejlsberg
2014-10-31 14:37:40 -07:00
34 changed files with 566 additions and 356 deletions
+267 -203
View File
@@ -2163,7 +2163,7 @@ module ts {
return false;
}
for (var i = 0; i < s.length; i++) {
if (!compareSignatures(s[i], t[i], /*compareReturnTypes*/ false, isTypeIdenticalTo)) {
if (!compareSignatures(s[i], t[i], /*compareReturnTypes*/ false, compareTypes)) {
return false;
}
}
@@ -3209,38 +3209,32 @@ module ts {
// TYPE CHECKING
var subtypeRelation: Map<boolean> = {};
var assignableRelation: Map<boolean> = {};
var identityRelation: Map<boolean> = {};
var subtypeRelation: Map<Ternary> = {};
var assignableRelation: Map<Ternary> = {};
var identityRelation: Map<Ternary> = {};
function isTypeIdenticalTo(source: Type, target: Type): boolean {
return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined);
}
function compareTypes(source: Type, target: Type): Ternary {
return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined) ? Ternary.True : Ternary.False;
}
function isTypeSubtypeOf(source: Type, target: Type): boolean {
return checkTypeSubtypeOf(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);
}
function isTypeAssignableTo(source: Type, target: Type): boolean {
return checkTypeAssignableTo(source, target, /*errorNode*/ undefined);
}
function checkTypeAssignableTo(source: Type, target: Type, errorNode: Node, headMessage?: DiagnosticMessage): boolean {
return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage);
function checkTypeSubtypeOf(source: Type, target: Type, errorNode: Node, headMessage?: DiagnosticMessage, containingMessageChain?: DiagnosticMessageChain): boolean {
return checkTypeRelatedTo(source, target, subtypeRelation, errorNode, headMessage, containingMessageChain);
}
function isTypeRelatedTo(source: Type, target: Type, relation: Map<boolean>): boolean {
return checkTypeRelatedTo(source, target, relation, /*errorNode*/ undefined);
function checkTypeAssignableTo(source: Type, target: Type, errorNode: Node, headMessage?: DiagnosticMessage): boolean {
return checkTypeRelatedTo(source, target, assignableRelation, errorNode, headMessage);
}
function isSignatureAssignableTo(source: Signature, target: Signature): boolean {
@@ -3249,71 +3243,10 @@ module ts {
return checkTypeRelatedTo(sourceType, targetType, assignableRelation, /*errorNode*/ undefined);
}
function isPropertyIdenticalTo(sourceProp: Symbol, targetProp: Symbol): boolean {
return isPropertyIdenticalToRecursive(sourceProp, targetProp, /*reportErrors*/ false, (s, t, _reportErrors) => isTypeIdenticalTo(s, t));
}
function checkInheritedPropertiesAreIdentical(type: InterfaceType, typeNode: Node): boolean {
if (!type.baseTypes.length || type.baseTypes.length === 1) {
return true;
}
var seen: Map<{ prop: Symbol; containingType: Type }> = {};
forEach(type.declaredProperties, p => { seen[p.name] = { prop: p, containingType: type }; });
var ok = true;
for (var i = 0, len = type.baseTypes.length; i < len; ++i) {
var base = type.baseTypes[i];
var properties = getPropertiesOfObjectType(base);
for (var j = 0, proplen = properties.length; j < proplen; ++j) {
var prop = properties[j];
if (!hasProperty(seen, prop.name)) {
seen[prop.name] = { prop: prop, containingType: base };
}
else {
var existing = seen[prop.name];
var isInheritedProperty = existing.containingType !== type;
if (isInheritedProperty && !isPropertyIdenticalTo(existing.prop, prop)) {
ok = false;
var typeName1 = typeToString(existing.containingType);
var typeName2 = typeToString(base);
var errorInfo = chainDiagnosticMessages(undefined, Diagnostics.Named_properties_0_of_types_1_and_2_are_not_identical, prop.name, typeName1, typeName2);
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2, typeToString(type), typeName1, typeName2);
addDiagnostic(createDiagnosticForNodeFromMessageChain(typeNode, errorInfo, program.getCompilerHost().getNewLine()));
}
}
}
}
return ok;
}
function isPropertyIdenticalToRecursive(sourceProp: Symbol, targetProp: Symbol, reportErrors: boolean, relate: (source: Type, target: Type, reportErrors: boolean) => boolean): boolean {
// Two members are considered identical when
// - they are public properties with identical names, optionality, and types,
// - they are private or protected properties originating in the same declaration and having identical types
if (sourceProp === targetProp) {
return true;
}
var sourcePropAccessibility = getDeclarationFlagsFromSymbol(sourceProp) & (NodeFlags.Private | NodeFlags.Protected);
var targetPropAccessibility = getDeclarationFlagsFromSymbol(targetProp) & (NodeFlags.Private | NodeFlags.Protected);
if (sourcePropAccessibility !== targetPropAccessibility) {
return false;
}
if (sourcePropAccessibility) {
return getTargetSymbol(sourceProp) === getTargetSymbol(targetProp) && relate(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
}
else {
return isOptionalProperty(sourceProp) === isOptionalProperty(targetProp) && relate(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
}
}
function checkTypeRelatedTo(
source: Type,
target: Type,
relation: Map<boolean>,
relation: Map<Ternary>,
errorNode: Node,
headMessage?: DiagnosticMessage,
containingMessageChain?: DiagnosticMessageChain): boolean {
@@ -3327,7 +3260,7 @@ module ts {
Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
var result = isRelatedToWithCustomErrors(source, target, errorNode !== undefined, headMessage);
var result = isRelatedTo(source, target, errorNode !== undefined, headMessage);
if (overflow) {
error(errorNode, Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target));
}
@@ -3337,54 +3270,55 @@ module ts {
}
addDiagnostic(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo, program.getCompilerHost().getNewLine()));
}
return result;
return result !== Ternary.False;
function reportError(message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): void {
errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2);
}
function isRelatedTo(source: Type, target: Type, reportErrors?: boolean): boolean {
return isRelatedToWithCustomErrors(source, target, reportErrors, /*headMessage*/ undefined);
}
function isRelatedToWithCustomErrors(source: Type, target: Type, reportErrors: boolean, headMessage: DiagnosticMessage): boolean {
// Compare two types and return
// Ternary.True if they are related with no assumptions,
// Ternary.Maybe if they are related with assumptions of other relationships, or
// Ternary.False if they are not related.
function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage): Ternary {
var result: Ternary;
if (relation === identityRelation) {
// both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases
if (source === target) return true;
if (source === target) return Ternary.True;
}
else {
if (source === target) return true;
if (target.flags & TypeFlags.Any) return true;
if (source === undefinedType) return true;
if (source === nullType && target !== undefinedType) return true;
if (source.flags & TypeFlags.Enum && target === numberType) return true;
if (source.flags & TypeFlags.StringLiteral && target === stringType) return true;
if (source === target) return Ternary.True;
if (target.flags & TypeFlags.Any) return Ternary.True;
if (source === undefinedType) return Ternary.True;
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 (source.flags & TypeFlags.Any) return true;
if (source === numberType && target.flags & TypeFlags.Enum) return true;
if (source.flags & TypeFlags.Any) return Ternary.True;
if (source === numberType && target.flags & TypeFlags.Enum) return Ternary.True;
}
}
if (source.flags & TypeFlags.Union) {
if (unionTypeRelatedToType(<UnionType>source, target, reportErrors)) {
return true;
if (result = unionTypeRelatedToType(<UnionType>source, target, reportErrors)) {
return result;
}
}
else if (target.flags & TypeFlags.Union) {
if (typeRelatedToUnionType(source, <UnionType>target, reportErrors)) {
return true;
if (result = typeRelatedToUnionType(source, <UnionType>target, reportErrors)) {
return result;
}
}
else if (source.flags & TypeFlags.TypeParameter && target.flags & TypeFlags.TypeParameter) {
if (typeParameterRelatedTo(<TypeParameter>source, <TypeParameter>target, reportErrors)) {
return true;
if (result = typeParameterRelatedTo(<TypeParameter>source, <TypeParameter>target, reportErrors)) {
return result;
}
}
else {
var saveErrorInfo = errorInfo;
if (source.flags & TypeFlags.Reference && target.flags & TypeFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target) {
// We have type references to same target type, see if relationship holds for all type arguments
if (typesRelatedTo((<TypeReference>source).typeArguments, (<TypeReference>target).typeArguments, reportErrors)) {
return true;
if (result = typesRelatedTo((<TypeReference>source).typeArguments, (<TypeReference>target).typeArguments, reportErrors)) {
return result;
}
}
// Even if relationship doesn't hold for type arguments, it may hold in a structural comparison
@@ -3393,9 +3327,9 @@ module ts {
// identity relation does not use apparent type
var sourceOrApparentType = relation === identityRelation ? source : getApparentType(source);
if (sourceOrApparentType.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType &&
objectTypeRelatedTo(sourceOrApparentType, <ObjectType>target, reportStructuralErrors)) {
(result = objectTypeRelatedTo(sourceOrApparentType, <ObjectType>target, reportStructuralErrors))) {
errorInfo = saveErrorInfo;
return true;
return result;
}
}
if (reportErrors) {
@@ -3403,61 +3337,67 @@ module ts {
Debug.assert(headMessage);
reportError(headMessage, typeToString(source), typeToString(target));
}
return false;
return Ternary.False;
}
function typeRelatedToUnionType(source: Type, target: UnionType, reportErrors: boolean): boolean {
function typeRelatedToUnionType(source: Type, target: UnionType, reportErrors: boolean): Ternary {
var targetTypes = target.types;
for (var i = 0, len = targetTypes.length; i < len; i++) {
if (isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1)) {
return true;
var related = isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1);
if (related) {
return related;
}
}
return false;
return Ternary.False;
}
function unionTypeRelatedToType(source: UnionType, target: Type, reportErrors: boolean): boolean {
function unionTypeRelatedToType(source: UnionType, target: Type, reportErrors: boolean): Ternary {
var result = Ternary.True;
var sourceTypes = source.types;
for (var i = 0, len = sourceTypes.length; i < len; i++) {
if (!isRelatedTo(sourceTypes[i], target, reportErrors)) {
return false;
var related = isRelatedTo(sourceTypes[i], target, reportErrors);
if (!related) {
return Ternary.False;
}
result &= related;
}
return true;
return result;
}
function typesRelatedTo(sources: Type[], targets: Type[], reportErrors: boolean): boolean {
function typesRelatedTo(sources: Type[], targets: Type[], reportErrors: boolean): Ternary {
var result = Ternary.True;
for (var i = 0, len = sources.length; i < len; i++) {
if (!isRelatedTo(sources[i], targets[i], reportErrors)) return false;
var related = isRelatedTo(sources[i], targets[i], reportErrors);
if (!related) {
return Ternary.False;
}
result &= related;
}
return true;
return result;
}
function typeParameterRelatedTo(source: TypeParameter, target: TypeParameter, reportErrors: boolean): boolean {
function typeParameterRelatedTo(source: TypeParameter, target: TypeParameter, reportErrors: boolean): Ternary {
if (relation === identityRelation) {
if (source.symbol.name !== target.symbol.name) {
return false;
return Ternary.False;
}
// covers case when both type parameters does not have constraint (both equal to noConstraintType)
if (source.constraint === target.constraint) {
return true;
return Ternary.True;
}
if (source.constraint === noConstraintType || target.constraint === noConstraintType) {
return false;
return Ternary.False;
}
return isRelatedTo(source.constraint, target.constraint, reportErrors);
}
else {
while (true) {
var constraint = getConstraintOfTypeParameter(source);
if (constraint === target) return true;
if (constraint === target) return Ternary.True;
if (!(constraint && constraint.flags & TypeFlags.TypeParameter)) break;
source = <TypeParameter>constraint;
}
return false;
return Ternary.False;
}
}
@@ -3466,18 +3406,25 @@ module ts {
// Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are
// equal and infinitely expanding. Fourth, if we have reached a depth of 100 nested comparisons, assume we have runaway recursion
// and issue an error. Otherwise, actually compare the structure of the two types.
function objectTypeRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean {
if (overflow) return false;
var result: boolean;
function objectTypeRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): Ternary {
if (overflow) {
return Ternary.False;
}
var id = source.id + "," + target.id;
if ((result = relation[id]) !== undefined) return result;
var related = relation[id];
if (related !== undefined) {
return related;
}
if (depth > 0) {
for (var i = 0; i < depth; i++) {
if (source === sourceStack[i] && target === targetStack[i]) return true;
// If source and target are already being compared, consider them related with assumptions
if (source === sourceStack[i] && target === targetStack[i]) {
return Ternary.Maybe;
}
}
if (depth === 100) {
overflow = true;
return false;
return Ternary.False;
}
}
else {
@@ -3491,15 +3438,28 @@ module ts {
var saveExpandingFlags = expandingFlags;
if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack)) expandingFlags |= 1;
if (!(expandingFlags & 2) && isDeeplyNestedGeneric(target, targetStack)) expandingFlags |= 2;
result = expandingFlags === 3 ||
propertiesRelatedTo(source, target, reportErrors) &&
signaturesRelatedTo(source, target, SignatureKind.Call, reportErrors) &&
signaturesRelatedTo(source, target, SignatureKind.Construct, reportErrors) &&
stringIndexTypesRelatedTo(source, target, reportErrors) &&
numberIndexTypesRelatedTo(source, target, reportErrors);
if (expandingFlags === 3) {
var result = Ternary.True;
}
else {
var result = propertiesRelatedTo(source, target, reportErrors);
if (result) {
result &= signaturesRelatedTo(source, target, SignatureKind.Call, reportErrors);
if (result) {
result &= signaturesRelatedTo(source, target, SignatureKind.Construct, reportErrors);
if (result) {
result &= stringIndexTypesRelatedTo(source, target, reportErrors);
if (result) {
result &= numberIndexTypesRelatedTo(source, target, reportErrors);
}
}
}
}
}
expandingFlags = saveExpandingFlags;
depth--;
if (depth === 0) {
// Only cache results that are free of assumptions
if (result !== Ternary.Maybe) {
relation[id] = result;
}
return result;
@@ -3525,10 +3485,11 @@ module ts {
return false;
}
function propertiesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean {
function propertiesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): Ternary {
if (relation === identityRelation) {
return propertiesIdenticalTo(source, target, reportErrors);
return propertiesIdenticalTo(source, target);
}
var result = Ternary.True;
var properties = getPropertiesOfObjectType(target);
for (var i = 0; i < properties.length; i++) {
var targetProp = properties[i];
@@ -3539,7 +3500,7 @@ module ts {
if (reportErrors) {
reportError(Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source));
}
return false;
return Ternary.False;
}
}
else if (!(targetProp.flags & SymbolFlags.Prototype)) {
@@ -3557,7 +3518,7 @@ module ts {
typeToString(sourceFlags & NodeFlags.Private ? target : source));
}
}
return false;
return Ternary.False;
}
}
else if (targetFlags & NodeFlags.Protected) {
@@ -3569,7 +3530,7 @@ module ts {
reportError(Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2,
symbolToString(targetProp), typeToString(sourceClass || source), typeToString(targetClass));
}
return false;
return Ternary.False;
}
}
else if (sourceFlags & NodeFlags.Protected) {
@@ -3577,14 +3538,16 @@ module ts {
reportError(Diagnostics.Property_0_is_protected_in_type_1_but_public_in_type_2,
symbolToString(targetProp), typeToString(source), typeToString(target));
}
return false;
return Ternary.False;
}
if (!isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors)) {
var related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
if (!related) {
if (reportErrors) {
reportError(Diagnostics.Types_of_property_0_are_incompatible, symbolToString(targetProp));
}
return false;
return Ternary.False;
}
result &= related;
if (isOptionalProperty(sourceProp) && !isOptionalProperty(targetProp)) {
// TypeScript 1.0 spec (April 2014): 3.8.3
// S is a subtype of a type T, and T is a supertype of S if ...
@@ -3597,37 +3560,46 @@ module ts {
reportError(Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2,
symbolToString(targetProp), typeToString(source), typeToString(target));
}
return false;
return Ternary.False;
}
}
}
}
return true;
return result;
}
function propertiesIdenticalTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean {
function propertiesIdenticalTo(source: ObjectType, target: ObjectType): Ternary {
var sourceProperties = getPropertiesOfObjectType(source);
var targetProperties = getPropertiesOfObjectType(target);
if (sourceProperties.length !== targetProperties.length) {
return false;
return Ternary.False;
}
var result = Ternary.True;
for (var i = 0, len = sourceProperties.length; i < len; ++i) {
var sourceProp = sourceProperties[i];
var targetProp = getPropertyOfObjectType(target, sourceProp.name);
if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) {
return false;
if (!targetProp) {
return Ternary.False;
}
var related = compareProperties(sourceProp, targetProp, isRelatedTo);
if (!related) {
return Ternary.False;
}
result &= related;
}
return true;
return result;
}
function signaturesRelatedTo(source: ObjectType, target: ObjectType, kind: SignatureKind, reportErrors: boolean): boolean {
function signaturesRelatedTo(source: ObjectType, target: ObjectType, kind: SignatureKind, reportErrors: boolean): Ternary {
if (relation === identityRelation) {
return signaturesIdenticalTo(source, target, kind, reportErrors);
return signaturesIdenticalTo(source, target, kind);
}
if (target === anyFunctionType || source === anyFunctionType) {
return Ternary.True;
}
if (target === anyFunctionType || source === anyFunctionType) return true;
var sourceSignatures = getSignaturesOfType(source, kind);
var targetSignatures = getSignaturesOfType(target, kind);
var result = Ternary.True;
var saveErrorInfo = errorInfo;
outer: for (var i = 0; i < targetSignatures.length; i++) {
var t = targetSignatures[i];
@@ -3636,7 +3608,9 @@ module ts {
for (var j = 0; j < sourceSignatures.length; j++) {
var s = sourceSignatures[j];
if (!s.hasStringLiterals || source.flags & TypeFlags.FromSignature) {
if (signatureRelatedTo(s, t, localErrors)) {
var related = signatureRelatedTo(s, t, localErrors);
if (related) {
result &= related;
errorInfo = saveErrorInfo;
continue outer;
}
@@ -3644,18 +3618,18 @@ module ts {
localErrors = false;
}
}
return false;
return Ternary.False;
}
}
return true;
return result;
}
function signatureRelatedTo(source: Signature, target: Signature, reportErrors: boolean): boolean {
function signatureRelatedTo(source: Signature, target: Signature, reportErrors: boolean): Ternary {
if (source === target) {
return true;
return Ternary.True;
}
if (!target.hasRestParameter && source.minArgumentCount > target.parameters.length) {
return false;
return Ternary.False;
}
var sourceMax = source.parameters.length;
var targetMax = target.parameters.length;
@@ -3680,45 +3654,52 @@ module ts {
// M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N
source = getErasedSignature(source);
target = getErasedSignature(target);
var result = Ternary.True;
for (var i = 0; i < checkCount; i++) {
var s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source);
var t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target);
var saveErrorInfo = errorInfo;
if (!isRelatedTo(s, t, reportErrors)) {
if (!isRelatedTo(t, s, false)) {
var related = isRelatedTo(s, t, reportErrors);
if (!related) {
related = isRelatedTo(t, s, false);
if (!related) {
if (reportErrors) {
reportError(Diagnostics.Types_of_parameters_0_and_1_are_incompatible,
source.parameters[i < sourceMax ? i : sourceMax].name,
target.parameters[i < targetMax ? i : targetMax].name);
}
return false;
return Ternary.False;
}
errorInfo = saveErrorInfo;
}
result &= related;
}
var t = getReturnTypeOfSignature(target);
if (t === voidType) return true;
if (t === voidType) return result;
var s = getReturnTypeOfSignature(source);
return isRelatedTo(s, t, reportErrors);
return result & isRelatedTo(s, t, reportErrors);
}
function signaturesIdenticalTo(source: ObjectType, target: ObjectType, kind: SignatureKind, reportErrors: boolean): boolean {
function signaturesIdenticalTo(source: ObjectType, target: ObjectType, kind: SignatureKind): Ternary {
var sourceSignatures = getSignaturesOfType(source, kind);
var targetSignatures = getSignaturesOfType(target, kind);
if (sourceSignatures.length !== targetSignatures.length) {
return false;
return Ternary.False;
}
var result = Ternary.True;
for (var i = 0, len = sourceSignatures.length; i < len; ++i) {
if (!compareSignatures(sourceSignatures[i], targetSignatures[i], /*compareReturnTypes*/ true, isRelatedTo)) {
return false;
var related = compareSignatures(sourceSignatures[i], targetSignatures[i], /*compareReturnTypes*/ true, isRelatedTo);
if (!related) {
return Ternary.False;
}
result &= related;
}
return true;
return result;
}
function stringIndexTypesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean {
function stringIndexTypesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): Ternary {
if (relation === identityRelation) {
return indexTypesIdenticalTo(IndexKind.String, source, target, reportErrors);
return indexTypesIdenticalTo(IndexKind.String, source, target);
}
var targetType = getIndexTypeOfType(target, IndexKind.String);
if (targetType) {
@@ -3727,21 +3708,23 @@ module ts {
if (reportErrors) {
reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source));
}
return false;
return Ternary.False;
}
if (!isRelatedTo(sourceType, targetType, reportErrors)) {
var related = isRelatedTo(sourceType, targetType, reportErrors);
if (!related) {
if (reportErrors) {
reportError(Diagnostics.Index_signatures_are_incompatible);
}
return false;
return Ternary.False;
}
return related;
}
return true;
return Ternary.True;
}
function numberIndexTypesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean {
function numberIndexTypesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): Ternary {
if (relation === identityRelation) {
return indexTypesIdenticalTo(IndexKind.Number, source, target, reportErrors);
return indexTypesIdenticalTo(IndexKind.Number, source, target);
}
var targetType = getIndexTypeOfType(target, IndexKind.Number);
if (targetType) {
@@ -3751,53 +3734,92 @@ module ts {
if (reportErrors) {
reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source));
}
return false;
return Ternary.False;
}
if (sourceStringType && sourceNumberType) {
// If we know for sure we're testing both string and numeric index types then only report errors from the second one
var compatible = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors);
var related = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors);
}
else {
var compatible = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors);
var related = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors);
}
if (!compatible) {
if (!related) {
if (reportErrors) {
reportError(Diagnostics.Index_signatures_are_incompatible);
}
return false;
return Ternary.False;
}
return related;
}
return true;
return Ternary.True;
}
function indexTypesIdenticalTo(indexKind: IndexKind, source: ObjectType, target: ObjectType, reportErrors: boolean): boolean {
function indexTypesIdenticalTo(indexKind: IndexKind, source: ObjectType, target: ObjectType): Ternary {
var targetType = getIndexTypeOfType(target, indexKind);
var sourceType = getIndexTypeOfType(source, indexKind);
return (!sourceType && !targetType) || (sourceType && targetType && isRelatedTo(sourceType, targetType, reportErrors));
if (!sourceType && !targetType) {
return Ternary.True;
}
if (sourceType && targetType) {
return isRelatedTo(sourceType, targetType);
}
return Ternary.False;
}
}
function compareSignatures(source: Signature, target: Signature, compareReturnTypes: boolean, compareTypes: (s: Type, t: Type) => boolean): boolean {
function isPropertyIdenticalTo(sourceProp: Symbol, targetProp: Symbol): boolean {
return compareProperties(sourceProp, targetProp, compareTypes) !== Ternary.False;
}
function compareProperties(sourceProp: Symbol, targetProp: Symbol, compareTypes: (source: Type, target: Type) => Ternary): Ternary {
// Two members are considered identical when
// - they are public properties with identical names, optionality, and types,
// - they are private or protected properties originating in the same declaration and having identical types
if (sourceProp === targetProp) {
return Ternary.True;
}
var sourcePropAccessibility = getDeclarationFlagsFromSymbol(sourceProp) & (NodeFlags.Private | NodeFlags.Protected);
var targetPropAccessibility = getDeclarationFlagsFromSymbol(targetProp) & (NodeFlags.Private | NodeFlags.Protected);
if (sourcePropAccessibility !== targetPropAccessibility) {
return Ternary.False;
}
if (sourcePropAccessibility) {
if (getTargetSymbol(sourceProp) !== getTargetSymbol(targetProp)) {
return Ternary.False;
}
}
else {
if (isOptionalProperty(sourceProp) !== isOptionalProperty(targetProp)) {
return Ternary.False;
}
}
return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp));
}
function compareSignatures(source: Signature, target: Signature, compareReturnTypes: boolean, compareTypes: (s: Type, t: Type) => Ternary): Ternary {
if (source === target) {
return true;
return Ternary.True;
}
if (source.parameters.length !== target.parameters.length ||
source.minArgumentCount !== target.minArgumentCount ||
source.hasRestParameter !== target.hasRestParameter) {
return false;
return Ternary.False;
}
var result = Ternary.True;
if (source.typeParameters && target.typeParameters) {
if (source.typeParameters.length !== target.typeParameters.length) {
return false;
return Ternary.False;
}
for (var i = 0, len = source.typeParameters.length; i < len; ++i) {
if (!compareTypes(source.typeParameters[i], target.typeParameters[i])) {
return false;
var related = compareTypes(source.typeParameters[i], target.typeParameters[i]);
if (!related) {
return Ternary.False;
}
result &= related;
}
}
else if (source.typeParameters || source.typeParameters) {
return false;
return Ternary.False;
}
// Spec 1.0 Section 3.8.3 & 3.8.4:
// M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N
@@ -3806,11 +3828,16 @@ module ts {
for (var i = 0, len = source.parameters.length; i < len; i++) {
var s = source.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]);
var t = target.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]);
if (!compareTypes(s, t)) {
return false;
var related = compareTypes(s, t);
if (!related) {
return Ternary.False;
}
result &= related;
}
return !compareReturnTypes || compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target));
if (compareReturnTypes) {
result &= compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target));
}
return result;
}
function isSupertypeOfEach(candidate: Type, types: Type[]): boolean {
@@ -4859,7 +4886,7 @@ module ts {
if (!result) {
result = signature;
}
else if (!compareSignatures(result, signature, /*compareReturnTypes*/ true, isTypeIdenticalTo)) {
else if (!compareSignatures(result, signature, /*compareReturnTypes*/ true, compareTypes)) {
return undefined;
}
}
@@ -5251,7 +5278,7 @@ module ts {
return typeArgumentsAreAssignable;
}
function checkApplicableSignature(node: CallExpression, signature: Signature, relation: Map<boolean>, excludeArgument: boolean[], reportErrors: boolean) {
function checkApplicableSignature(node: CallExpression, signature: Signature, relation: Map<Ternary>, excludeArgument: boolean[], reportErrors: boolean) {
if (node.arguments) {
for (var i = 0; i < node.arguments.length; i++) {
var arg = node.arguments[i];
@@ -5389,7 +5416,7 @@ module ts {
return resolveErrorCall(node);
function chooseOverload(candidates: Signature[], relation: Map<boolean>, excludeArgument: boolean[]) {
function chooseOverload(candidates: Signature[], relation: Map<Ternary>, excludeArgument: boolean[]) {
for (var i = 0; i < candidates.length; i++) {
if (!signatureHasCorrectArity(node, candidates[i])) {
continue;
@@ -7574,6 +7601,43 @@ module ts {
return true;
}
function checkInheritedPropertiesAreIdentical(type: InterfaceType, typeNode: Node): boolean {
if (!type.baseTypes.length || type.baseTypes.length === 1) {
return true;
}
var seen: Map<{ prop: Symbol; containingType: Type }> = {};
forEach(type.declaredProperties, p => { seen[p.name] = { prop: p, containingType: type }; });
var ok = true;
for (var i = 0, len = type.baseTypes.length; i < len; ++i) {
var base = type.baseTypes[i];
var properties = getPropertiesOfObjectType(base);
for (var j = 0, proplen = properties.length; j < proplen; ++j) {
var prop = properties[j];
if (!hasProperty(seen, prop.name)) {
seen[prop.name] = { prop: prop, containingType: base };
}
else {
var existing = seen[prop.name];
var isInheritedProperty = existing.containingType !== type;
if (isInheritedProperty && !isPropertyIdenticalTo(existing.prop, prop)) {
ok = false;
var typeName1 = typeToString(existing.containingType);
var typeName2 = typeToString(base);
var errorInfo = chainDiagnosticMessages(undefined, Diagnostics.Named_properties_0_of_types_1_and_2_are_not_identical, prop.name, typeName1, typeName2);
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2, typeToString(type), typeName1, typeName2);
addDiagnostic(createDiagnosticForNodeFromMessageChain(typeNode, errorInfo, program.getCompilerHost().getNewLine()));
}
}
}
}
return ok;
}
function checkInterfaceDeclaration(node: InterfaceDeclaration) {
checkTypeParameters(node.typeParameters);
if (fullTypeCheck) {
+14
View File
@@ -1,6 +1,20 @@
/// <reference path="types.ts"/>
module ts {
// Ternary values are defined such that
// x & y is False if either x or y is False.
// x & y is Maybe if either x or y is Maybe, but neither x or y is False.
// x & y is True if both x and y are True.
// x | y is False if both x and y are False.
// x | y is Maybe if either x or y is Maybe, but neither x or y is True.
// x | y is True if either x or y is True.
export enum Ternary {
False = 0,
Maybe = 1,
True = -1
}
export interface Map<T> {
[index: string]: T;
}
@@ -26,13 +26,10 @@ tests/cases/compiler/arrayAssignmentTest1.ts(70,1): error TS2323: Type 'C3[]' is
Property 'C2M1' is missing in type 'C3'.
tests/cases/compiler/arrayAssignmentTest1.ts(75,1): error TS2323: Type 'C2[]' is not assignable to type 'C3[]'.
Type 'C2' is not assignable to type 'C3'.
Property 'CM3M1' is missing in type 'C2'.
tests/cases/compiler/arrayAssignmentTest1.ts(76,1): error TS2323: Type 'C1[]' is not assignable to type 'C3[]'.
Type 'C1' is not assignable to type 'C3'.
Property 'CM3M1' is missing in type 'C1'.
tests/cases/compiler/arrayAssignmentTest1.ts(77,1): error TS2323: Type 'I1[]' is not assignable to type 'C3[]'.
Type 'I1' is not assignable to type 'C3'.
Property 'CM3M1' is missing in type 'I1'.
tests/cases/compiler/arrayAssignmentTest1.ts(79,1): error TS2323: Type '() => C1' is not assignable to type 'any[]'.
Property 'push' is missing in type '() => C1'.
tests/cases/compiler/arrayAssignmentTest1.ts(80,1): error TS2323: Type '{ one: number; }' is not assignable to type 'any[]'.
@@ -162,17 +159,14 @@ tests/cases/compiler/arrayAssignmentTest1.ts(85,1): error TS2323: Type 'I1' is n
~~~~~~
!!! error TS2323: Type 'C2[]' is not assignable to type 'C3[]'.
!!! error TS2323: Type 'C2' is not assignable to type 'C3'.
!!! error TS2323: Property 'CM3M1' is missing in type 'C2'.
arr_c3 = arr_c1_2; // should be an error - is
~~~~~~
!!! error TS2323: Type 'C1[]' is not assignable to type 'C3[]'.
!!! error TS2323: Type 'C1' is not assignable to type 'C3'.
!!! error TS2323: Property 'CM3M1' is missing in type 'C1'.
arr_c3 = arr_i1_2; // should be an error - is
~~~~~~
!!! error TS2323: Type 'I1[]' is not assignable to type 'C3[]'.
!!! error TS2323: Type 'I1' is not assignable to type 'C3'.
!!! error TS2323: Property 'CM3M1' is missing in type 'I1'.
arr_any = f1; // should be an error - is
~~~~~~~
@@ -1,6 +1,5 @@
tests/cases/compiler/arrayCast.ts(3,1): 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; }'.
Property 'id' is missing in type '{ foo: string; }'.
==== tests/cases/compiler/arrayCast.ts (1 errors) ====
@@ -10,7 +9,6 @@ tests/cases/compiler/arrayCast.ts(3,1): error TS2352: Neither type '{ foo: strin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! 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: Property 'id' is missing in type '{ foo: string; }'.
// Should succeed, as the {} element causes the type of the array to be {}[]
<{ id: number; }[]>[{ foo: "s" }, {}];
@@ -8,10 +8,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(53,9): error TS2323: Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'.
Types of parameters 'y' and 'y' are incompatible.
Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'.
Types of parameters 'arg2' and 'arg2' are incompatible.
Type 'Base' is not assignable to type '{ foo: number; }'.
Types of property 'foo' are incompatible.
Type 'string' is not assignable to type 'number'.
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts (2 errors) ====
@@ -80,10 +76,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'.
!!! error TS2323: Types of parameters 'y' and 'y' are incompatible.
!!! error TS2323: Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'.
!!! error TS2323: Types of parameters 'arg2' and 'arg2' are incompatible.
!!! error TS2323: Type 'Base' is not assignable to type '{ foo: number; }'.
!!! error TS2323: Types of property 'foo' are incompatible.
!!! error TS2323: Type 'string' is not assignable to type 'number'.
var b10: <T extends Derived>(...x: T[]) => T;
@@ -8,10 +8,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(53,9): error TS2323: Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'.
Types of parameters 'y' and 'y' are incompatible.
Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'.
Types of parameters 'arg2' and 'arg2' are incompatible.
Type 'Base' is not assignable to type '{ foo: number; }'.
Types of property 'foo' are incompatible.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(77,9): error TS2323: Type 'new <T>(x: (a: T) => T) => T[]' is not assignable to type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean; }): boolean[]; }'.
Types of parameters 'x' and 'x' are incompatible.
Type '(a: any) => any' is not assignable to type '{ new (a: number): number; new (a?: number): number; }'.
@@ -92,10 +88,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'.
!!! error TS2323: Types of parameters 'y' and 'y' are incompatible.
!!! error TS2323: Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'.
!!! error TS2323: Types of parameters 'arg2' and 'arg2' are incompatible.
!!! error TS2323: Type 'Base' is not assignable to type '{ foo: number; }'.
!!! error TS2323: Types of property 'foo' are incompatible.
!!! error TS2323: Type 'string' is not assignable to type 'number'.
var b10: new <T extends Derived>(...x: T[]) => T;
@@ -12,14 +12,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(33,9): error TS2323: Type 'A<T>' is not assignable to type '{ [x: number]: Derived; }'.
Index signatures are incompatible.
Type 'T' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(36,9): error TS2323: Type '{ [x: number]: Derived2; }' is not assignable to type 'A<T>'.
Index signatures are incompatible.
Type 'Derived2' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(37,9): error TS2323: Type 'A<T>' is not assignable to type '{ [x: number]: Derived2; }'.
Index signatures are incompatible.
Type 'T' is not assignable to type 'Derived2'.
Property 'baz' is missing in type 'Base'.
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts (6 errors) ====
@@ -74,7 +72,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type 'A<T>' is not assignable to type '{ [x: number]: Derived; }'.
!!! error TS2323: Index signatures are incompatible.
!!! error TS2323: Type 'T' is not assignable to type 'Derived'.
!!! error TS2323: Property 'bar' is missing in type 'Base'.
var b2: { [x: number]: Derived2; }
a = b2; // error
@@ -87,7 +84,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type 'A<T>' is not assignable to type '{ [x: number]: Derived2; }'.
!!! error TS2323: Index signatures are incompatible.
!!! error TS2323: Type 'T' is not assignable to type 'Derived2'.
!!! error TS2323: Property 'baz' is missing in type 'Base'.
var b3: { [x: number]: T; }
a = b3; // ok
@@ -12,14 +12,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(33,9): error TS2323: Type 'A<T>' is not assignable to type '{ [x: number]: Derived; }'.
Index signatures are incompatible.
Type 'T' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(36,9): error TS2323: Type '{ [x: number]: Derived2; }' is not assignable to type 'A<T>'.
Index signatures are incompatible.
Type 'Derived2' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(37,9): error TS2323: Type 'A<T>' is not assignable to type '{ [x: number]: Derived2; }'.
Index signatures are incompatible.
Type 'T' is not assignable to type 'Derived2'.
Property 'baz' is missing in type 'Base'.
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts (6 errors) ====
@@ -74,7 +72,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type 'A<T>' is not assignable to type '{ [x: number]: Derived; }'.
!!! error TS2323: Index signatures are incompatible.
!!! error TS2323: Type 'T' is not assignable to type 'Derived'.
!!! error TS2323: Property 'bar' is missing in type 'Base'.
var b2: { [x: number]: Derived2; }
a = b2; // error
@@ -87,7 +84,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type 'A<T>' is not assignable to type '{ [x: number]: Derived2; }'.
!!! error TS2323: Index signatures are incompatible.
!!! error TS2323: Type 'T' is not assignable to type 'Derived2'.
!!! error TS2323: Property 'baz' is missing in type 'Base'.
var b3: { [x: number]: T; }
a = b3; // ok
@@ -9,47 +9,36 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(29,5): error TS2323: Type 'T2' is not assignable to type 'S2'.
Types of property 'foo' are incompatible.
Type 'Derived2' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Derived2'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(30,5): error TS2323: Type 'S2' is not assignable to type 'T2'.
Types of property 'foo' are incompatible.
Type 'Derived' is not assignable to type 'Derived2'.
Property 'baz' is missing in type 'Derived'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(31,5): error TS2323: Type 'T' is not assignable to type 'S2'.
Types of property 'foo' are incompatible.
Type 'Derived2' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Derived2'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(32,5): error TS2323: Type '{ foo: Derived2; }' is not assignable to type 'S2'.
Types of property 'foo' are incompatible.
Type 'Derived2' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Derived2'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(35,5): error TS2323: Type '{ foo: Derived2; }' is not assignable to type '{ foo: Derived; }'.
Types of property 'foo' are incompatible.
Type 'Derived2' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Derived2'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(36,5): error TS2323: Type '{ foo: Derived; }' is not assignable to type '{ foo: Derived2; }'.
Types of property 'foo' are incompatible.
Type 'Derived' is not assignable to type 'Derived2'.
Property 'baz' is missing in type 'Derived'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(41,5): error TS2323: Type '{ foo: Derived2; }' is not assignable to type '{ foo: Derived; }'.
Types of property 'foo' are incompatible.
Type 'Derived2' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Derived2'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(42,5): error TS2323: Type '{ foo: Derived; }' is not assignable to type '{ foo: Derived2; }'.
Types of property 'foo' are incompatible.
Type 'Derived' is not assignable to type 'Derived2'.
Property 'baz' is missing in type 'Derived'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(43,5): error TS2323: Type '{ foo: Derived2; }' is not assignable to type '{ foo: Derived; }'.
Types of property 'foo' are incompatible.
Type 'Derived2' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Derived2'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(44,5): error TS2323: Type 'T2' is not assignable to type '{ foo: Derived; }'.
Types of property 'foo' are incompatible.
Type 'Derived2' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Derived2'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(45,5): error TS2323: Type 'T' is not assignable to type '{ foo: Derived; }'.
Types of property 'foo' are incompatible.
Type 'Derived2' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Derived2'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(70,5): error TS2323: Type 'S' is not assignable to type 'T'.
Types of property 'foo' are incompatible.
Type 'Base' is not assignable to type 'Derived2'.
@@ -57,15 +46,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(75,5): error TS2323: Type 'S2' is not assignable to type 'T2'.
Types of property 'foo' are incompatible.
Type 'Base' is not assignable to type 'Derived2'.
Property 'baz' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(81,5): error TS2323: Type '{ foo: Base; }' is not assignable to type '{ foo: Derived2; }'.
Types of property 'foo' are incompatible.
Type 'Base' is not assignable to type 'Derived2'.
Property 'baz' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts(87,5): error TS2323: Type '{ foo: Base; }' is not assignable to type '{ foo: Derived2; }'.
Types of property 'foo' are incompatible.
Type 'Base' is not assignable to type 'Derived2'.
Property 'baz' is missing in type 'Base'.
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithObjectMembers4.ts (17 errors) ====
@@ -112,25 +98,21 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type 'T2' is not assignable to type 'S2'.
!!! error TS2323: Types of property 'foo' are incompatible.
!!! error TS2323: Type 'Derived2' is not assignable to type 'Derived'.
!!! error TS2323: Property 'bar' is missing in type 'Derived2'.
t2 = s2; // error
~~
!!! error TS2323: Type 'S2' is not assignable to type 'T2'.
!!! error TS2323: Types of property 'foo' are incompatible.
!!! error TS2323: Type 'Derived' is not assignable to type 'Derived2'.
!!! error TS2323: Property 'baz' is missing in type 'Derived'.
s2 = t; // error
~~
!!! error TS2323: Type 'T' is not assignable to type 'S2'.
!!! error TS2323: Types of property 'foo' are incompatible.
!!! error TS2323: Type 'Derived2' is not assignable to type 'Derived'.
!!! error TS2323: Property 'bar' is missing in type 'Derived2'.
s2 = b; // error
~~
!!! error TS2323: Type '{ foo: Derived2; }' is not assignable to type 'S2'.
!!! error TS2323: Types of property 'foo' are incompatible.
!!! error TS2323: Type 'Derived2' is not assignable to type 'Derived'.
!!! error TS2323: Property 'bar' is missing in type 'Derived2'.
s2 = a2; // ok
a = b; // error
@@ -138,13 +120,11 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type '{ foo: Derived2; }' is not assignable to type '{ foo: Derived; }'.
!!! error TS2323: Types of property 'foo' are incompatible.
!!! error TS2323: Type 'Derived2' is not assignable to type 'Derived'.
!!! error TS2323: Property 'bar' is missing in type 'Derived2'.
b = a; // error
~
!!! error TS2323: Type '{ foo: Derived; }' is not assignable to type '{ foo: Derived2; }'.
!!! error TS2323: Types of property 'foo' are incompatible.
!!! error TS2323: Type 'Derived' is not assignable to type 'Derived2'.
!!! error TS2323: Property 'baz' is missing in type 'Derived'.
a = s; // ok
a = s2; // ok
a = a2; // ok
@@ -154,31 +134,26 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type '{ foo: Derived2; }' is not assignable to type '{ foo: Derived; }'.
!!! error TS2323: Types of property 'foo' are incompatible.
!!! error TS2323: Type 'Derived2' is not assignable to type 'Derived'.
!!! error TS2323: Property 'bar' is missing in type 'Derived2'.
b2 = a2; // error
~~
!!! error TS2323: Type '{ foo: Derived; }' is not assignable to type '{ foo: Derived2; }'.
!!! error TS2323: Types of property 'foo' are incompatible.
!!! error TS2323: Type 'Derived' is not assignable to type 'Derived2'.
!!! error TS2323: Property 'baz' is missing in type 'Derived'.
a2 = b; // error
~~
!!! error TS2323: Type '{ foo: Derived2; }' is not assignable to type '{ foo: Derived; }'.
!!! error TS2323: Types of property 'foo' are incompatible.
!!! error TS2323: Type 'Derived2' is not assignable to type 'Derived'.
!!! error TS2323: Property 'bar' is missing in type 'Derived2'.
a2 = t2; // error
~~
!!! error TS2323: Type 'T2' is not assignable to type '{ foo: Derived; }'.
!!! error TS2323: Types of property 'foo' are incompatible.
!!! error TS2323: Type 'Derived2' is not assignable to type 'Derived'.
!!! error TS2323: Property 'bar' is missing in type 'Derived2'.
a2 = t; // error
~~
!!! error TS2323: Type 'T' is not assignable to type '{ foo: Derived; }'.
!!! error TS2323: Types of property 'foo' are incompatible.
!!! error TS2323: Type 'Derived2' is not assignable to type 'Derived'.
!!! error TS2323: Property 'bar' is missing in type 'Derived2'.
}
module WithBase {
@@ -218,7 +193,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type 'S2' is not assignable to type 'T2'.
!!! error TS2323: Types of property 'foo' are incompatible.
!!! error TS2323: Type 'Base' is not assignable to type 'Derived2'.
!!! error TS2323: Property 'baz' is missing in type 'Base'.
s2 = t; // ok
s2 = b; // ok
s2 = a2; // ok
@@ -229,7 +203,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type '{ foo: Base; }' is not assignable to type '{ foo: Derived2; }'.
!!! error TS2323: Types of property 'foo' are incompatible.
!!! error TS2323: Type 'Base' is not assignable to type 'Derived2'.
!!! error TS2323: Property 'baz' is missing in type 'Base'.
a = s; // ok
a = s2; // ok
a = a2; // ok
@@ -240,7 +213,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type '{ foo: Base; }' is not assignable to type '{ foo: Derived2; }'.
!!! error TS2323: Types of property 'foo' are incompatible.
!!! error TS2323: Type 'Base' is not assignable to type 'Derived2'.
!!! error TS2323: Property 'baz' is missing in type 'Base'.
a2 = b; // ok
a2 = t2; // ok
a2 = t; // ok
@@ -9,25 +9,21 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(33,5): error TS2323: Type 'A<Base>' is not assignable to type '{ [x: string]: Derived; }'.
Index signatures are incompatible.
Type 'Base' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(41,5): error TS2323: Type 'A<Base>' is not assignable to type '{ [x: string]: Derived2; }'.
Index signatures are incompatible.
Type 'Base' is not assignable to type 'Derived2'.
Property 'baz' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(46,9): error TS2323: Type '{ [x: string]: Derived; }' is not assignable to type 'A<T>'.
Index signatures are incompatible.
Type 'Derived' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(47,9): error TS2323: Type 'A<T>' is not assignable to type '{ [x: string]: Derived; }'.
Index signatures are incompatible.
Type 'T' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(50,9): error TS2323: Type '{ [x: string]: Derived2; }' is not assignable to type 'A<T>'.
Index signatures are incompatible.
Type 'Derived2' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(51,9): error TS2323: Type 'A<T>' is not assignable to type '{ [x: string]: Derived2; }'.
Index signatures are incompatible.
Type 'T' is not assignable to type 'Derived2'.
Property 'baz' is missing in type 'Base'.
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts (8 errors) ====
@@ -78,7 +74,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type 'A<Base>' is not assignable to type '{ [x: string]: Derived; }'.
!!! error TS2323: Index signatures are incompatible.
!!! error TS2323: Type 'Base' is not assignable to type 'Derived'.
!!! error TS2323: Property 'bar' is missing in type 'Base'.
class B2 extends A<Base> {
[x: string]: Derived2; // ok
@@ -91,7 +86,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type 'A<Base>' is not assignable to type '{ [x: string]: Derived2; }'.
!!! error TS2323: Index signatures are incompatible.
!!! error TS2323: Type 'Base' is not assignable to type 'Derived2'.
!!! error TS2323: Property 'baz' is missing in type 'Base'.
function foo<T extends Base>() {
var b3: { [x: string]: Derived; };
@@ -106,7 +100,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type 'A<T>' is not assignable to type '{ [x: string]: Derived; }'.
!!! error TS2323: Index signatures are incompatible.
!!! error TS2323: Type 'T' is not assignable to type 'Derived'.
!!! error TS2323: Property 'bar' is missing in type 'Base'.
var b4: { [x: string]: Derived2; };
a3 = b4; // error
@@ -119,6 +112,5 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type 'A<T>' is not assignable to type '{ [x: string]: Derived2; }'.
!!! error TS2323: Index signatures are incompatible.
!!! error TS2323: Type 'T' is not assignable to type 'Derived2'.
!!! error TS2323: Property 'baz' is missing in type 'Base'.
}
}
@@ -9,25 +9,21 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(33,5): error TS2323: Type 'A<Base>' is not assignable to type '{ [x: string]: Derived; }'.
Index signatures are incompatible.
Type 'Base' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(41,5): error TS2323: Type 'A<Base>' is not assignable to type '{ [x: string]: Derived2; }'.
Index signatures are incompatible.
Type 'Base' is not assignable to type 'Derived2'.
Property 'baz' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(46,9): error TS2323: Type '{ [x: string]: Derived; }' is not assignable to type 'A<T>'.
Index signatures are incompatible.
Type 'Derived' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(47,9): error TS2323: Type 'A<T>' is not assignable to type '{ [x: string]: Derived; }'.
Index signatures are incompatible.
Type 'T' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(50,9): error TS2323: Type '{ [x: string]: Derived2; }' is not assignable to type 'A<T>'.
Index signatures are incompatible.
Type 'Derived2' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(51,9): error TS2323: Type 'A<T>' is not assignable to type '{ [x: string]: Derived2; }'.
Index signatures are incompatible.
Type 'T' is not assignable to type 'Derived2'.
Property 'baz' is missing in type 'Base'.
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts (8 errors) ====
@@ -78,7 +74,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type 'A<Base>' is not assignable to type '{ [x: string]: Derived; }'.
!!! error TS2323: Index signatures are incompatible.
!!! error TS2323: Type 'Base' is not assignable to type 'Derived'.
!!! error TS2323: Property 'bar' is missing in type 'Base'.
interface B2 extends A<Base> {
[x: string]: Derived2; // ok
@@ -91,7 +86,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type 'A<Base>' is not assignable to type '{ [x: string]: Derived2; }'.
!!! error TS2323: Index signatures are incompatible.
!!! error TS2323: Type 'Base' is not assignable to type 'Derived2'.
!!! error TS2323: Property 'baz' is missing in type 'Base'.
function foo<T extends Base>() {
var b3: { [x: string]: Derived; };
@@ -106,7 +100,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type 'A<T>' is not assignable to type '{ [x: string]: Derived; }'.
!!! error TS2323: Index signatures are incompatible.
!!! error TS2323: Type 'T' is not assignable to type 'Derived'.
!!! error TS2323: Property 'bar' is missing in type 'Base'.
var b4: { [x: string]: Derived2; };
a3 = b4; // error
@@ -119,6 +112,5 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
!!! error TS2323: Type 'A<T>' is not assignable to type '{ [x: string]: Derived2; }'.
!!! error TS2323: Index signatures are incompatible.
!!! error TS2323: Type 'T' is not assignable to type 'Derived2'.
!!! error TS2323: Property 'baz' is missing in type 'Base'.
}
}
@@ -8,7 +8,6 @@ tests/cases/conformance/types/tuple/castingTuple.ts(24,10): error TS2352: Neithe
tests/cases/conformance/types/tuple/castingTuple.ts(25,10): error TS2352: Neither type '[C, D]' nor type '[A, I]' is assignable to the other.
Types of property '0' are incompatible.
Type 'C' is not assignable to type 'A'.
Property 'a' is missing in type 'C'.
tests/cases/conformance/types/tuple/castingTuple.ts(26,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(26,14): error TS2352: Neither type '[number, string]' nor type 'number[]' is assignable to the other.
Types of property 'pop' are incompatible.
@@ -58,7 +57,6 @@ tests/cases/conformance/types/tuple/castingTuple.ts(27,1): error TS2304: Cannot
!!! 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'.
var array1 = <number[]>numStrTuple;
~~~~~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'.
@@ -0,0 +1,25 @@
//// [checkInfiniteExpansionTermination.ts]
// Regression test for #1002
// Before fix this code would cause infinite loop
interface IObservable<T> {
n: IObservable<T[]>; // Needed, must be T[]
}
// Needed
interface ISubject<T> extends IObservable<T> { }
interface Foo { x }
interface Bar { y }
var values: IObservable<Foo>;
var values2: ISubject<Bar>;
values = values2;
//// [checkInfiniteExpansionTermination.js]
// Regression test for #1002
// Before fix this code would cause infinite loop
var values;
var values2;
values = values2;
@@ -0,0 +1,44 @@
=== tests/cases/compiler/checkInfiniteExpansionTermination.ts ===
// Regression test for #1002
// Before fix this code would cause infinite loop
interface IObservable<T> {
>IObservable : IObservable<T>
>T : T
n: IObservable<T[]>; // Needed, must be T[]
>n : IObservable<T[]>
>IObservable : IObservable<T>
>T : T
}
// Needed
interface ISubject<T> extends IObservable<T> { }
>ISubject : ISubject<T>
>T : T
>IObservable : IObservable<T>
>T : T
interface Foo { x }
>Foo : Foo
>x : any
interface Bar { y }
>Bar : Bar
>y : any
var values: IObservable<Foo>;
>values : IObservable<Foo>
>IObservable : IObservable<T>
>Foo : Foo
var values2: ISubject<Bar>;
>values2 : ISubject<Bar>
>ISubject : ISubject<T>
>Bar : Bar
values = values2;
>values = values2 : ISubject<Bar>
>values : IObservable<Foo>
>values2 : ISubject<Bar>
@@ -0,0 +1,27 @@
//// [checkInfiniteExpansionTermination2.ts]
// Regression test for #1002
// Before fix this code would cause infinite loop
interface IObservable<T> {
n: IObservable<T[]>;
}
interface ISubject<T> extends IObservable<T> { }
declare function combineLatest<TOther>(x: IObservable<TOther>[]): void;
declare function combineLatest(): void;
function fn<T>() {
var values: ISubject<any>[] = [];
// Hang when using <T>, but not <any>
combineLatest<T>(values);
}
//// [checkInfiniteExpansionTermination2.js]
// Regression test for #1002
// Before fix this code would cause infinite loop
function fn() {
var values = [];
// Hang when using <T>, but not <any>
combineLatest(values);
}
@@ -0,0 +1,46 @@
=== tests/cases/compiler/checkInfiniteExpansionTermination2.ts ===
// Regression test for #1002
// Before fix this code would cause infinite loop
interface IObservable<T> {
>IObservable : IObservable<T>
>T : T
n: IObservable<T[]>;
>n : IObservable<T[]>
>IObservable : IObservable<T>
>T : T
}
interface ISubject<T> extends IObservable<T> { }
>ISubject : ISubject<T>
>T : T
>IObservable : IObservable<T>
>T : T
declare function combineLatest<TOther>(x: IObservable<TOther>[]): void;
>combineLatest : { <TOther>(x: IObservable<TOther>[]): void; (): void; }
>TOther : TOther
>x : IObservable<TOther>[]
>IObservable : IObservable<T>
>TOther : TOther
declare function combineLatest(): void;
>combineLatest : { <TOther>(x: IObservable<TOther>[]): void; (): void; }
function fn<T>() {
>fn : <T>() => void
>T : T
var values: ISubject<any>[] = [];
>values : ISubject<any>[]
>ISubject : ISubject<T>
>[] : undefined[]
// Hang when using <T>, but not <any>
combineLatest<T>(values);
>combineLatest<T>(values) : void
>combineLatest : { <TOther>(x: IObservable<TOther>[]): void; (): void; }
>T : T
>values : ISubject<any>[]
}
@@ -29,7 +29,6 @@ tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAnd
Type 'A' is not assignable to type 'A'.
Property 'name' is missing in type 'A'.
tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAndInvalidInitializer.ts(51,5): error TS2323: Type 'A' is not assignable to type 'A'.
Property 'name' is missing in type 'A'.
tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAndInvalidInitializer.ts(52,5): error TS2323: Type '(x: number) => boolean' is not assignable to type '(x: number) => string'.
Type 'boolean' is not assignable to type 'string'.
@@ -131,7 +130,6 @@ tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAnd
var aClassInModule: M.A = new N.A();
~~~~~~~~~~~~~~
!!! error TS2323: Type 'A' is not assignable to type 'A'.
!!! error TS2323: Property 'name' is missing in type 'A'.
var aFunctionInModule: typeof M.F2 = F2;
~~~~~~~~~~~~~~~~~
!!! error TS2323: Type '(x: number) => boolean' is not assignable to type '(x: number) => string'.
@@ -8,24 +8,12 @@ tests/cases/compiler/genericAssignmentCompatWithInterfaces1.ts(12,5): error TS23
tests/cases/compiler/genericAssignmentCompatWithInterfaces1.ts(13,5): error TS2323: Type '{ x: A<number>; }' is not assignable to type 'I<string>'.
Types of property 'x' are incompatible.
Type 'A<number>' is not assignable to type 'Comparable<string>'.
Types of property 'compareTo' are incompatible.
Type '(other: number) => number' is not assignable to type '(other: string) => number'.
Types of parameters 'other' and 'other' are incompatible.
Type 'number' is not assignable to type 'string'.
tests/cases/compiler/genericAssignmentCompatWithInterfaces1.ts(16,5): error TS2323: Type '{ x: A<number>; }' is not assignable to type 'I<string>'.
Types of property 'x' are incompatible.
Type 'A<number>' is not assignable to type 'Comparable<string>'.
Types of property 'compareTo' are incompatible.
Type '(other: number) => number' is not assignable to type '(other: string) => number'.
Types of parameters 'other' and 'other' are incompatible.
Type 'number' is not assignable to type 'string'.
tests/cases/compiler/genericAssignmentCompatWithInterfaces1.ts(17,5): error TS2323: Type 'K<number>' is not assignable to type 'I<string>'.
Types of property 'x' are incompatible.
Type 'A<number>' is not assignable to type 'Comparable<string>'.
Types of property 'compareTo' are incompatible.
Type '(other: number) => number' is not assignable to type '(other: string) => number'.
Types of parameters 'other' and 'other' are incompatible.
Type 'number' is not assignable to type 'string'.
==== tests/cases/compiler/genericAssignmentCompatWithInterfaces1.ts (4 errors) ====
@@ -54,10 +42,6 @@ tests/cases/compiler/genericAssignmentCompatWithInterfaces1.ts(17,5): error TS23
!!! error TS2323: Type '{ x: A<number>; }' is not assignable to type 'I<string>'.
!!! error TS2323: Types of property 'x' are incompatible.
!!! error TS2323: Type 'A<number>' is not assignable to type 'Comparable<string>'.
!!! error TS2323: Types of property 'compareTo' are incompatible.
!!! error TS2323: Type '(other: number) => number' is not assignable to type '(other: string) => number'.
!!! error TS2323: Types of parameters 'other' and 'other' are incompatible.
!!! error TS2323: Type 'number' is not assignable to type 'string'.
var z = { x: new A<number>() }; return z;
} ();
var a3: I<string> = z;
@@ -65,18 +49,10 @@ tests/cases/compiler/genericAssignmentCompatWithInterfaces1.ts(17,5): error TS23
!!! error TS2323: Type '{ x: A<number>; }' is not assignable to type 'I<string>'.
!!! error TS2323: Types of property 'x' are incompatible.
!!! error TS2323: Type 'A<number>' is not assignable to type 'Comparable<string>'.
!!! error TS2323: Types of property 'compareTo' are incompatible.
!!! error TS2323: Type '(other: number) => number' is not assignable to type '(other: string) => number'.
!!! error TS2323: Types of parameters 'other' and 'other' are incompatible.
!!! error TS2323: Type 'number' is not assignable to type 'string'.
var a4: I<string> = <K<number>>z;
~~
!!! error TS2323: Type 'K<number>' is not assignable to type 'I<string>'.
!!! error TS2323: Types of property 'x' are incompatible.
!!! error TS2323: Type 'A<number>' is not assignable to type 'Comparable<string>'.
!!! error TS2323: Types of property 'compareTo' are incompatible.
!!! error TS2323: Type '(other: number) => number' is not assignable to type '(other: string) => number'.
!!! error TS2323: Types of parameters 'other' and 'other' are incompatible.
!!! error TS2323: Type 'number' is not assignable to type 'string'.
@@ -4,7 +4,6 @@ tests/cases/compiler/genericTypeAssertions1.ts(4,5): error TS2323: Type 'A<A<num
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>'.
Property 'foo' is missing in type 'Number'.
==== tests/cases/compiler/genericTypeAssertions1.ts (3 errors) ====
@@ -20,5 +19,4 @@ tests/cases/compiler/genericTypeAssertions1.ts(4,21): error TS2352: Neither type
!!! error TS2323: 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: Property 'foo' is missing in type 'Number'.
!!! error TS2352: Type 'number' is not assignable to type 'A<number>'.
@@ -1,7 +1,6 @@
tests/cases/compiler/interfaceAssignmentCompat.ts(32,18): error TS2345: Argument of type '(a: IFrenchEye, b: IFrenchEye) => number' is not assignable to parameter of type '(a: IEye, b: IEye) => number'.
tests/cases/compiler/interfaceAssignmentCompat.ts(37,29): error TS2339: Property '_map' does not exist on type 'typeof Color'.
tests/cases/compiler/interfaceAssignmentCompat.ts(42,13): error TS2323: Type 'IEye' is not assignable to type 'IFrenchEye'.
Property 'coleur' is missing in type 'IEye'.
tests/cases/compiler/interfaceAssignmentCompat.ts(44,9): error TS2323: Type 'IEye[]' is not assignable to type 'IFrenchEye[]'.
Type 'IEye' is not assignable to type 'IFrenchEye'.
@@ -55,7 +54,6 @@ tests/cases/compiler/interfaceAssignmentCompat.ts(44,9): error TS2323: Type 'IEy
eeks[j]=z[j]; // nope: element assignment
~~~~~~~
!!! error TS2323: Type 'IEye' is not assignable to type 'IFrenchEye'.
!!! error TS2323: Property 'coleur' is missing in type 'IEye'.
}
eeks=z; // nope: array assignment
~~~~
@@ -3,8 +3,6 @@ tests/cases/compiler/lastPropertyInLiteralWins.ts(9,5): error TS2300: Duplicate
tests/cases/compiler/lastPropertyInLiteralWins.ts(12,6): error TS2345: Argument of type '{ thunk: (num: number) => void; }' is not assignable to parameter of type 'Thing'.
Types of property 'thunk' are incompatible.
Type '(num: number) => void' is not assignable to type '(str: string) => void'.
Types of parameters 'num' and 'str' are incompatible.
Type 'number' is not assignable to type 'string'.
tests/cases/compiler/lastPropertyInLiteralWins.ts(13,5): error TS2300: Duplicate identifier 'thunk'.
tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS2300: Duplicate identifier 'thunk'.
@@ -40,6 +38,4 @@ tests/cases/compiler/lastPropertyInLiteralWins.ts(14,5): error TS2300: Duplicate
!!! error TS2345: Argument of type '{ thunk: (num: number) => void; }' is not assignable to parameter of type 'Thing'.
!!! error TS2345: Types of property 'thunk' are incompatible.
!!! error TS2345: Type '(num: number) => void' is not assignable to type '(str: string) => void'.
!!! error TS2345: Types of parameters 'num' and 'str' are incompatible.
!!! error TS2345: Type 'number' is not assignable to type 'string'.
@@ -1,7 +1,6 @@
tests/cases/compiler/objectLiteralIndexerErrors.ts(13,5): error TS2323: Type '{ [x: string]: A; [x: number]: A; 0: A; x: B; }' is not assignable to type '{ [x: string]: A; [x: number]: B; }'.
Index signatures are incompatible.
Type 'A' is not assignable to type 'B'.
Property 'y' is missing in type 'A'.
==== tests/cases/compiler/objectLiteralIndexerErrors.ts (1 errors) ====
@@ -22,5 +21,4 @@ tests/cases/compiler/objectLiteralIndexerErrors.ts(13,5): error TS2323: Type '{
!!! error TS2323: Type '{ [x: string]: A; [x: number]: A; 0: A; x: B; }' is not assignable to type '{ [x: string]: A; [x: number]: B; }'.
!!! error TS2323: Index signatures are incompatible.
!!! error TS2323: Type 'A' is not assignable to type 'B'.
!!! error TS2323: Property 'y' is missing in type 'A'.
o1 = { x: c, 0: a }; // string indexer is any, number indexer is A
@@ -3,7 +3,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
Type 'Base' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer2.ts(24,25): error TS2344: Type 'Base' does not satisfy the constraint 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer2.ts(32,15): error TS2430: Interface 'B3<T>' incorrectly extends interface 'A<T>'.
Index signatures are incompatible.
Type 'Base' is not assignable to type 'T'.
@@ -47,7 +46,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
interface B extends A<Base> {
~~~~~~~
!!! error TS2344: Type 'Base' does not satisfy the constraint 'Derived'.
!!! error TS2344: Property 'bar' is missing in type 'Base'.
[x: number]: Derived; // error
}
@@ -3,7 +3,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
Type 'Base' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3.ts(24,21): error TS2344: Type 'Base' does not satisfy the constraint 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3.ts(32,11): error TS2415: Class 'B3<T>' incorrectly extends base class 'A<T>'.
Index signatures are incompatible.
Type 'Base' is not assignable to type 'T'.
@@ -47,7 +46,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
class B extends A<Base> {
~~~~~~~
!!! error TS2344: Type 'Base' does not satisfy the constraint 'Derived'.
!!! error TS2344: Property 'bar' is missing in type 'Base'.
[x: number]: Derived; // error
}
@@ -5,23 +5,18 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(22,7): error TS2415: Class 'B2' incorrectly extends base class 'A2'.
Types of property '2.0' are incompatible.
Type 'string' is not assignable to type 'Base'.
Property 'foo' is missing in type 'String'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(32,7): error TS2415: Class 'B3' incorrectly extends base class 'A3'.
Types of property ''2.0'' are incompatible.
Type 'string' is not assignable to type 'Base'.
Property 'foo' is missing in type 'String'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(43,11): error TS2415: Class 'B' incorrectly extends base class 'A'.
Types of property 'bar' are incompatible.
Type 'string' is not assignable to type 'Base'.
Property 'foo' is missing in type 'String'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(53,11): error TS2415: Class 'B2' incorrectly extends base class 'A2'.
Types of property '2.0' are incompatible.
Type 'string' is not assignable to type 'Base'.
Property 'foo' is missing in type 'String'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(63,11): error TS2415: Class 'B3' incorrectly extends base class 'A3'.
Types of property ''2.0'' are incompatible.
Type 'string' is not assignable to type 'Base'.
Property 'foo' is missing in type 'String'.
==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts (6 errors) ====
@@ -56,7 +51,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
!!! error TS2415: Class 'B2' incorrectly extends base class 'A2'.
!!! error TS2415: Types of property '2.0' are incompatible.
!!! error TS2415: Type 'string' is not assignable to type 'Base'.
!!! error TS2415: Property 'foo' is missing in type 'String'.
1: Derived; // ok
2: string; // error
}
@@ -71,7 +65,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
!!! error TS2415: Class 'B3' incorrectly extends base class 'A3'.
!!! error TS2415: Types of property ''2.0'' are incompatible.
!!! error TS2415: Type 'string' is not assignable to type 'Base'.
!!! error TS2415: Property 'foo' is missing in type 'String'.
'1': Derived; // ok
'2.0': string; // error
}
@@ -87,7 +80,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
!!! error TS2415: Class 'B' incorrectly extends base class 'A'.
!!! error TS2415: Types of property 'bar' are incompatible.
!!! error TS2415: Type 'string' is not assignable to type 'Base'.
!!! error TS2415: Property 'foo' is missing in type 'String'.
foo: Derived2; // ok
bar: string; // error
}
@@ -102,7 +94,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
!!! error TS2415: Class 'B2' incorrectly extends base class 'A2'.
!!! error TS2415: Types of property '2.0' are incompatible.
!!! error TS2415: Type 'string' is not assignable to type 'Base'.
!!! error TS2415: Property 'foo' is missing in type 'String'.
1: Derived2; // ok
2: string; // error
}
@@ -117,7 +108,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
!!! error TS2415: Class 'B3' incorrectly extends base class 'A3'.
!!! error TS2415: Types of property ''2.0'' are incompatible.
!!! error TS2415: Type 'string' is not assignable to type 'Base'.
!!! error TS2415: Property 'foo' is missing in type 'String'.
'1': Derived2; // ok
'2.0': string; // error
}
@@ -5,23 +5,18 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2.ts(27,15): error TS2430: Interface 'B2' incorrectly extends interface 'A2'.
Types of property '2.0' are incompatible.
Type 'string' is not assignable to type 'Base'.
Property 'foo' is missing in type 'String'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2.ts(37,15): error TS2430: Interface 'B3' incorrectly extends interface 'A3'.
Types of property ''2.0'' are incompatible.
Type 'string' is not assignable to type 'Base'.
Property 'foo' is missing in type 'String'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2.ts(50,15): error TS2430: Interface 'B' incorrectly extends interface 'A'.
Types of property 'bar' are incompatible.
Type 'string' is not assignable to type 'Base'.
Property 'foo' is missing in type 'String'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2.ts(60,15): error TS2430: Interface 'B2' incorrectly extends interface 'A2'.
Types of property '2.0' are incompatible.
Type 'string' is not assignable to type 'Base'.
Property 'foo' is missing in type 'String'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2.ts(70,15): error TS2430: Interface 'B3' incorrectly extends interface 'A3'.
Types of property ''2.0'' are incompatible.
Type 'string' is not assignable to type 'Base'.
Property 'foo' is missing in type 'String'.
==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2.ts (6 errors) ====
@@ -61,7 +56,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
!!! error TS2430: Interface 'B2' incorrectly extends interface 'A2'.
!!! error TS2430: Types of property '2.0' are incompatible.
!!! error TS2430: Type 'string' is not assignable to type 'Base'.
!!! error TS2430: Property 'foo' is missing in type 'String'.
1: Derived; // ok
2: string; // error
}
@@ -76,7 +70,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
!!! error TS2430: Interface 'B3' incorrectly extends interface 'A3'.
!!! error TS2430: Types of property ''2.0'' are incompatible.
!!! error TS2430: Type 'string' is not assignable to type 'Base'.
!!! error TS2430: Property 'foo' is missing in type 'String'.
'1': Derived; // ok
'2.0': string; // error
}
@@ -94,7 +87,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
!!! error TS2430: Interface 'B' incorrectly extends interface 'A'.
!!! error TS2430: Types of property 'bar' are incompatible.
!!! error TS2430: Type 'string' is not assignable to type 'Base'.
!!! error TS2430: Property 'foo' is missing in type 'String'.
foo?: Derived; // ok
bar?: string; // error
}
@@ -109,7 +101,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
!!! error TS2430: Interface 'B2' incorrectly extends interface 'A2'.
!!! error TS2430: Types of property '2.0' are incompatible.
!!! error TS2430: Type 'string' is not assignable to type 'Base'.
!!! error TS2430: Property 'foo' is missing in type 'String'.
1?: Derived; // ok
2?: string; // error
}
@@ -124,7 +115,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
!!! error TS2430: Interface 'B3' incorrectly extends interface 'A3'.
!!! error TS2430: Types of property ''2.0'' are incompatible.
!!! error TS2430: Type 'string' is not assignable to type 'Base'.
!!! error TS2430: Property 'foo' is missing in type 'String'.
'1'?: Derived; // ok
'2.0'?: string; // error
}
@@ -5,23 +5,18 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3.ts(27,15): error TS2430: Interface 'B2' incorrectly extends interface 'A2'.
Types of property '2.0' are incompatible.
Type 'Base' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3.ts(37,15): error TS2430: Interface 'B3' incorrectly extends interface 'A3'.
Types of property ''2.0'' are incompatible.
Type 'Base' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3.ts(49,15): error TS2430: Interface 'B' incorrectly extends interface 'A'.
Types of property 'bar' are incompatible.
Type 'Base' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3.ts(59,15): error TS2430: Interface 'B2' incorrectly extends interface 'A2'.
Types of property '2.0' are incompatible.
Type 'Base' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3.ts(69,15): error TS2430: Interface 'B3' incorrectly extends interface 'A3'.
Types of property ''2.0'' are incompatible.
Type 'Base' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Base'.
==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3.ts (6 errors) ====
@@ -61,7 +56,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
!!! error TS2430: Interface 'B2' incorrectly extends interface 'A2'.
!!! error TS2430: Types of property '2.0' are incompatible.
!!! error TS2430: Type 'Base' is not assignable to type 'Derived'.
!!! error TS2430: Property 'bar' is missing in type 'Base'.
1: Derived; // ok
2: Base; // error
}
@@ -76,7 +70,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
!!! error TS2430: Interface 'B3' incorrectly extends interface 'A3'.
!!! error TS2430: Types of property ''2.0'' are incompatible.
!!! error TS2430: Type 'Base' is not assignable to type 'Derived'.
!!! error TS2430: Property 'bar' is missing in type 'Base'.
'1': Derived; // ok
'2.0': Base; // error
}
@@ -93,7 +86,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
!!! error TS2430: Interface 'B' incorrectly extends interface 'A'.
!!! error TS2430: Types of property 'bar' are incompatible.
!!! error TS2430: Type 'Base' is not assignable to type 'Derived'.
!!! error TS2430: Property 'bar' is missing in type 'Base'.
foo?: Derived; // ok
bar?: Base; // error
}
@@ -108,7 +100,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
!!! error TS2430: Interface 'B2' incorrectly extends interface 'A2'.
!!! error TS2430: Types of property '2.0' are incompatible.
!!! error TS2430: Type 'Base' is not assignable to type 'Derived'.
!!! error TS2430: Property 'bar' is missing in type 'Base'.
1?: Derived; // ok
2?: Base; // error
}
@@ -123,7 +114,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
!!! error TS2430: Interface 'B3' incorrectly extends interface 'A3'.
!!! error TS2430: Types of property ''2.0'' are incompatible.
!!! error TS2430: Type 'Base' is not assignable to type 'Derived'.
!!! error TS2430: Property 'bar' is missing in type 'Base'.
'1'?: Derived; // ok
'2.0'?: Base; // error
}
@@ -3,7 +3,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
Type 'Base' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer2.ts(24,25): error TS2344: Type 'Base' does not satisfy the constraint 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer2.ts(32,15): error TS2430: Interface 'B3<T>' incorrectly extends interface 'A<T>'.
Index signatures are incompatible.
Type 'Base' is not assignable to type 'T'.
@@ -47,7 +46,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
interface B extends A<Base> {
~~~~~~~
!!! error TS2344: Type 'Base' does not satisfy the constraint 'Derived'.
!!! error TS2344: Property 'bar' is missing in type 'Base'.
[x: string]: Derived; // error
}
@@ -3,7 +3,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
Type 'Base' is not assignable to type 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3.ts(24,21): error TS2344: Type 'Base' does not satisfy the constraint 'Derived'.
Property 'bar' is missing in type 'Base'.
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3.ts(32,11): error TS2415: Class 'B3<T>' incorrectly extends base class 'A<T>'.
Index signatures are incompatible.
Type 'Base' is not assignable to type 'T'.
@@ -47,7 +46,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
class B extends A<Base> {
~~~~~~~
!!! error TS2344: Type 'Base' does not satisfy the constraint 'Derived'.
!!! error TS2344: Property 'bar' is missing in type 'Base'.
[x: string]: Derived; // error
}
@@ -0,0 +1,45 @@
tests/cases/compiler/typeComparisonCaching.ts(26,1): error TS2323: Type 'B' is not assignable to type 'A'.
Types of property 's' are incompatible.
Type 'number' is not assignable to type 'string'.
tests/cases/compiler/typeComparisonCaching.ts(27,1): error TS2323: Type 'D' is not assignable to type 'C'.
Types of property 'q' are incompatible.
Type 'B' is not assignable to type 'A'.
==== tests/cases/compiler/typeComparisonCaching.ts (2 errors) ====
// Check that we only cache results of type comparisons that are free of assumptions
interface A {
p: C;
s: string;
}
interface B {
p: D;
s: number;
}
interface C {
q: A;
}
interface D {
q: B;
}
var a: A;
var b: B;
var c: C;
var d: D;
a = b;
~
!!! error TS2323: Type 'B' is not assignable to type 'A'.
!!! error TS2323: Types of property 's' are incompatible.
!!! error TS2323: Type 'number' is not assignable to type 'string'.
c = d; // Should not be allowed
~
!!! error TS2323: Type 'D' is not assignable to type 'C'.
!!! error TS2323: Types of property 'q' are incompatible.
!!! error TS2323: Type 'B' is not assignable to type 'A'.
@@ -0,0 +1,38 @@
//// [typeComparisonCaching.ts]
// Check that we only cache results of type comparisons that are free of assumptions
interface A {
p: C;
s: string;
}
interface B {
p: D;
s: number;
}
interface C {
q: A;
}
interface D {
q: B;
}
var a: A;
var b: B;
var c: C;
var d: D;
a = b;
c = d; // Should not be allowed
//// [typeComparisonCaching.js]
// Check that we only cache results of type comparisons that are free of assumptions
var a;
var b;
var c;
var d;
a = b;
c = d; // Should not be allowed
@@ -0,0 +1,16 @@
// Regression test for #1002
// Before fix this code would cause infinite loop
interface IObservable<T> {
n: IObservable<T[]>; // Needed, must be T[]
}
// Needed
interface ISubject<T> extends IObservable<T> { }
interface Foo { x }
interface Bar { y }
var values: IObservable<Foo>;
var values2: ISubject<Bar>;
values = values2;
@@ -0,0 +1,16 @@
// Regression test for #1002
// Before fix this code would cause infinite loop
interface IObservable<T> {
n: IObservable<T[]>;
}
interface ISubject<T> extends IObservable<T> { }
declare function combineLatest<TOther>(x: IObservable<TOther>[]): void;
declare function combineLatest(): void;
function fn<T>() {
var values: ISubject<any>[] = [];
// Hang when using <T>, but not <any>
combineLatest<T>(values);
}
@@ -0,0 +1,27 @@
// Check that we only cache results of type comparisons that are free of assumptions
interface A {
p: C;
s: string;
}
interface B {
p: D;
s: number;
}
interface C {
q: A;
}
interface D {
q: B;
}
var a: A;
var b: B;
var c: C;
var d: D;
a = b;
c = d; // Should not be allowed