From e836fe17297a68ab6a3fb8de1980d07386d02935 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 4 Oct 2014 09:19:47 -0700 Subject: [PATCH 01/23] Initial implementation of Union Types --- src/compiler/checker.ts | 543 ++++++++++++------ src/compiler/core.ts | 2 +- .../diagnosticInformationMap.generated.ts | 2 - src/compiler/diagnosticMessages.json | 8 - src/compiler/parser.ts | 22 +- src/compiler/types.ts | 39 +- 6 files changed, 407 insertions(+), 209 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cf35c1c02f5..1dcbde1f9d0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -130,6 +130,7 @@ module ts { var globalRegExpType: ObjectType; var tupleTypes: Map = {}; + var unionTypes: Map = {}; var stringLiteralTypes: Map = {}; var emitExtends = false; @@ -1136,6 +1137,9 @@ module ts { else if (type.flags & TypeFlags.Tuple) { writeTupleType(type); } + else if (type.flags & TypeFlags.Union) { + writeUnionType(type); + } else if (type.flags & TypeFlags.Anonymous) { writeAnonymousType(type, allowFunctionOrConstructorTypeLiteral); } @@ -1153,18 +1157,21 @@ module ts { } } - function writeTypeList(types: Type[]) { + function writeTypeList(types: Type[], union?: boolean) { for (var i = 0; i < types.length; i++) { if (i > 0) { - writePunctuation(writer, SyntaxKind.CommaToken); + if (union) { + writeSpace(writer); + } + writePunctuation(writer, union ? SyntaxKind.BarToken : SyntaxKind.CommaToken); writeSpace(writer); } - writeType(types[i], /*allowFunctionOrConstructorTypeLiteral*/ true); + writeType(types[i], /*allowFunctionOrConstructorTypeLiteral*/ !union); } } function writeTypeReference(type: TypeReference) { - if (type.target === globalArrayType && !(flags & TypeFormatFlags.WriteArrayAsGenericType)) { + if (type.target === globalArrayType && !(flags & TypeFormatFlags.WriteArrayAsGenericType) && !(type.typeArguments[0].flags & TypeFlags.Union)) { // If we are writing array element type the arrow style signatures are not allowed as // we need to surround it by curlies, e.g. { (): T; }[]; as () => T[] would mean something different writeType(type.typeArguments[0], /*allowFunctionOrConstructorTypeLiteral*/ false); @@ -1185,6 +1192,10 @@ module ts { writePunctuation(writer, SyntaxKind.CloseBracketToken); } + function writeUnionType(type: UnionType) { + writeTypeList(type.types, /*union*/ true); + } + function writeAnonymousType(type: ObjectType, allowFunctionOrConstructorTypeLiteral: boolean) { // Always use 'typeof T' for type of class, enum, and module objects if (type.symbol && type.symbol.flags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) { @@ -1730,6 +1741,15 @@ module ts { return links.type; } + function getTypeOfUnionProperty(symbol: Symbol): Type { + var links = getSymbolLinks(symbol); + if (!links.type) { + var types = map(links.unionType.types, t => getTypeOfSymbol(getPropertyOfType(getApparentType(t), symbol.name) || undefinedSymbol)); + links.type = getUnionType(types); + } + return links.type; + } + function getTypeOfSymbol(symbol: Symbol): Type { if (symbol.flags & (SymbolFlags.Variable | SymbolFlags.Property)) { return getTypeOfVariableOrParameterOrProperty(symbol); @@ -1749,6 +1769,9 @@ module ts { if (symbol.flags & SymbolFlags.Instantiated) { return getTypeOfInstantiatedSymbol(symbol); } + if (symbol.flags & SymbolFlags.UnionProperty) { + return getTypeOfUnionProperty(symbol); + } return unknownType; } @@ -2045,6 +2068,71 @@ module ts { setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType); } + function signatureListsIdentical(s: Signature[], t: Signature[]): boolean { + if (s.length !== t.length) return false; + for (var i = 0; i < s.length; i++) { + if (!compareSignatures(s[i], t[i], false, isTypeIdenticalTo)) return false; + } + return true; + } + + function getUnionSignatures(types: Type[], kind: SignatureKind): Signature[] { + var signatureLists = map(types, t => getSignaturesOfType(t, kind)); + var baseSignatures = signatureLists[0]; + for (var i = 0; i < baseSignatures.length; i++) { + if (baseSignatures[i].typeParameters) return emptyArray; + } + for (var i = 1; i < signatureLists.length; i++) { + if (!signatureListsIdentical(baseSignatures, signatureLists[i])) return emptyArray; + } + var result = map(baseSignatures, cloneSignature); + for (var i = 0; i < result.length; i++) { + var s = result[i]; + s.resolvedReturnType = undefined; + s.unionSignatures = map(signatureLists, signatures => signatures[i]); + } + return result; + } + + function getUnionIndexType(types: Type[], kind: IndexKind): Type { + var indexTypes: Type[] = []; + for (var i = 0; i < types.length; i++) { + var indexType = getIndexTypeOfType(types[i], kind); + if (!indexType) return undefined; + indexTypes.push(indexType); + } + return getUnionType(indexTypes); + } + + function resolveUnionTypeMembers(type: UnionType) { + var types: Type[] = []; + forEach(type.types, t => { + var apparentType = getApparentType(t); + if (!contains(types, apparentType)) { + types.push(apparentType); + } + }); + if (types.length <= 1) { + var res = types.length ? resolveObjectTypeMembers(types[0]) : emptyObjectType; + setObjectTypeMembers(type, res.members, res.callSignatures, res.constructSignatures, res.stringIndexType, res.numberIndexType); + return; + } + var members: SymbolTable = {}; + forEach(getPropertiesOfType(types[0]), prop => { + for (var i = 1; i < types.length; i++) { + if (!getPropertyOfType(types[i], prop.name)) return; + } + var symbol = createSymbol(SymbolFlags.UnionProperty | SymbolFlags.Transient, prop.name); + symbol.unionType = type; + members[prop.name] = symbol; + }); + var callSignatures = getUnionSignatures(types, SignatureKind.Call); + var constructSignatures = getUnionSignatures(types, SignatureKind.Construct); + var stringIndexType = getUnionIndexType(types, IndexKind.String); + var numberIndexType = getUnionIndexType(types, IndexKind.Number); + setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); + } + function resolveAnonymousTypeMembers(type: ObjectType) { var symbol = type.symbol; if (symbol.flags & SymbolFlags.TypeLiteral) { @@ -2093,6 +2181,9 @@ module ts { else if (type.flags & TypeFlags.Tuple) { resolveTupleTypeMembers(type); } + else if (type.flags & TypeFlags.Union) { + resolveUnionTypeMembers(type); + } else { resolveTypeReferenceMembers(type); } @@ -2253,6 +2344,9 @@ module ts { if (signature.target) { var type = instantiateType(getReturnTypeOfSignature(signature.target), signature.mapper); } + else if (signature.unionSignatures) { + var type = getUnionType(map(signature.unionSignatures, getReturnTypeOfSignature)); + } else { var type = getReturnTypeFromBody(signature.declaration); } @@ -2561,6 +2655,70 @@ module ts { return links.resolvedType; } + function addTypeToSortedSet(sortedSet: Type[], type: Type) { + if (type.flags & TypeFlags.Union) { + addTypesToSortedSet(sortedSet, (type).types); + } + else { + var i = 0; + var id = type.id; + while (i < sortedSet.length && sortedSet[i].id < id) i++; + if (i === sortedSet.length || sortedSet[i].id !== id) { + sortedSet.splice(i, 0, type); + } + } + } + + function addTypesToSortedSet(sortedTypes: Type[], types: Type[]) { + for (var i = 0, len = types.length; i < len; i++) { + addTypeToSortedSet(sortedTypes, types[i]); + } + } + + function isSubtypeOfAny(candidate: Type, types: Type[]): boolean { + for (var i = 0, len = types.length; i < len; i++) { + if (candidate !== types[i] && isTypeSubtypeOf(candidate, types[i])) return true; + } + return false; + } + + function removeSubtypes(types: Type[]) { + var i = types.length; + while (i > 0) { + i--; + if (isSubtypeOfAny(types[i], types)) { + types.splice(i, 1); + } + } + } + + function getUnionType(types: Type[]): Type { + if (types.length === 0) { + return emptyObjectType; + } + var sortedTypes: Type[] = []; + addTypesToSortedSet(sortedTypes, types); + removeSubtypes(sortedTypes); + if (sortedTypes.length === 1) { + return sortedTypes[0]; + } + var id = getTypeListId(sortedTypes); + var type = unionTypes[id]; + if (!type) { + type = unionTypes[id] = createObjectType(TypeFlags.Union); + type.types = sortedTypes; + } + return type; + } + + function getTypeFromUnionTypeNode(node: UnionTypeNode): Type { + var links = getNodeLinks(node); + if (!links.resolvedType) { + links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNode)); + } + return links.resolvedType; + } + function getTypeFromTypeLiteralNode(node: TypeLiteralNode): Type { var links = getNodeLinks(node); if (!links.resolvedType) { @@ -2607,6 +2765,8 @@ module ts { return getTypeFromArrayTypeNode(node); case SyntaxKind.TupleType: return getTypeFromTupleTypeNode(node); + case SyntaxKind.UnionType: + return getTypeFromUnionTypeNode(node); case SyntaxKind.TypeLiteral: return getTypeFromTypeLiteralNode(node); // This function assumes that an identifier or qualified name is a type expression @@ -2771,6 +2931,9 @@ module ts { if (type.flags & TypeFlags.Tuple) { return createTupleType(instantiateList((type).elementTypes, mapper, instantiateType)); } + if (type.flags & TypeFlags.Union) { + return getUnionType(instantiateList((type).types, mapper, instantiateType)); + } } return type; } @@ -2932,7 +3095,7 @@ module ts { errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); } - function isRelatedTo(source: Type, target: Type, reportErrors: boolean): boolean { + function isRelatedTo(source: Type, target: Type, reportErrors?: boolean): boolean { return isRelatedToWithCustomErrors(source, target, reportErrors, /*chainedMessage*/ undefined, /*terminalMessage*/ undefined); } @@ -2953,8 +3116,17 @@ module ts { if (source === numberType && target.flags & TypeFlags.Enum) return true; } } - - if (source.flags & TypeFlags.TypeParameter && target.flags & TypeFlags.TypeParameter) { + if (source.flags & TypeFlags.Union) { + if (unionTypeRelatedToType(source, target, reportErrors)) { + return true; + } + } + else if (target.flags & TypeFlags.Union) { + if (typeRelatedToUnionType(source, target, reportErrors)) { + return true; + } + } + else if (source.flags & TypeFlags.TypeParameter && target.flags & TypeFlags.TypeParameter) { if (typeParameterRelatedTo(source, target, reportErrors)) { return true; } @@ -2971,7 +3143,7 @@ module ts { // Report structural errors only if we haven't reported any errors yet var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo; // identity relation does not use apparent type - var sourceOrApparentType = relation === identityRelation ? source : getApparentType(source); + var sourceOrApparentType = relation === identityRelation ? source : getApparentType(source); if (sourceOrApparentType.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType && objectTypeRelatedTo(sourceOrApparentType, target, reportStructuralErrors)) { errorInfo = saveErrorInfo; @@ -2992,6 +3164,26 @@ module ts { return false; } + function typeRelatedToUnionType(source: Type, target: UnionType, reportErrors: boolean): boolean { + 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; + } + } + return false; + } + + function unionTypeRelatedToType(source: UnionType, target: Type, reportErrors: boolean): boolean { + var sourceTypes = source.types; + for (var i = 0, len = sourceTypes.length; i < len; i++) { + if (!isRelatedTo(sourceTypes[i], target, reportErrors)) { + return false; + } + } + return true; + } + function typesRelatedTo(sources: Type[], targets: Type[], reportErrors: boolean): boolean { for (var i = 0, len = sources.length; i < len; i++) { if (!isRelatedTo(sources[i], targets[i], reportErrors)) return false; @@ -3093,34 +3285,12 @@ module ts { function propertiesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { if (relation === identityRelation) { - return propertiesAreIdenticalTo(source, target, reportErrors); + return propertiesIdenticalTo(source, target, reportErrors); } - else { - return propertiesAreSubtypeOrAssignableTo(source, target, reportErrors); - } - } - - function propertiesAreIdenticalTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { - var sourceProperties = getPropertiesOfType(source); - var targetProperties = getPropertiesOfType(target); - if (sourceProperties.length !== targetProperties.length) { - return false; - } - for (var i = 0, len = sourceProperties.length; i < len; ++i) { - var sourceProp = sourceProperties[i]; - var targetProp = getPropertyOfType(target, sourceProp.name); - if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) { - return false; - } - } - return true; - } - - function propertiesAreSubtypeOrAssignableTo(source: ApparentType, target: ObjectType, reportErrors: boolean): boolean { var properties = getPropertiesOfType(target); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; - var sourceProp = getPropertyOfApparentType(source, targetProp.name); + var sourceProp = getPropertyOfApparentType(source, targetProp.name); if (sourceProp !== targetProp) { if (!sourceProp) { if (!isOptionalProperty(targetProp)) { @@ -3193,80 +3363,26 @@ module ts { return true; } - function signaturesRelatedTo(source: ObjectType, target: ObjectType, kind: SignatureKind, reportErrors: boolean): boolean { - if (relation === identityRelation) { - return areSignaturesIdenticalTo(source, target, kind, reportErrors); - } - else { - return areSignaturesSubtypeOrAssignableTo(source, target, kind, reportErrors); - } - } - - function areSignaturesIdenticalTo(source: ObjectType, target: ObjectType, kind: SignatureKind, reportErrors: boolean): boolean { - var sourceSignatures = getSignaturesOfType(source, kind); - var targetSignatures = getSignaturesOfType(target, kind); - if (sourceSignatures.length !== targetSignatures.length) { + function propertiesIdenticalTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { + var sourceProperties = getPropertiesOfType(source); + var targetProperties = getPropertiesOfType(target); + if (sourceProperties.length !== targetProperties.length) { return false; } - - for (var i = 0, len = sourceSignatures.length; i < len; ++i) { - if (!isSignatureIdenticalTo(sourceSignatures[i], targetSignatures[i], reportErrors)) { + for (var i = 0, len = sourceProperties.length; i < len; ++i) { + var sourceProp = sourceProperties[i]; + var targetProp = getPropertyOfType(target, sourceProp.name); + if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) { return false; } } - return true; } - function isSignatureIdenticalTo(source: Signature, target: Signature, reportErrors: boolean): boolean { - if (source === target) { - return true; + function signaturesRelatedTo(source: ObjectType, target: ObjectType, kind: SignatureKind, reportErrors: boolean): boolean { + if (relation === identityRelation) { + return signaturesIdenticalTo(source, target, kind, reportErrors); } - - if (source.hasRestParameter !== target.hasRestParameter) { - return false; - } - - if (source.parameters.length !== target.parameters.length) { - return false; - } - - if (source.minArgumentCount !== target.minArgumentCount) { - return false; - } - - if (source.typeParameters && target.typeParameters) { - if (source.typeParameters.length !== target.typeParameters.length) { - return false; - } - - for (var i = 0, len = source.typeParameters.length; i < len; ++i) { - if (!isRelatedTo(source.typeParameters[i], target.typeParameters[i], reportErrors)) { - return false; - } - } - } - else if (source.typeParameters || source.typeParameters) { - return 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 - source = getErasedSignature(source); - target = getErasedSignature(target); - 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 (!isRelatedTo(s, t, reportErrors)) { - return false; - } - } - var t = getReturnTypeOfSignature(target); - var s = getReturnTypeOfSignature(source); - return isRelatedTo(s, t, reportErrors); - } - - function areSignaturesSubtypeOrAssignableTo(source: ObjectType, target: ObjectType, kind: SignatureKind, reportErrors: boolean): boolean { if (target === anyFunctionType || source === anyFunctionType) return true; var sourceSignatures = getSignaturesOfType(source, kind); var targetSignatures = getSignaturesOfType(target, kind); @@ -3278,7 +3394,7 @@ module ts { for (var j = 0; j < sourceSignatures.length; j++) { var s = sourceSignatures[j]; if (!s.hasStringLiterals || source.flags & TypeFlags.FromSignature) { - if (isSignatureSubtypeOrAssignableTo(s, t, localErrors)) { + if (signatureRelatedTo(s, t, localErrors)) { errorInfo = saveErrorInfo; continue outer; } @@ -3292,15 +3408,13 @@ module ts { return true; } - function isSignatureSubtypeOrAssignableTo(source: Signature, target: Signature, reportErrors: boolean): boolean { + function signatureRelatedTo(source: Signature, target: Signature, reportErrors: boolean): boolean { if (source === target) { return true; } - if (!target.hasRestParameter && source.minArgumentCount > target.parameters.length) { return false; } - var sourceMax = source.parameters.length; var targetMax = target.parameters.length; var checkCount: number; @@ -3346,71 +3460,117 @@ module ts { return isRelatedTo(s, t, reportErrors); } + function signaturesIdenticalTo(source: ObjectType, target: ObjectType, kind: SignatureKind, reportErrors: boolean): boolean { + var sourceSignatures = getSignaturesOfType(source, kind); + var targetSignatures = getSignaturesOfType(target, kind); + if (sourceSignatures.length !== targetSignatures.length) { + return false; + } + for (var i = 0, len = sourceSignatures.length; i < len; ++i) { + if (!compareSignatures(sourceSignatures[i], targetSignatures[i], /*returnTypes*/ true, isRelatedTo)) { + return false; + } + } + return true; + } + function stringIndexTypesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { if (relation === identityRelation) { - return areIndexTypesIdenticalTo(IndexKind.String, source, target, reportErrors); + return indexTypesIdenticalTo(IndexKind.String, source, target, reportErrors); } - else { - var targetType = getIndexTypeOfType(target, IndexKind.String); - if (targetType) { - var sourceType = getIndexTypeOfType(source, IndexKind.String); - if (!sourceType) { - if (reportErrors) { - reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); - } - return false; - } - if (!isRelatedTo(sourceType, targetType, reportErrors)) { - if (reportErrors) { - reportError(Diagnostics.Index_signatures_are_incompatible_Colon); - } - return false; + var targetType = getIndexTypeOfType(target, IndexKind.String); + if (targetType) { + var sourceType = getIndexTypeOfType(source, IndexKind.String); + if (!sourceType) { + if (reportErrors) { + reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } + return false; + } + if (!isRelatedTo(sourceType, targetType, reportErrors)) { + if (reportErrors) { + reportError(Diagnostics.Index_signatures_are_incompatible_Colon); + } + return false; } - return true; } + return true; } function numberIndexTypesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { if (relation === identityRelation) { - return areIndexTypesIdenticalTo(IndexKind.Number, source, target, reportErrors); + return indexTypesIdenticalTo(IndexKind.Number, source, target, reportErrors); } - else { - var targetType = getIndexTypeOfType(target, IndexKind.Number); - if (targetType) { - var sourceStringType = getIndexTypeOfType(source, IndexKind.String); - var sourceNumberType = getIndexTypeOfType(source, IndexKind.Number); - if (!(sourceStringType || sourceNumberType)) { - if (reportErrors) { - reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); - } - return 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); - } - else { - var compatible = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); - } - if (!compatible) { - if (reportErrors) { - reportError(Diagnostics.Index_signatures_are_incompatible_Colon); - } - return false; + var targetType = getIndexTypeOfType(target, IndexKind.Number); + if (targetType) { + var sourceStringType = getIndexTypeOfType(source, IndexKind.String); + var sourceNumberType = getIndexTypeOfType(source, IndexKind.Number); + if (!(sourceStringType || sourceNumberType)) { + if (reportErrors) { + reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } + return 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); + } + else { + var compatible = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); + } + if (!compatible) { + if (reportErrors) { + reportError(Diagnostics.Index_signatures_are_incompatible_Colon); + } + return false; } - return true; } + return true; } - function areIndexTypesIdenticalTo(indexKind: IndexKind, source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { + function indexTypesIdenticalTo(indexKind: IndexKind, source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { var targetType = getIndexTypeOfType(target, indexKind); var sourceType = getIndexTypeOfType(source, indexKind); return (!sourceType && !targetType) || (sourceType && targetType && isRelatedTo(sourceType, targetType, reportErrors)); } } + function compareSignatures(source: Signature, target: Signature, returnTypes: boolean, compareTypes: (s: Type, t: Type) => boolean): boolean { + if (source === target) { + return true; + } + if (source.parameters.length !== target.parameters.length || + source.minArgumentCount !== target.minArgumentCount || + source.hasRestParameter !== target.hasRestParameter) { + return false; + } + if (source.typeParameters && target.typeParameters) { + if (source.typeParameters.length !== target.typeParameters.length) { + return false; + } + for (var i = 0, len = source.typeParameters.length; i < len; ++i) { + if (!compareTypes(source.typeParameters[i], target.typeParameters[i])) { + return false; + } + } + } + else if (source.typeParameters || source.typeParameters) { + return 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 + source = getErasedSignature(source); + target = getErasedSignature(target); + 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; + } + } + return !returnTypes || compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); + } + function isSupertypeOfEach(candidate: Type, types: Type[]): boolean { for (var i = 0, len = types.length; i < len; i++) { if (candidate !== types[i] && !isTypeSubtypeOf(types[i], candidate)) return false; @@ -3418,11 +3578,13 @@ module ts { return true; } - function getBestCommonType(types: Type[], contextualType?: Type, candidatesOnly?: boolean): Type { - if (contextualType && isSupertypeOfEach(contextualType, types)) return contextualType; - return forEach(types, t => isSupertypeOfEach(t, types) ? t : undefined) || (candidatesOnly ? undefined : emptyObjectType); + function getCommonSupertype(types: Type[]): Type { + return forEach(types, t => isSupertypeOfEach(t, types) ? t : undefined); } + function getBestCommonType(types: Type[], contextualType?: Type): Type { + return contextualType && isSupertypeOfEach(contextualType, types) ? contextualType : getUnionType(types); } + function isTypeOfObjectLiteral(type: Type): boolean { return (type.flags & TypeFlags.Anonymous) && type.symbol && (type.symbol.flags & SymbolFlags.ObjectLiteral) ? true : false; } @@ -3439,10 +3601,13 @@ module ts { } /* If we are widening on a literal, then we may need to the 'node' parameter for reporting purposes */ - function getWidenedType(type: Type, supressNoImplicitAnyErrors?: boolean): Type { + function getWidenedType(type: Type, suppressNoImplicitAnyErrors?: boolean): Type { if (type.flags & (TypeFlags.Undefined | TypeFlags.Null)) { return anyType; } + if (type.flags & TypeFlags.Union) { + return getWidenedTypeOfUnion(type); + } if (isTypeOfObjectLiteral(type)) { return getWidenedTypeOfObjectLiteral(type); } @@ -3451,6 +3616,10 @@ module ts { } return type; + function getWidenedTypeOfUnion(type: Type): Type { + return getUnionType(map((type).types, t => getWidenedType(t, suppressNoImplicitAnyErrors))); + } + function getWidenedTypeOfObjectLiteral(type: Type): Type { var properties = getPropertiesOfType(type); if (properties.length) { @@ -3461,8 +3630,7 @@ module ts { var widenedType = getWidenedType(propType); if (propType !== widenedType) { propTypeWasWidened = true; - - if (!supressNoImplicitAnyErrors && program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (!suppressNoImplicitAnyErrors && compilerOptions.noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType)); } } @@ -3492,10 +3660,8 @@ module ts { function getWidenedTypeOfArrayLiteral(type: Type): Type { var elementType = (type).typeArguments[0]; - var widenedType = getWidenedType(elementType, supressNoImplicitAnyErrors); - + var widenedType = getWidenedType(elementType, suppressNoImplicitAnyErrors); type = elementType !== widenedType ? createArrayType(widenedType) : type; - return type; } } @@ -3646,9 +3812,19 @@ module ts { function getInferredType(context: InferenceContext, index: number): Type { var result = context.inferredTypes[index]; if (!result) { - var commonType = getWidenedType(getBestCommonType(context.inferences[index])); + var inferences = context.inferences[index]; + if (inferences.length) { + // Find type that is supertype of all others + var supertype = getCommonSupertype(inferences); + // Infer widened supertype, or the undefined type for no common supertype + var inferredType = supertype ? getWidenedType(supertype) : undefinedType; + } + else { + // Infer the empty object type when no inferences were made + inferredType = emptyObjectType; + } var constraint = getConstraintOfTypeParameter(context.typeParameters[index]); - var result = constraint && !isTypeAssignableTo(commonType, constraint) ? constraint : commonType; + var result = constraint && !isTypeAssignableTo(inferredType, constraint) ? constraint : inferredType; context.inferredTypes[index] = result; } return result; @@ -4083,10 +4259,7 @@ module ts { return createTupleType(elementTypes); } var contextualElementType = contextualType && !isInferentialContext(contextualMapper) ? getIndexTypeOfType(contextualType, IndexKind.Number) : undefined; - var elementType = getBestCommonType(uniqueElements(elementTypes), contextualElementType, true); - if (!elementType) { - elementType = elements.length ? emptyObjectType : undefinedType; - } + var elementType = elements.length || contextualElementType ? getBestCommonType(deduplicate(elementTypes), contextualElementType) : undefinedType; return createArrayType(elementType); } @@ -4380,7 +4553,9 @@ module ts { } } } - return getInferredTypes(context); + var inferredTypes = getInferredTypes(context); + // Inference has failed if the undefined type is in list of inferences + return contains(inferredTypes, undefinedType) ? undefined : inferredTypes; } function checkTypeArguments(signature: Signature, typeArguments: TypeNode[]): Type[] { @@ -4405,7 +4580,6 @@ module ts { if (arg.kind === SyntaxKind.OmittedExpression) { continue; } - var paramType = getTypeAtPosition(signature, i); // String literals get string literal types unless we're reporting errors var argType = arg.kind === SyntaxKind.StringLiteral && !reportErrors ? @@ -4441,26 +4615,30 @@ module ts { } } var relation = candidates.length === 1 ? assignableRelation : subtypeRelation; + var lastCandidate: Signature; while (true) { for (var i = 0; i < candidates.length; i++) { if (!signatureHasCorrectArity(node, candidates[i])) { continue; } - while (true) { - var candidateWithCorrectArity = candidates[i]; - if (candidateWithCorrectArity.typeParameters) { + var candidate = candidates[i]; + if (candidate.typeParameters) { var typeArguments = node.typeArguments ? - checkTypeArguments(candidateWithCorrectArity, node.typeArguments) : - inferTypeArguments(candidateWithCorrectArity, args, excludeArgument); - candidateWithCorrectArity = getSignatureInstantiation(candidateWithCorrectArity, typeArguments); + checkTypeArguments(candidate, node.typeArguments) : + inferTypeArguments(candidate, args, excludeArgument); + if (!typeArguments) { + break; + } + candidate = getSignatureInstantiation(candidate, typeArguments); } - if (!checkApplicableSignature(node, candidateWithCorrectArity, relation, excludeArgument, /*reportErrors*/ false)) { + lastCandidate = candidate; + if (!checkApplicableSignature(node, candidate, relation, excludeArgument, /*reportErrors*/ false)) { break; } var index = excludeArgument ? indexOf(excludeArgument, true) : -1; if (index < 0) { - return candidateWithCorrectArity; + return candidate; } excludeArgument[index] = false; } @@ -4475,8 +4653,8 @@ module ts { // no arguments excluded from assignability checks. // If candidate is undefined, it means that no candidates had a suitable arity. In that case, // skip the checkApplicableSignature check. - if (candidateWithCorrectArity) { - checkApplicableSignature(node, candidateWithCorrectArity, relation, /*excludeArgument*/ undefined, /*reportErrors*/ true); + if (lastCandidate) { + checkApplicableSignature(node, lastCandidate, relation, /*excludeArgument*/ undefined, /*reportErrors*/ true); } else { error(node, Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); @@ -4563,7 +4741,9 @@ module ts { // but is a subtype of the Function interface, the call is an untyped function call. In an // untyped function call no TypeArgs are permitted, Args can be any argument list, no contextual // types are provided for the argument expressions, and the result is always of type Any. - if ((funcType === anyType) || (!callSignatures.length && !constructSignatures.length && isTypeAssignableTo(funcType, globalFunctionType))) { + // We exclude union types because we may have a union of function types that happen to have + // no common signatures. + if (funcType === anyType || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) { if (node.typeArguments) { error(node, Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } @@ -4723,7 +4903,7 @@ module ts { // Try to return the best common type if we have any return expressions. if (types.length > 0) { - var commonType = getBestCommonType(types, /*contextualType:*/ undefined, /*candidatesOnly:*/ true); + var commonType = getCommonSupertype(types); if (!commonType) { error(func, Diagnostics.No_best_common_type_exists_among_return_expressions); @@ -5118,16 +5298,7 @@ module ts { var type1 = checkExpression(node.whenTrue, contextualMapper); var type2 = checkExpression(node.whenFalse, contextualMapper); var contextualType = isInferentialContext(contextualMapper) ? undefined : getContextualType(node); - var resultType = getBestCommonType([type1, type2], contextualType, true); - if (!resultType) { - if (contextualType) { - error(node, Diagnostics.No_best_common_type_exists_between_0_1_and_2, typeToString(contextualType), typeToString(type1), typeToString(type2)); - } - else { - error(node, Diagnostics.No_best_common_type_exists_between_0_and_1, typeToString(type1), typeToString(type2)); - } - resultType = emptyObjectType; - } + var resultType = getBestCommonType([type1, type2], contextualType); return resultType; } @@ -5520,6 +5691,10 @@ module ts { forEach(node.elementTypes, checkSourceElement); } + function checkUnionType(node: UnionTypeNode) { + forEach(node.types, checkSourceElement); + } + function isPrivateWithinAmbient(node: Node): boolean { return (node.flags & NodeFlags.Private) && isInAmbientContext(node); } @@ -6782,6 +6957,8 @@ module ts { return checkArrayType(node); case SyntaxKind.TupleType: return checkTupleType(node); + case SyntaxKind.TupleType: + return checkUnionType(node); case SyntaxKind.FunctionDeclaration: return checkFunctionDeclaration(node); case SyntaxKind.Block: diff --git a/src/compiler/core.ts b/src/compiler/core.ts index fb2bde52453..8d8ea66d86b 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -82,7 +82,7 @@ module ts { return array1.concat(array2); } - export function uniqueElements(array: T[]): T[] { + export function deduplicate(array: T[]): T[] { if (array) { var result: T[] = []; for (var i = 0, len = array.length; i < len; i++) { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index ba6f742c4c1..266d0a14c4b 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -179,8 +179,6 @@ module ts { The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2363, category: DiagnosticCategory.Error, key: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." }, Invalid_left_hand_side_of_assignment_expression: { code: 2364, category: DiagnosticCategory.Error, key: "Invalid left-hand side of assignment expression." }, Operator_0_cannot_be_applied_to_types_1_and_2: { code: 2365, category: DiagnosticCategory.Error, key: "Operator '{0}' cannot be applied to types '{1}' and '{2}'." }, - No_best_common_type_exists_between_0_1_and_2: { code: 2366, category: DiagnosticCategory.Error, key: "No best common type exists between '{0}', '{1}', and '{2}'." }, - No_best_common_type_exists_between_0_and_1: { code: 2367, category: DiagnosticCategory.Error, key: "No best common type exists between '{0}' and '{1}'." }, Type_parameter_name_cannot_be_0: { code: 2368, category: DiagnosticCategory.Error, key: "Type parameter name cannot be '{0}'" }, A_parameter_property_is_only_allowed_in_a_constructor_implementation: { code: 2369, category: DiagnosticCategory.Error, key: "A parameter property is only allowed in a constructor implementation." }, A_rest_parameter_must_be_of_an_array_type: { code: 2370, category: DiagnosticCategory.Error, key: "A rest parameter must be of an array type." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 0480cd3000c..cc2a752fce7 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -708,14 +708,6 @@ "category": "Error", "code": 2365 }, - "No best common type exists between '{0}', '{1}', and '{2}'.": { - "category": "Error", - "code": 2366 - }, - "No best common type exists between '{0}' and '{1}'.": { - "category": "Error", - "code": 2367 - }, "Type parameter name cannot be '{0}'": { "category": "Error", "code": 2368 diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b06326f6925..cb6c9a37cd9 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -232,6 +232,8 @@ module ts { return child((node).elementType); case SyntaxKind.TupleType: return children((node).elementTypes); + case SyntaxKind.UnionType: + return children((node).types); case SyntaxKind.ArrayLiteral: return children((node).elements); case SyntaxKind.ObjectLiteral: @@ -1728,9 +1730,9 @@ module ts { } } - function parseType(): TypeNode { + function parseNonUnionType(): TypeNode { var type = parseNonArrayType(); - while (type && !scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) { + while (!scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) { parseExpected(SyntaxKind.CloseBracketToken); var node = createNode(SyntaxKind.ArrayType, type.pos); node.elementType = type; @@ -1739,6 +1741,22 @@ module ts { return type; } + function parseType(): TypeNode { + var type = parseNonUnionType(); + if (token === SyntaxKind.BarToken) { + var types = >[type]; + types.pos = type.pos; + while (parseOptional(SyntaxKind.BarToken)) { + types.push(parseNonUnionType()); + } + types.end = getNodeEnd(); + var node = createNode(SyntaxKind.UnionType, type.pos); + node.types = types; + type = finishNode(node); + } + return type; + } + function parseTypeAnnotation(): TypeNode { return parseOptional(SyntaxKind.ColonToken) ? parseType() : undefined; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index dcc42bf3358..0c322b49d25 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -154,6 +154,7 @@ module ts { TypeLiteral, ArrayType, TupleType, + UnionType, // Expression ArrayLiteral, ObjectLiteral, @@ -224,7 +225,7 @@ module ts { FirstFutureReservedWord = ImplementsKeyword, LastFutureReservedWord = YieldKeyword, FirstTypeNode = TypeReference, - LastTypeNode = TupleType, + LastTypeNode = UnionType, FirstPunctuation = OpenBraceToken, LastPunctuation = CaretEqualsToken, FirstToken = EndOfFileToken, @@ -337,6 +338,10 @@ module ts { elementTypes: NodeArray; } + export interface UnionTypeNode extends TypeNode { + types: NodeArray; + } + export interface StringLiteralTypeNode extends TypeNode { text: string; } @@ -728,19 +733,20 @@ module ts { ConstructSignature = 0x00010000, // Construct signature IndexSignature = 0x00020000, // Index signature TypeParameter = 0x00040000, // Type parameter + UnionProperty = 0x00080000, // Property in union type // Export markers (see comment in declareModuleMember in binder) - ExportValue = 0x00080000, // Exported value marker - ExportType = 0x00100000, // Exported type marker - ExportNamespace = 0x00200000, // Exported namespace marker + ExportValue = 0x00100000, // Exported value marker + ExportType = 0x00200000, // Exported type marker + ExportNamespace = 0x00400000, // Exported namespace marker - Import = 0x00400000, // Import - Instantiated = 0x00800000, // Instantiated symbol - Merged = 0x01000000, // Merged symbol (created during program binding) - Transient = 0x02000000, // Transient symbol (created during type check) - Prototype = 0x04000000, // Symbol for the prototype property (without source code representation) + Import = 0x00800000, // Import + Instantiated = 0x01000000, // Instantiated symbol + Merged = 0x02000000, // Merged symbol (created during program binding) + Transient = 0x04000000, // Transient symbol (created during type check) + Prototype = 0x08000000, // Prototype property (no source representation) - Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor, + Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor | UnionProperty, Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter, Namespace = ValueModule | NamespaceModule, Module = ValueModule | NamespaceModule, @@ -798,6 +804,7 @@ module ts { mapper?: TypeMapper; // Type mapper for instantiation alias referenced?: boolean; // True if alias symbol has been referenced as a value exportAssignSymbol?: Symbol; // Symbol exported from external module + unionType?: UnionType; // Containing union type for union property } export interface TransientSymbol extends Symbol, SymbolLinks { } @@ -845,13 +852,14 @@ module ts { Interface = 0x00000800, // Interface Reference = 0x00001000, // Generic type reference Tuple = 0x00002000, // Tuple - Anonymous = 0x00004000, // Anonymous - FromSignature = 0x00008000, // Created for signature assignment check + Union = 0x00004000, // Union + Anonymous = 0x00008000, // Anonymous + FromSignature = 0x00010000, // Created for signature assignment check Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null, StringLike = String | StringLiteral, NumberLike = Number | Enum, - ObjectType = Class | Interface | Reference | Tuple | Anonymous + ObjectType = Class | Interface | Reference | Tuple | Union | Anonymous } // Properties common to all types @@ -909,6 +917,10 @@ module ts { baseArrayType: TypeReference; // Array where T is best common type of element types } + export interface UnionType extends ObjectType { + types: Type[]; // Constituent types + } + // Resolved object type export interface ResolvedObjectType extends ObjectType { members: SymbolTable; // Properties by name @@ -941,6 +953,7 @@ module ts { hasStringLiterals: boolean; // True if specialized target?: Signature; // Instantiation target mapper?: TypeMapper; // Instantiation mapper + unionSignatures?: Signature[]; // Underlying signatures of a union signature erasedSignatureCache?: Signature; // Erased version of signature (deferred) isolatedSignatureType?: ObjectType; // A manufactured type that just contains the signature for purposes of signature comparison } From d70494fdad8ac6d5250afa5ea8511ebb63d7d6c9 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 7 Oct 2014 14:05:58 -0700 Subject: [PATCH 02/23] Narrowing of variable types using typeof/instanceof type guards --- src/compiler/checker.ts | 295 ++++++++++++++++++++++++++++++++++++---- src/compiler/types.ts | 19 +-- 2 files changed, 278 insertions(+), 36 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1dcbde1f9d0..cf2099badde 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3844,44 +3844,285 @@ module ts { // EXPRESSION TYPE CHECKING - function checkIdentifier(node: Identifier): Type { - function isInTypeQuery(node: Node): boolean { - // TypeScript 1.0 spec (April 2014): 3.6.3 - // A type query consists of the keyword typeof followed by an expression. - // The expression is restricted to a single identifier or a sequence of identifiers separated by periods - while (node) { - switch (node.kind) { - case SyntaxKind.TypeQuery: - return true; - case SyntaxKind.Identifier: - case SyntaxKind.QualifiedName: - node = node.parent; - continue; - default: - return false; + function getResolvedSymbol(node: Identifier): Symbol { + var links = getNodeLinks(node); + if (!links.resolvedSymbol) { + links.resolvedSymbol = resolveName(node, node.text, SymbolFlags.Value | SymbolFlags.ExportValue, Diagnostics.Cannot_find_name_0, identifierToString(node)) || unknownSymbol; + } + return links.resolvedSymbol; + } + + function isInTypeQuery(node: Node): boolean { + // TypeScript 1.0 spec (April 2014): 3.6.3 + // A type query consists of the keyword typeof followed by an expression. + // The expression is restricted to a single identifier or a sequence of identifiers separated by periods + while (node) { + switch (node.kind) { + case SyntaxKind.TypeQuery: + return true; + case SyntaxKind.Identifier: + case SyntaxKind.QualifiedName: + node = node.parent; + continue; + default: + return false; + } + } + Debug.fail("should not get here"); + } + + // Remove one or more primitive types from a union type + function subtractPrimitiveTypes(type: Type, subtractMask: TypeFlags): Type { + if (type.flags & TypeFlags.Union) { + var types = (type).types; + if (forEach(types, t => t.flags & subtractMask)) { + var newTypes: Type[] = []; + forEach(types, t => { + if (!(t.flags & subtractMask)) { + newTypes.push(t); + } + }); + return getUnionType(newTypes); + } + } + return type; + } + + // Check if a given variable is assigned within a given syntax node + function IsVariableAssignedWithin(symbol: Symbol, node: Node): boolean { + var links = getNodeLinks(node); + if (links.assignmentChecks) { + var cachedResult = links.assignmentChecks[symbol.id]; + if (cachedResult !== undefined) { + return cachedResult; + } + } + else { + links.assignmentChecks = {}; + } + return links.assignmentChecks[symbol.id] = isAssignedIn(node); + + function isAssignedInBinaryExpression(node: BinaryExpression) { + if (node.operator >= SyntaxKind.FirstAssignment && node.operator <= SyntaxKind.LastAssignment) { + var n = node.left; + while (n.kind === SyntaxKind.ParenExpression) { + n = (n).expression; + } + if (n.kind === SyntaxKind.Identifier && getResolvedSymbol(n) === symbol) { + return true; } } - Debug.fail("should not get here"); + return forEachChild(node, isAssignedIn); } - var symbol = resolveName(node, node.text, SymbolFlags.Value | SymbolFlags.ExportValue, Diagnostics.Cannot_find_name_0, identifierToString(node)); - if (!symbol) { - symbol = unknownSymbol; + function isAssignedInVariableDeclaration(node: VariableDeclaration) { + if (getSymbolOfNode(node) === symbol && node.initializer) { + return true; + } + return forEachChild(node, isAssignedIn); } + function isAssignedIn(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.BinaryExpression: + return isAssignedInBinaryExpression(node); + case SyntaxKind.VariableDeclaration: + return isAssignedInVariableDeclaration(node); + case SyntaxKind.ArrayLiteral: + case SyntaxKind.ObjectLiteral: + case SyntaxKind.PropertyAccess: + case SyntaxKind.IndexedAccess: + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + case SyntaxKind.TypeAssertion: + case SyntaxKind.ParenExpression: + case SyntaxKind.PrefixOperator: + case SyntaxKind.PostfixOperator: + case SyntaxKind.ConditionalExpression: + case SyntaxKind.Block: + case SyntaxKind.VariableStatement: + case SyntaxKind.ExpressionStatement: + case SyntaxKind.IfStatement: + case SyntaxKind.DoStatement: + case SyntaxKind.WhileStatement: + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.ReturnStatement: + case SyntaxKind.WithStatement: + case SyntaxKind.SwitchStatement: + case SyntaxKind.CaseClause: + case SyntaxKind.DefaultClause: + case SyntaxKind.LabeledStatement: + case SyntaxKind.ThrowStatement: + case SyntaxKind.TryStatement: + case SyntaxKind.TryBlock: + case SyntaxKind.CatchBlock: + case SyntaxKind.FinallyBlock: + return forEachChild(node, isAssignedIn); + } + return false; + } + } + + // Get the narrowed type of a given symbol at a given location + function getNarrowedTypeOfSymbol(symbol: Symbol, node: Node) { + var type = getTypeOfSymbol(symbol); + // Only narrow when symbol is variable of a non-primitive type + if (symbol.flags & SymbolFlags.Variable && isTypeAnyOrObjectOrTypeParameter(type)) { + while (true) { + var child = node; + node = node.parent; + // Stop at containing function or module block + if (!node || node.kind === SyntaxKind.FunctionBlock || node.kind === SyntaxKind.ModuleBlock) { + break; + } + var narrowedType = type; + switch (node.kind) { + case SyntaxKind.IfStatement: + // In a branch of an if statement, narrow based on controlling expression + if (child !== (node).expression) { + narrowedType = narrowType(type, (node).expression, child === (node).thenStatement); + } + break; + case SyntaxKind.ConditionalExpression: + // In a branch of a conditional expression, narrow based on controlling condition + if (child !== (node).condition) { + narrowedType = narrowType(type, (node).condition, child === (node).whenTrue); + } + break; + case SyntaxKind.BinaryExpression: + // In the right operand of an && or ||, narrow based on left operand + if (child === (node).right) { + if ((node).operator === SyntaxKind.AmpersandAmpersandToken) { + narrowedType = narrowType(type, (node).left, true); + } + else if ((node).operator === SyntaxKind.BarBarToken) { + narrowedType = narrowType(type, (node).left, false); + } + } + break; + } + // Only use narrowed type if construct contains no assignments to variable + if (narrowedType !== type && !IsVariableAssignedWithin(symbol, node)) { + type = narrowedType; + } + } + } + return type; + + function narrowTypeByEquality(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { + var left = expr.left; + var right = expr.right; + // Check that we have 'typeof ' on the left and string literal on the right + if (left.kind !== SyntaxKind.PrefixOperator || left.operator !== SyntaxKind.TypeOfKeyword || + left.operand.kind !== SyntaxKind.Identifier || right.kind !== SyntaxKind.StringLiteral || + getResolvedSymbol(left.operand) !== symbol) { + return type; + } + var t = right.text; + var checkType: Type = t === "string" ? stringType : t === "number" ? numberType : t === "boolean" ? booleanType : emptyObjectType; + if (expr.operator === SyntaxKind.ExclamationEqualsEqualsToken) { + assumeTrue = !assumeTrue; + } + if (assumeTrue) { + // The assumed result is true. If check was for a primitive type, that type is the narrowed type. Otherwise we can + // remove the primitive types from the narrowed type. + return checkType === emptyObjectType ? subtractPrimitiveTypes(type, TypeFlags.String | TypeFlags.Number | TypeFlags.Boolean) : checkType; + } + else { + // The assumed result is false. If check was for a primitive type we can remove that type from the narrowed type. + // Otherwise we don't have enough information to do anything. + return checkType === emptyObjectType ? type : subtractPrimitiveTypes(type, checkType.flags); + } + } + + function narrowTypeByAnd(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { + if (assumeTrue) { + // The assumed result is true, therefore we narrow assuming each operand to be true. + return narrowType(narrowType(type, expr.left, true), expr.right, true); + } + else { + // The assumed result is true. This means either the first operand was false, or the first operand was true + // and the second operand was false. We narrow with those assumptions and union the two resulting types. + return getUnionType([narrowType(type, expr.left, false), narrowType(narrowType(type, expr.left, true), expr.right, false)]); + } + } + + function narrowTypeByOr(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { + if (assumeTrue) { + // The assumed result is true. This means either the first operand was true, or the first operand was false + // and the second operand was true. We narrow with those assumptions and union the two resulting types. + return getUnionType([narrowType(type, expr.left, true), narrowType(narrowType(type, expr.left, false), expr.right, true)]); + } + else { + // The assumed result is false, therefore we narrow assuming each operand to be false. + return narrowType(narrowType(type, expr.left, false), expr.right, false); + } + } + + function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { + // Check that we have variable symbol on the left + if (expr.left.kind !== SyntaxKind.Identifier || getResolvedSymbol(expr.left) !== symbol) { + return type; + } + // Check that right operand is a function type with a prototype property + var rightType = checkExpression(expr.right); + if (!isTypeSubtypeOf(rightType, globalFunctionType)) { + return type; + } + var prototypeProperty = getPropertyOfType(getApparentType(rightType), "prototype"); + if (!prototypeProperty) { + return type; + } + var prototypeType = getTypeOfSymbol(prototypeProperty); + // Narrow to type of prototype property if it is a subtype of current type + return isTypeSubtypeOf(prototypeType, type) ? prototypeType : type; + } + + // Narrow the given type based on the given expression having the assumed boolean value + function narrowType(type: Type, expr: Expression, assumeTrue: boolean): Type { + switch (expr.kind) { + case SyntaxKind.ParenExpression: + return narrowType(type, (expr).expression, assumeTrue); + case SyntaxKind.BinaryExpression: + var operator = (expr).operator; + if (operator === SyntaxKind.EqualsEqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken) { + return narrowTypeByEquality(type, expr, assumeTrue); + } + else if (operator === SyntaxKind.AmpersandAmpersandToken) { + return narrowTypeByAnd(type, expr, assumeTrue); + } + else if (operator === SyntaxKind.BarBarToken) { + return narrowTypeByOr(type, expr, assumeTrue); + } + else if (operator === SyntaxKind.InstanceOfKeyword) { + return narrowTypeByInstanceof(type, expr, assumeTrue); + } + break; + case SyntaxKind.PrefixOperator: + if ((expr).operator === SyntaxKind.ExclamationToken) { + return narrowType(type, (expr).operand, !assumeTrue); + } + break; + } + return type; + } + } + + function checkIdentifier(node: Identifier): Type { + var symbol = getResolvedSymbol(node); + if (symbol.flags & SymbolFlags.Import) { // Mark the import as referenced so that we emit it in the final .js file. // exception: identifiers that appear in type queries getSymbolLinks(symbol).referenced = !isInTypeQuery(node); } - getNodeLinks(node).resolvedSymbol = symbol; - checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); checkCollisionWithIndexVariableInGeneratedCode(node, node); - return getTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol)); + return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); } function captureLexicalThis(node: Node, container: Node): void { @@ -5134,8 +5375,8 @@ module ts { return numberType; } - function isTypeAnyTypeObjectTypeOrTypeParameter(type: Type): boolean { - return type === anyType || ((type.flags & (TypeFlags.ObjectType | TypeFlags.TypeParameter)) !== 0); + function isTypeAnyOrObjectOrTypeParameter(type: Type): boolean { + return (type.flags & (TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) !== 0; } function checkInstanceOfExpression(node: BinaryExpression, leftType: Type, rightType: Type): Type { @@ -5144,7 +5385,7 @@ module ts { // and the right operand to be of type Any or a subtype of the 'Function' interface type. // The result is always of the Boolean primitive type. // NOTE: do not raise error if leftType is unknown as related error was already reported - if (leftType !== unknownType && !isTypeAnyTypeObjectTypeOrTypeParameter(leftType)) { + if (leftType !== unknownType && !isTypeAnyOrObjectOrTypeParameter(leftType)) { error(node.left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported @@ -5162,7 +5403,7 @@ module ts { if (leftType !== anyType && leftType !== stringType && leftType !== numberType) { error(node.left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number); } - if (!isTypeAnyTypeObjectTypeOrTypeParameter(rightType)) { + if (!isTypeAnyOrObjectOrTypeParameter(rightType)) { error(node.right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -6338,7 +6579,7 @@ module ts { var exprType = checkExpression(node.expression); // unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved // in this case error about missing name is already reported - do not report extra one - if (!isTypeAnyTypeObjectTypeOrTypeParameter(exprType) && exprType !== unknownType) { + if (!isTypeAnyOrObjectOrTypeParameter(exprType) && exprType !== unknownType) { error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 0c322b49d25..f6691353c22 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -827,14 +827,15 @@ module ts { } export interface NodeLinks { - resolvedType?: Type; // Cached type of type node - resolvedSignature?: Signature; // Cached signature of signature node or call expression - resolvedSymbol?: Symbol; // Cached name resolution result - flags?: NodeCheckFlags; // Set of flags specific to Node - enumMemberValue?: number; // Constant value of enum member + resolvedType?: Type; // Cached type of type node + resolvedSignature?: Signature; // Cached signature of signature node or call expression + resolvedSymbol?: Symbol; // Cached name resolution result + flags?: NodeCheckFlags; // Set of flags specific to Node + enumMemberValue?: number; // Constant value of enum member isIllegalTypeReferenceInConstraint?: boolean; // Is type reference in constraint refers to the type parameter from the same list - isVisible?: boolean; // Is this node visible - localModuleName?: string; // Local name for module instance + isVisible?: boolean; // Is this node visible + localModuleName?: string; // Local name for module instance + assignmentChecks?: Map; // Cache of assignment checks } export enum TypeFlags { @@ -856,10 +857,10 @@ module ts { Anonymous = 0x00008000, // Anonymous FromSignature = 0x00010000, // Created for signature assignment check - Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null, + Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null, StringLike = String | StringLiteral, NumberLike = Number | Enum, - ObjectType = Class | Interface | Reference | Tuple | Union | Anonymous + ObjectType = Class | Interface | Reference | Tuple | Union | Anonymous, } // Properties common to all types From b8923b3de1a8319e0a87f8d792701d07d78e2d14 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 7 Oct 2014 22:48:16 -0700 Subject: [PATCH 03/23] Support symbol kind for union properties --- src/compiler/checker.ts | 10 ++++++++-- src/compiler/types.ts | 2 ++ src/services/services.ts | 11 +++++++++- .../completionEntryForUnionProperty.ts | 20 +++++++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/completionEntryForUnionProperty.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cf2099badde..523cd139248 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -92,7 +92,8 @@ module ts { getContextualType: getContextualType, getFullyQualifiedName: getFullyQualifiedName, getResolvedSignature: getResolvedSignature, - getEnumMemberValue: getEnumMemberValue + getEnumMemberValue: getEnumMemberValue, + getUnionTypesOfUnionProperty: getUnionTypesOfUnionProperty }; var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined"); @@ -1750,6 +1751,10 @@ module ts { return links.type; } + function getUnionTypesOfUnionProperty(symbol: Symbol): Type[] { + return (symbol.flags & SymbolFlags.UnionProperty) ? getSymbolLinks(symbol).unionType.types : undefined; + } + function getTypeOfSymbol(symbol: Symbol): Type { if (symbol.flags & (SymbolFlags.Variable | SymbolFlags.Property)) { return getTypeOfVariableOrParameterOrProperty(symbol); @@ -3583,7 +3588,8 @@ module ts { } function getBestCommonType(types: Type[], contextualType?: Type): Type { - return contextualType && isSupertypeOfEach(contextualType, types) ? contextualType : getUnionType(types); } + return contextualType && isSupertypeOfEach(contextualType, types) ? contextualType : getUnionType(types); + } function isTypeOfObjectLiteral(type: Type): boolean { return (type.flags & TypeFlags.Anonymous) && type.symbol && (type.symbol.flags & SymbolFlags.ObjectLiteral) ? true : false; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f6691353c22..0d943915e44 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -657,6 +657,8 @@ module ts { getContextualType(node: Node): Type; getResolvedSignature(node: CallExpression, candidatesOutArray?: Signature[]): Signature; + getUnionTypesOfUnionProperty(symbol: Symbol): Type[]; + // Returns the constant value of this enum member, or 'undefined' if the enum member has a // computed value. getEnumMemberValue(node: EnumMember): number; diff --git a/src/services/services.ts b/src/services/services.ts index 3e222450aa7..53e6f0e1401 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2284,8 +2284,16 @@ module ts { } } + function getConcreteSymbol(symbol: Symbol): Symbol { + if (symbol.flags & SymbolFlags.UnionProperty) { + var types = typeInfoResolver.getUnionTypesOfUnionProperty(symbol); + symbol = typeInfoResolver.getPropertyOfType(types[0], symbol.name); + } + return typeInfoResolver.getRootSymbol(symbol); + } + function getSymbolKind(symbol: Symbol): string { - var flags = typeInfoResolver.getRootSymbol(symbol).getFlags(); + var flags = getConcreteSymbol(symbol).getFlags(); if (flags & SymbolFlags.Module) return ScriptElementKind.moduleElement; if (flags & SymbolFlags.Class) return ScriptElementKind.classElement; @@ -2344,6 +2352,7 @@ module ts { } function getSymbolModifiers(symbol: Symbol): string { + symbol = getConcreteSymbol(symbol); return symbol && symbol.declarations && symbol.declarations.length > 0 ? getNodeModifiers(symbol.declarations[0]) : ScriptElementKindModifier.none; diff --git a/tests/cases/fourslash/completionEntryForUnionProperty.ts b/tests/cases/fourslash/completionEntryForUnionProperty.ts new file mode 100644 index 00000000000..6d5a3627a9c --- /dev/null +++ b/tests/cases/fourslash/completionEntryForUnionProperty.ts @@ -0,0 +1,20 @@ +/// + +////interface One { +//// commonProperty: number; +//// commonFunction(): number; +////} +//// +////interface Two { +//// commonProperty: string +//// commonFunction(): number; +////} +//// +////var x : One | Two; +//// +////x./**/ + +goTo.marker(); +verify.memberListContains("commonProperty", "string | number", undefined, undefined, "property"); +verify.memberListContains("commonFunction", "() => number", undefined, undefined, "method"); +verify.memberListCount(2); \ No newline at end of file From 5669f63430e42aad473a7b84b51ab71f792ac53f Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 7 Oct 2014 22:49:06 -0700 Subject: [PATCH 04/23] add test for quick info --- .../fourslash/quickinfoForUnionProperty.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/cases/fourslash/quickinfoForUnionProperty.ts diff --git a/tests/cases/fourslash/quickinfoForUnionProperty.ts b/tests/cases/fourslash/quickinfoForUnionProperty.ts new file mode 100644 index 00000000000..665d03f9435 --- /dev/null +++ b/tests/cases/fourslash/quickinfoForUnionProperty.ts @@ -0,0 +1,27 @@ +/// + +////interface One { +//// commonProperty: number; +//// commonFunction(): number; +////} +//// +////interface Two { +//// commonProperty: string +//// commonFunction(): number; +////} +//// +////var /*1*/x : One | Two; +//// +////x./*2*/commonProperty; +////x./*3*/commonFunction; + + +goTo.marker("1"); +verify.quickInfoIs("One | Two", "", "x", "var"); + + +goTo.marker("2"); +verify.quickInfoIs("string | number", "", "commonProperty", "property"); + +goTo.marker("3"); +verify.quickInfoIs("() => number", "", "commonFunction", "method"); From c439ae4a9d5e7931ce9d369f91d5350817654d46 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 7 Oct 2014 23:17:05 -0700 Subject: [PATCH 05/23] Add support for union properties in goto def --- src/services/services.ts | 39 ++++++++++++------- .../goToDefinitionUnionTypeProperty.ts | 24 ++++++++++++ .../goToDefinitionUnionTypeProperty2.ts | 25 ++++++++++++ 3 files changed, 75 insertions(+), 13 deletions(-) create mode 100644 tests/cases/fourslash/goToDefinitionUnionTypeProperty.ts create mode 100644 tests/cases/fourslash/goToDefinitionUnionTypeProperty2.ts diff --git a/src/services/services.ts b/src/services/services.ts index 53e6f0e1401..3fc2ae7f05a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2563,6 +2563,25 @@ module ts { return false; } + function getDefinitionFromSymbol(symbol: Symbol, location: Node, result: DefinitionInfo[]): void { + var declarations = symbol.getDeclarations(); + if (declarations) { + var symbolName = typeInfoResolver.symbolToString(symbol, location); + var symbolKind = getSymbolKind(symbol); + var containerSymbol = symbol.parent; + var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, location) : ""; + var containerKind = containerSymbol ? getSymbolKind(symbol) : ""; + + if (!tryAddConstructSignature(symbol, location, symbolKind, symbolName, containerName, result) && + !tryAddCallSignature(symbol, location, symbolKind, symbolName, containerName, result)) { + // Just add all the declarations. + forEach(declarations, declaration => { + result.push(getDefinitionInfo(declaration, symbolKind, symbolName, containerName)); + }); + } + } + } + synchronizeHostData(); filename = TypeScript.switchToForwardSlashes(filename); @@ -2601,26 +2620,20 @@ module ts { // Could not find a symbol e.g. node is string or number keyword, // or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol - if (!symbol || !(symbol.getDeclarations())) { + if (!symbol) { return undefined; } var result: DefinitionInfo[] = []; - var declarations = symbol.getDeclarations(); - var symbolName = typeInfoResolver.symbolToString(symbol, node); - var symbolKind = getSymbolKind(symbol); - var containerSymbol = symbol.parent; - var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, node) : ""; - var containerKind = containerSymbol ? getSymbolKind(symbol) : ""; - - if (!tryAddConstructSignature(symbol, node, symbolKind, symbolName, containerName, result) && - !tryAddCallSignature(symbol, node, symbolKind, symbolName, containerName, result)) { - // Just add all the declarations. - forEach(declarations, declaration => { - result.push(getDefinitionInfo(declaration, symbolKind, symbolName, containerName)); + if (symbol.flags & SymbolFlags.UnionProperty) { + forEach(typeInfoResolver.getUnionTypesOfUnionProperty(symbol), t => { + getDefinitionFromSymbol(typeInfoResolver.getPropertyOfType(t, symbol.name), node, result); }); } + else { + getDefinitionFromSymbol(symbol, node, result); + } return result; } diff --git a/tests/cases/fourslash/goToDefinitionUnionTypeProperty.ts b/tests/cases/fourslash/goToDefinitionUnionTypeProperty.ts new file mode 100644 index 00000000000..74b5e2aad8a --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionUnionTypeProperty.ts @@ -0,0 +1,24 @@ +/// + +////interface One { +//// /*propertyDefinition1*/commonProperty: number; +//// commonFunction(): number; +////} +//// +////interface Two { +//// /*propertyDefinition2*/commonProperty: string +//// commonFunction(): number; +////} +//// +////var x : One | Two; +//// +////x./*propertyReference*/commonProperty; +////x./*3*/commonFunction; + +goTo.marker("propertyReference"); +goTo.definition(0); +verify.caretAtMarker("propertyDefinition1"); + +goTo.marker("propertyReference"); +goTo.definition(1); +verify.caretAtMarker("propertyDefinition2"); diff --git a/tests/cases/fourslash/goToDefinitionUnionTypeProperty2.ts b/tests/cases/fourslash/goToDefinitionUnionTypeProperty2.ts new file mode 100644 index 00000000000..6536bb76e7d --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionUnionTypeProperty2.ts @@ -0,0 +1,25 @@ +/// +////interface HasAOrB { +//// /*propertyDefinition1*/a: string; +//// b: string; +////} +//// +////interface One { +//// common: { /*propertyDefinition2*/a : number; }; +////} +//// +////interface Two { +//// common: HasAOrB; +////} +//// +////var x : One | Two; +//// +////x.common./*propertyReference*/a; + +goTo.marker("propertyReference"); +goTo.definition(0); +verify.caretAtMarker("propertyDefinition1"); + +goTo.marker("propertyReference"); +goTo.definition(1); +verify.caretAtMarker("propertyDefinition2"); From 95584e91041f705a59be8b1c70e940cc0ee508a8 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 8 Oct 2014 06:56:25 -0700 Subject: [PATCH 06/23] Addressing CR feedback --- src/compiler/checker.ts | 107 +++++++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 41 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cf2099badde..47ee21c3cbf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1157,7 +1157,7 @@ module ts { } } - function writeTypeList(types: Type[], union?: boolean) { + function writeTypeList(types: Type[], union: boolean) { for (var i = 0; i < types.length; i++) { if (i > 0) { if (union) { @@ -1166,6 +1166,8 @@ module ts { writePunctuation(writer, union ? SyntaxKind.BarToken : SyntaxKind.CommaToken); writeSpace(writer); } + // Don't output function type literals in unions because '() => string | () => number' would be parsed + // as a function type that returns a union type. Instead output '{ (): string; } | { (): number; }'. writeType(types[i], /*allowFunctionOrConstructorTypeLiteral*/ !union); } } @@ -1181,14 +1183,14 @@ module ts { else { writeSymbol(type.target.symbol, writer, enclosingDeclaration, SymbolFlags.Type); writePunctuation(writer, SyntaxKind.LessThanToken); - writeTypeList(type.typeArguments); + writeTypeList(type.typeArguments, /*union*/ false); writePunctuation(writer, SyntaxKind.GreaterThanToken); } } function writeTupleType(type: TupleType) { writePunctuation(writer, SyntaxKind.OpenBracketToken); - writeTypeList(type.elementTypes); + writeTypeList(type.elementTypes, /*union*/ false); writePunctuation(writer, SyntaxKind.CloseBracketToken); } @@ -1744,7 +1746,7 @@ module ts { function getTypeOfUnionProperty(symbol: Symbol): Type { var links = getSymbolLinks(symbol); if (!links.type) { - var types = map(links.unionType.types, t => getTypeOfSymbol(getPropertyOfType(getApparentType(t), symbol.name) || undefinedSymbol)); + var types = map(links.unionType.types, t => getTypeOfSymbol(getPropertyOfType(getApparentType(t), symbol.name))); links.type = getUnionType(types); } return links.type; @@ -2069,25 +2071,37 @@ module ts { } function signatureListsIdentical(s: Signature[], t: Signature[]): boolean { - if (s.length !== t.length) return false; + if (s.length !== t.length) { + return false; + } for (var i = 0; i < s.length; i++) { - if (!compareSignatures(s[i], t[i], false, isTypeIdenticalTo)) return false; + if (!compareSignatures(s[i], t[i], /*compareReturnTypes*/ false, isTypeIdenticalTo)) { + return false; + } } return true; } + // If the lists of call or construct signatures in the given types are all identical except for return types, + // and if none of the signatures are generic, return a list of signatures that has substitutes a union of the + // return types of the corresponding signatures in each resulting signature. function getUnionSignatures(types: Type[], kind: SignatureKind): Signature[] { var signatureLists = map(types, t => getSignaturesOfType(t, kind)); - var baseSignatures = signatureLists[0]; - for (var i = 0; i < baseSignatures.length; i++) { - if (baseSignatures[i].typeParameters) return emptyArray; + var signatures = signatureLists[0]; + for (var i = 0; i < signatures.length; i++) { + if (signatures[i].typeParameters) { + return emptyArray; + } } for (var i = 1; i < signatureLists.length; i++) { - if (!signatureListsIdentical(baseSignatures, signatureLists[i])) return emptyArray; + if (!signatureListsIdentical(signatures, signatureLists[i])) { + return emptyArray; + } } - var result = map(baseSignatures, cloneSignature); + var result = map(signatures, cloneSignature); for (var i = 0; i < result.length; i++) { var s = result[i]; + // Clear resolved return type we possibly got from cloneSignature s.resolvedReturnType = undefined; s.unionSignatures = map(signatureLists, signatures => signatures[i]); } @@ -2098,7 +2112,9 @@ module ts { var indexTypes: Type[] = []; for (var i = 0; i < types.length; i++) { var indexType = getIndexTypeOfType(types[i], kind); - if (!indexType) return undefined; + if (!indexType) { + return undefined; + } indexTypes.push(indexType); } return getUnionType(indexTypes); @@ -2113,14 +2129,16 @@ module ts { } }); if (types.length <= 1) { - var res = types.length ? resolveObjectTypeMembers(types[0]) : emptyObjectType; - setObjectTypeMembers(type, res.members, res.callSignatures, res.constructSignatures, res.stringIndexType, res.numberIndexType); + var resolved = types.length ? resolveObjectTypeMembers(types[0]) : emptyObjectType; + setObjectTypeMembers(type, resolved.members, resolved.callSignatures, resolved.constructSignatures, resolved.stringIndexType, resolved.numberIndexType); return; } var members: SymbolTable = {}; forEach(getPropertiesOfType(types[0]), prop => { for (var i = 1; i < types.length; i++) { - if (!getPropertyOfType(types[i], prop.name)) return; + if (!getPropertyOfType(types[i], prop.name)) { + return; + } } var symbol = createSymbol(SymbolFlags.UnionProperty | SymbolFlags.Transient, prop.name); symbol.unionType = type; @@ -2662,7 +2680,9 @@ module ts { else { var i = 0; var id = type.id; - while (i < sortedSet.length && sortedSet[i].id < id) i++; + while (i < sortedSet.length && sortedSet[i].id < id) { + i++; + } if (i === sortedSet.length || sortedSet[i].id !== id) { sortedSet.splice(i, 0, type); } @@ -2677,7 +2697,9 @@ module ts { function isSubtypeOfAny(candidate: Type, types: Type[]): boolean { for (var i = 0, len = types.length; i < len; i++) { - if (candidate !== types[i] && isTypeSubtypeOf(candidate, types[i])) return true; + if (candidate !== types[i] && isTypeSubtypeOf(candidate, types[i])) { + return true; + } } return false; } @@ -3467,7 +3489,7 @@ module ts { return false; } for (var i = 0, len = sourceSignatures.length; i < len; ++i) { - if (!compareSignatures(sourceSignatures[i], targetSignatures[i], /*returnTypes*/ true, isRelatedTo)) { + if (!compareSignatures(sourceSignatures[i], targetSignatures[i], /*compareReturnTypes*/ true, isRelatedTo)) { return false; } } @@ -3535,7 +3557,7 @@ module ts { } } - function compareSignatures(source: Signature, target: Signature, returnTypes: boolean, compareTypes: (s: Type, t: Type) => boolean): boolean { + function compareSignatures(source: Signature, target: Signature, compareReturnTypes: boolean, compareTypes: (s: Type, t: Type) => boolean): boolean { if (source === target) { return true; } @@ -3568,7 +3590,7 @@ module ts { return false; } } - return !returnTypes || compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); + return !compareReturnTypes || compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); } function isSupertypeOfEach(candidate: Type, types: Type[]): boolean { @@ -3876,20 +3898,14 @@ module ts { if (type.flags & TypeFlags.Union) { var types = (type).types; if (forEach(types, t => t.flags & subtractMask)) { - var newTypes: Type[] = []; - forEach(types, t => { - if (!(t.flags & subtractMask)) { - newTypes.push(t); - } - }); - return getUnionType(newTypes); + return getUnionType(filter(types, t => !(t.flags & subtractMask))); } } return type; } // Check if a given variable is assigned within a given syntax node - function IsVariableAssignedWithin(symbol: Symbol, node: Node): boolean { + function isVariableAssignedWithin(symbol: Symbol, node: Node): boolean { var links = getNodeLinks(node); if (links.assignmentChecks) { var cachedResult = links.assignmentChecks[symbol.id]; @@ -3981,29 +3997,32 @@ module ts { case SyntaxKind.IfStatement: // In a branch of an if statement, narrow based on controlling expression if (child !== (node).expression) { - narrowedType = narrowType(type, (node).expression, child === (node).thenStatement); + narrowedType = narrowType(type, (node).expression, /*assumeTrue*/ child === (node).thenStatement); } break; case SyntaxKind.ConditionalExpression: // In a branch of a conditional expression, narrow based on controlling condition if (child !== (node).condition) { - narrowedType = narrowType(type, (node).condition, child === (node).whenTrue); + narrowedType = narrowType(type, (node).condition, /*assumeTrue*/ child === (node).whenTrue); } break; case SyntaxKind.BinaryExpression: // In the right operand of an && or ||, narrow based on left operand if (child === (node).right) { if ((node).operator === SyntaxKind.AmpersandAmpersandToken) { - narrowedType = narrowType(type, (node).left, true); + narrowedType = narrowType(type, (node).left, /*assumeTrue*/ true); } else if ((node).operator === SyntaxKind.BarBarToken) { - narrowedType = narrowType(type, (node).left, false); + narrowedType = narrowType(type, (node).left, /*assumeTrue*/ false); } } break; } // Only use narrowed type if construct contains no assignments to variable - if (narrowedType !== type && !IsVariableAssignedWithin(symbol, node)) { + if (narrowedType !== type) { + if (isVariableAssignedWithin(symbol, node)) { + break; + } type = narrowedType; } } @@ -4039,12 +4058,15 @@ module ts { function narrowTypeByAnd(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { if (assumeTrue) { // The assumed result is true, therefore we narrow assuming each operand to be true. - return narrowType(narrowType(type, expr.left, true), expr.right, true); + return narrowType(narrowType(type, expr.left, /*assumeTrue*/ true), expr.right, /*assumeTrue*/ true); } else { - // The assumed result is true. This means either the first operand was false, or the first operand was true + // The assumed result is false. This means either the first operand was false, or the first operand was true // and the second operand was false. We narrow with those assumptions and union the two resulting types. - return getUnionType([narrowType(type, expr.left, false), narrowType(narrowType(type, expr.left, true), expr.right, false)]); + return getUnionType([ + narrowType(type, expr.left, /*assumeTrue*/ false), + narrowType(narrowType(type, expr.left, /*assumeTrue*/ true), expr.right, /*assumeTrue*/ false) + ]); } } @@ -4052,17 +4074,20 @@ module ts { if (assumeTrue) { // The assumed result is true. This means either the first operand was true, or the first operand was false // and the second operand was true. We narrow with those assumptions and union the two resulting types. - return getUnionType([narrowType(type, expr.left, true), narrowType(narrowType(type, expr.left, false), expr.right, true)]); + return getUnionType([ + narrowType(type, expr.left, /*assumeTrue*/ true), + narrowType(narrowType(type, expr.left, /*assumeTrue*/ false), expr.right, /*assumeTrue*/ true) + ]); } else { // The assumed result is false, therefore we narrow assuming each operand to be false. - return narrowType(narrowType(type, expr.left, false), expr.right, false); + return narrowType(narrowType(type, expr.left, /*assumeTrue*/ false), expr.right, /*assumeTrue*/ false); } } function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { - // Check that we have variable symbol on the left - if (expr.left.kind !== SyntaxKind.Identifier || getResolvedSymbol(expr.left) !== symbol) { + // Check that assumed result is true and we have variable symbol on the left + if (!assumeTrue || expr.left.kind !== SyntaxKind.Identifier || getResolvedSymbol(expr.left) !== symbol) { return type; } // Check that right operand is a function type with a prototype property @@ -7198,7 +7223,7 @@ module ts { return checkArrayType(node); case SyntaxKind.TupleType: return checkTupleType(node); - case SyntaxKind.TupleType: + case SyntaxKind.UnionType: return checkUnionType(node); case SyntaxKind.FunctionDeclaration: return checkFunctionDeclaration(node); From fd5b80805e25bef9920ac6f39c327aadfb0ef251 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 8 Oct 2014 13:48:44 -0700 Subject: [PATCH 07/23] Accepting new baselines The new baselines all look correct to me, but obviously a number of the tests need to be updated to reflect union types and the new behavior of best common type. This commit does not cover that. --- .../reference/arrayBestCommonTypes.types | 12 +- .../arrayLiteralContextualType.errors.txt | 40 -- .../arrayLiteralContextualType.types | 86 ++++ ...ayLiteralWithMultipleBestCommonTypes.types | 4 +- .../reference/arrayLiterals.errors.txt | 56 +++ tests/baselines/reference/arrayLiterals.types | 150 ------ .../arrayLiteralsWithRecursiveGenerics.types | 4 +- ...stCommonTypeOfConditionalExpressions.types | 4 +- ...onTypeOfConditionalExpressions2.errors.txt | 17 +- .../conditionalExpression1.errors.txt | 11 +- ...onalOperatorWithoutIdenticalBCT.errors.txt | 67 ++- .../reference/contextualTyping21.errors.txt | 14 +- .../reference/contextualTyping30.errors.txt | 10 +- .../reference/contextualTyping33.errors.txt | 10 +- ...ontextualTypingOfArrayLiterals1.errors.txt | 14 +- ...lTypingOfConditionalExpression2.errors.txt | 17 +- ...lTypingWithFixedTypeParameters1.errors.txt | 7 +- .../contextuallyTypingOrOperator.types | 18 +- .../contextuallyTypingOrOperator2.types | 6 +- ...defaultBestCommonTypesHaveDecls.errors.txt | 6 +- tests/baselines/reference/enumBasics.types | 8 +- ...erInSignatureWithRestParameters.errors.txt | 8 + ...rameterInSignatureWithRestParameters.types | 13 - ...orStatementsMultipleInvalidDecl.errors.txt | 4 +- .../reference/generatedContextualTyping.types | 242 ++++----- ...nericArgumentCallSigAssignmentCompat.types | 2 +- .../genericCallWithArrayLiteralArgs.types | 6 +- ...cCallWithFunctionTypedArguments.errors.txt | 58 +++ ...enericCallWithFunctionTypedArguments.types | 173 ------- ...CallWithFunctionTypedArguments2.errors.txt | 50 ++ ...nericCallWithFunctionTypedArguments2.types | 161 ------ ...lWithGenericSignatureArguments2.errors.txt | 5 +- ...lWithGenericSignatureArguments3.errors.txt | 42 ++ ...icCallWithGenericSignatureArguments3.types | 202 -------- ...enericCallWithObjectLiteralArgs.errors.txt | 14 + .../genericCallWithObjectLiteralArgs.types | 49 -- ...CallWithObjectLiteralArguments1.errors.txt | 5 +- .../genericCallWithObjectTypeArgs.errors.txt | 27 + .../genericCallWithObjectTypeArgs.types | 68 --- .../genericCallWithObjectTypeArgs2.types | 16 +- ...thObjectTypeArgsAndConstraints3.errors.txt | 5 +- ...loadedConstructorTypedArguments.errors.txt | 54 ++ ...hOverloadedConstructorTypedArguments.types | 173 ------- ...ithFunctionTypedMemberArguments.errors.txt | 81 +++ ...lassWithFunctionTypedMemberArguments.types | 297 ----------- .../reference/genericRestArgs.errors.txt | 8 +- .../genericTypeArgumentInference1.types | 6 +- .../genericsManyTypeParameters.types | 4 +- .../heterogeneousArrayAndOverloads.errors.txt | 10 +- .../heterogeneousArrayLiterals.types | 100 ++-- ...lidMultipleVariableDeclarations.errors.txt | 4 +- .../logicalOrOperatorWithEveryType.types | 160 +++--- .../logicalOrOperatorWithTypeParameters.types | 16 +- ...citTypeParameterAndArgumentType.errors.txt | 10 +- .../nonContextuallyTypedLogicalOr.errors.txt | 22 - .../nonContextuallyTypedLogicalOr.types | 39 ++ ...rConstrainsPropertyDeclarations.errors.txt | 10 +- ...ConstrainsPropertyDeclarations2.errors.txt | 12 +- .../reference/parser15.4.4.14-9-2.errors.txt | 5 +- .../reference/promisePermutations.errors.txt | 26 +- .../reference/promisePermutations2.errors.txt | 17 +- .../reference/promisePermutations3.errors.txt | 23 +- ...rConstrainsPropertyDeclarations.errors.txt | 10 +- .../subtypesOfTypeParameter.errors.txt | 110 +--- ...OfTypeParameterWithConstraints2.errors.txt | 80 +-- ...OfTypeParameterWithConstraints3.errors.txt | 20 +- ...OfTypeParameterWithConstraints4.errors.txt | 26 +- ...rameterWithRecursiveConstraints.errors.txt | 74 +-- .../subtypingWithCallSignatures2.types | 12 +- .../subtypingWithCallSignatures3.types | 12 +- .../subtypingWithCallSignatures4.types | 16 +- .../subtypingWithConstructSignatures2.types | 20 +- .../subtypingWithConstructSignatures3.types | 12 +- .../subtypingWithConstructSignatures4.types | 16 +- ...ngWithObjectMembersOptionality2.errors.txt | 7 +- .../reference/targetTypeTest3.errors.txt | 10 +- .../baselines/reference/throwStatements.types | 2 +- ...ommaInHeterogenousArrayLiteral1.errors.txt | 20 +- .../baselines/reference/tupleTypes.errors.txt | 30 +- .../reference/typeArgInference2.errors.txt | 18 + .../reference/typeArgInference2.types | 61 --- .../typeArgInference2WithError.errors.txt | 6 +- .../typeArgumentInference.errors.txt | 109 ++++ .../reference/typeArgumentInference.types | 468 ------------------ ...entInferenceConstructSignatures.errors.txt | 8 +- ...tInferenceTransitiveConstraints.errors.txt | 5 +- ...renceWithConstraintAsCommonRoot.errors.txt | 13 + ...tInferenceWithConstraintAsCommonRoot.types | 40 -- ...rgumentInferenceWithConstraints.errors.txt | 8 +- ...eInferenceConflictingCandidates.errors.txt | 9 + .../typeInferenceConflictingCandidates.types | 21 - .../typeParameterAsElementType.types | 4 +- .../baselines/reference/underscoreTest1.types | 12 +- 93 files changed, 1293 insertions(+), 2754 deletions(-) delete mode 100644 tests/baselines/reference/arrayLiteralContextualType.errors.txt create mode 100644 tests/baselines/reference/arrayLiteralContextualType.types create mode 100644 tests/baselines/reference/arrayLiterals.errors.txt delete mode 100644 tests/baselines/reference/arrayLiterals.types create mode 100644 tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.errors.txt delete mode 100644 tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.types create mode 100644 tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt delete mode 100644 tests/baselines/reference/genericCallWithFunctionTypedArguments.types create mode 100644 tests/baselines/reference/genericCallWithFunctionTypedArguments2.errors.txt delete mode 100644 tests/baselines/reference/genericCallWithFunctionTypedArguments2.types create mode 100644 tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt delete mode 100644 tests/baselines/reference/genericCallWithGenericSignatureArguments3.types create mode 100644 tests/baselines/reference/genericCallWithObjectLiteralArgs.errors.txt delete mode 100644 tests/baselines/reference/genericCallWithObjectLiteralArgs.types create mode 100644 tests/baselines/reference/genericCallWithObjectTypeArgs.errors.txt delete mode 100644 tests/baselines/reference/genericCallWithObjectTypeArgs.types create mode 100644 tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.errors.txt delete mode 100644 tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.types create mode 100644 tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.errors.txt delete mode 100644 tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.types delete mode 100644 tests/baselines/reference/nonContextuallyTypedLogicalOr.errors.txt create mode 100644 tests/baselines/reference/nonContextuallyTypedLogicalOr.types create mode 100644 tests/baselines/reference/typeArgInference2.errors.txt delete mode 100644 tests/baselines/reference/typeArgInference2.types create mode 100644 tests/baselines/reference/typeArgumentInference.errors.txt delete mode 100644 tests/baselines/reference/typeArgumentInference.types create mode 100644 tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.errors.txt delete mode 100644 tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.types create mode 100644 tests/baselines/reference/typeInferenceConflictingCandidates.errors.txt delete mode 100644 tests/baselines/reference/typeInferenceConflictingCandidates.types diff --git a/tests/baselines/reference/arrayBestCommonTypes.types b/tests/baselines/reference/arrayBestCommonTypes.types index a0f407358c3..6495b7df6a6 100644 --- a/tests/baselines/reference/arrayBestCommonTypes.types +++ b/tests/baselines/reference/arrayBestCommonTypes.types @@ -294,22 +294,22 @@ class f { >base2 : typeof base2 var b1 = [ baseObj, base2Obj, ifaceObj ]; ->b1 : base[] ->[ baseObj, base2Obj, ifaceObj ] : base[] +>b1 : iface[] +>[ baseObj, base2Obj, ifaceObj ] : iface[] >baseObj : base >base2Obj : base2 >ifaceObj : iface var b2 = [ base2Obj, baseObj, ifaceObj ]; ->b2 : base2[] ->[ base2Obj, baseObj, ifaceObj ] : base2[] +>b2 : iface[] +>[ base2Obj, baseObj, ifaceObj ] : iface[] >base2Obj : base2 >baseObj : base >ifaceObj : iface var b3 = [ baseObj, ifaceObj, base2Obj ]; ->b3 : base[] ->[ baseObj, ifaceObj, base2Obj ] : base[] +>b3 : iface[] +>[ baseObj, ifaceObj, base2Obj ] : iface[] >baseObj : base >ifaceObj : iface >base2Obj : base2 diff --git a/tests/baselines/reference/arrayLiteralContextualType.errors.txt b/tests/baselines/reference/arrayLiteralContextualType.errors.txt deleted file mode 100644 index 5f661647d9f..00000000000 --- a/tests/baselines/reference/arrayLiteralContextualType.errors.txt +++ /dev/null @@ -1,40 +0,0 @@ -tests/cases/compiler/arrayLiteralContextualType.ts(28,5): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'IAnimal[]'. - Type '{}' is not assignable to type 'IAnimal'. -tests/cases/compiler/arrayLiteralContextualType.ts(29,5): error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ [x: number]: IAnimal; }'. - - -==== tests/cases/compiler/arrayLiteralContextualType.ts (2 errors) ==== - interface IAnimal { - name: string; - } - - class Giraffe { - name = "Giraffe"; - neckLength = "3m"; - } - - class Elephant { - name = "Elephant"; - trunkDiameter = "20cm"; - } - - function foo(animals: IAnimal[]) { } - function bar(animals: { [n: number]: IAnimal }) { } - - foo([ - new Giraffe(), - new Elephant() - ]); // Legal because of the contextual type IAnimal provided by the parameter - bar([ - new Giraffe(), - new Elephant() - ]); // Legal because of the contextual type IAnimal provided by the parameter - - var arr = [new Giraffe(), new Elephant()]; - foo(arr); // Error because of no contextual type - ~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'IAnimal[]'. -!!! error TS2345: Type '{}' is not assignable to type 'IAnimal'. - bar(arr); // Error because of no contextual type - ~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ [x: number]: IAnimal; }'. \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiteralContextualType.types b/tests/baselines/reference/arrayLiteralContextualType.types new file mode 100644 index 00000000000..3d5330d00c9 --- /dev/null +++ b/tests/baselines/reference/arrayLiteralContextualType.types @@ -0,0 +1,86 @@ +=== tests/cases/compiler/arrayLiteralContextualType.ts === +interface IAnimal { +>IAnimal : IAnimal + + name: string; +>name : string +} + +class Giraffe { +>Giraffe : Giraffe + + name = "Giraffe"; +>name : string + + neckLength = "3m"; +>neckLength : string +} + +class Elephant { +>Elephant : Elephant + + name = "Elephant"; +>name : string + + trunkDiameter = "20cm"; +>trunkDiameter : string +} + +function foo(animals: IAnimal[]) { } +>foo : (animals: IAnimal[]) => void +>animals : IAnimal[] +>IAnimal : IAnimal + +function bar(animals: { [n: number]: IAnimal }) { } +>bar : (animals: { [x: number]: IAnimal; }) => void +>animals : { [x: number]: IAnimal; } +>n : number +>IAnimal : IAnimal + +foo([ +>foo([ new Giraffe(), new Elephant()]) : void +>foo : (animals: IAnimal[]) => void +>[ new Giraffe(), new Elephant()] : IAnimal[] + + new Giraffe(), +>new Giraffe() : Giraffe +>Giraffe : typeof Giraffe + + new Elephant() +>new Elephant() : Elephant +>Elephant : typeof Elephant + +]); // Legal because of the contextual type IAnimal provided by the parameter +bar([ +>bar([ new Giraffe(), new Elephant()]) : void +>bar : (animals: { [x: number]: IAnimal; }) => void +>[ new Giraffe(), new Elephant()] : IAnimal[] + + new Giraffe(), +>new Giraffe() : Giraffe +>Giraffe : typeof Giraffe + + new Elephant() +>new Elephant() : Elephant +>Elephant : typeof Elephant + +]); // Legal because of the contextual type IAnimal provided by the parameter + +var arr = [new Giraffe(), new Elephant()]; +>arr : Array +>[new Giraffe(), new Elephant()] : Array +>new Giraffe() : Giraffe +>Giraffe : typeof Giraffe +>new Elephant() : Elephant +>Elephant : typeof Elephant + +foo(arr); // Error because of no contextual type +>foo(arr) : void +>foo : (animals: IAnimal[]) => void +>arr : Array + +bar(arr); // Error because of no contextual type +>bar(arr) : void +>bar : (animals: { [x: number]: IAnimal; }) => void +>arr : Array + diff --git a/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types b/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types index 7729b280160..49b65a86aa6 100644 --- a/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types +++ b/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types @@ -23,8 +23,8 @@ var as = [a, b]; // { x: number; y?: number };[] >b : { x: number; z?: number; } var bs = [b, a]; // { x: number; z?: number };[] ->bs : { x: number; z?: number; }[] ->[b, a] : { x: number; z?: number; }[] +>bs : { x: number; y?: number; }[] +>[b, a] : { x: number; y?: number; }[] >b : { x: number; z?: number; } >a : { x: number; y?: number; } diff --git a/tests/baselines/reference/arrayLiterals.errors.txt b/tests/baselines/reference/arrayLiterals.errors.txt new file mode 100644 index 00000000000..65666a50ce8 --- /dev/null +++ b/tests/baselines/reference/arrayLiterals.errors.txt @@ -0,0 +1,56 @@ +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts(4,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr1' must be of type 'Array', but here has type '{}[]'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts(7,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'Array', but here has type '{}[]'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts(33,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'context2' must be of type 'Array<{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }>', but here has type '{}[]'. + + +==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts (3 errors) ==== + // Empty array literal with no contextual type has type Undefined[] + + var arr1= [[], [1], ['']]; + var arr1: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK + ~~~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr1' must be of type 'Array', but here has type '{}[]'. + + var arr2 = [[null], [1], ['']]; + var arr2: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK + ~~~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'Array', but here has type '{}[]'. + + + // Array literal with elements of only EveryType E has type E[] + var stringArrArr = [[''], [""]]; + var stringArrArr: string[][]; + + var stringArr = ['', ""]; + var stringArr: string[]; + + var numberArr = [0, 0.0, 0x00, 1e1]; + var numberArr: number[]; + + var boolArr = [false, true, false, true]; + var boolArr: boolean[]; + + class C { private p; } + var classArr = [new C(), new C()]; + var classArr: C[]; // Should be OK + + var classTypeArray = [C, C, C]; + var classTypeArray: Array; // Should OK, not be a parse error + + // Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[] + var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; + var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; + var context2: Array<{}>; // Should be OK + ~~~~~~~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'context2' must be of type 'Array<{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }>', but here has type '{}[]'. + + // Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[] + class Base { private p; } + class Derived1 extends Base { private m }; + class Derived2 extends Base { private n }; + var context3: Base[] = [new Derived1(), new Derived2()]; + + // Contextual type C with numeric index signature of type Base makes array literal of Derived1 and Derived2 have type Base[] + var context4: Base[] = [new Derived1(), new Derived1()]; + + \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiterals.types b/tests/baselines/reference/arrayLiterals.types deleted file mode 100644 index 29dd1b19970..00000000000 --- a/tests/baselines/reference/arrayLiterals.types +++ /dev/null @@ -1,150 +0,0 @@ -=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts === -// Empty array literal with no contextual type has type Undefined[] - -var arr1= [[], [1], ['']]; ->arr1 : {}[] ->[[], [1], ['']] : {}[] ->[] : undefined[] ->[1] : number[] ->[''] : string[] - -var arr1: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK ->arr1 : {}[] - -var arr2 = [[null], [1], ['']]; ->arr2 : {}[] ->[[null], [1], ['']] : {}[] ->[null] : null[] ->[1] : number[] ->[''] : string[] - -var arr2: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK ->arr2 : {}[] - - -// Array literal with elements of only EveryType E has type E[] -var stringArrArr = [[''], [""]]; ->stringArrArr : string[][] ->[[''], [""]] : string[][] ->[''] : string[] ->[""] : string[] - -var stringArrArr: string[][]; ->stringArrArr : string[][] - -var stringArr = ['', ""]; ->stringArr : string[] ->['', ""] : string[] - -var stringArr: string[]; ->stringArr : string[] - -var numberArr = [0, 0.0, 0x00, 1e1]; ->numberArr : number[] ->[0, 0.0, 0x00, 1e1] : number[] - -var numberArr: number[]; ->numberArr : number[] - -var boolArr = [false, true, false, true]; ->boolArr : boolean[] ->[false, true, false, true] : boolean[] - -var boolArr: boolean[]; ->boolArr : boolean[] - -class C { private p; } ->C : C ->p : any - -var classArr = [new C(), new C()]; ->classArr : C[] ->[new C(), new C()] : C[] ->new C() : C ->C : typeof C ->new C() : C ->C : typeof C - -var classArr: C[]; // Should be OK ->classArr : C[] ->C : C - -var classTypeArray = [C, C, C]; ->classTypeArray : typeof C[] ->[C, C, C] : typeof C[] ->C : typeof C ->C : typeof C ->C : typeof C - -var classTypeArray: Array; // Should OK, not be a parse error ->classTypeArray : typeof C[] ->Array : T[] ->C : typeof C - -// Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[] -var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; ->context1 : { [x: number]: { a: string; b: number; }; } ->n : number ->a : string ->b : number ->[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : { a: string; b: number; }[] ->{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; } ->a : string ->b : number ->c : string ->{ a: "", b: 3, c: 0 } : { a: string; b: number; c: number; } ->a : string ->b : number ->c : number - -var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; ->context2 : {}[] ->[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : {}[] ->{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; } ->a : string ->b : number ->c : string ->{ a: "", b: 3, c: 0 } : { a: string; b: number; c: number; } ->a : string ->b : number ->c : number - -var context2: Array<{}>; // Should be OK ->context2 : {}[] ->Array : T[] - -// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[] -class Base { private p; } ->Base : Base ->p : any - -class Derived1 extends Base { private m }; ->Derived1 : Derived1 ->Base : Base ->m : any - -class Derived2 extends Base { private n }; ->Derived2 : Derived2 ->Base : Base ->n : any - -var context3: Base[] = [new Derived1(), new Derived2()]; ->context3 : Base[] ->Base : Base ->[new Derived1(), new Derived2()] : Base[] ->new Derived1() : Derived1 ->Derived1 : typeof Derived1 ->new Derived2() : Derived2 ->Derived2 : typeof Derived2 - -// Contextual type C with numeric index signature of type Base makes array literal of Derived1 and Derived2 have type Base[] -var context4: Base[] = [new Derived1(), new Derived1()]; ->context4 : Base[] ->Base : Base ->[new Derived1(), new Derived1()] : Base[] ->new Derived1() : Derived1 ->Derived1 : typeof Derived1 ->new Derived1() : Derived1 ->Derived1 : typeof Derived1 - - diff --git a/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types b/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types index becff7617b7..e99ca18673e 100644 --- a/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types +++ b/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types @@ -61,8 +61,8 @@ var xs = [list, myList]; // {}[] >myList : MyList var ys = [list, list2]; // {}[] ->ys : {}[] ->[list, list2] : {}[] +>ys : Array | List> +>[list, list2] : Array | List> >list : List >list2 : List diff --git a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types index 3deeae69bbe..18fe6efb8ce 100644 --- a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types +++ b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types @@ -54,8 +54,8 @@ var r4 = true ? a : b; // typeof a >b : { x: number; z?: number; } var r5 = true ? b : a; // typeof b ->r5 : { x: number; z?: number; } ->true ? b : a : { x: number; z?: number; } +>r5 : { x: number; y?: number; } +>true ? b : a : { x: number; y?: number; } >b : { x: number; z?: number; } >a : { x: number; y?: number; } diff --git a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.errors.txt b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.errors.txt index 532a40becd9..83f4678c8f3 100644 --- a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.errors.txt +++ b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.errors.txt @@ -1,14 +1,9 @@ -tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(11,10): error TS2367: No best common type exists between 'number' and 'string'. -tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(12,10): error TS2367: No best common type exists between 'Derived' and 'Derived2'. -tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(15,12): error TS2367: No best common type exists between 'T' and 'U'. tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(18,15): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(19,12): error TS2367: No best common type exists between 'T' and 'U'. tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(22,15): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(22,28): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(23,12): error TS2367: No best common type exists between 'T' and 'U'. -==== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts (8 errors) ==== +==== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts (3 errors) ==== // conditional expressions return the best common type of the branches plus contextual type (using the first candidate if multiple BCTs exist) // these are errors @@ -20,24 +15,16 @@ tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfC var derived2: Derived2; var r2 = true ? 1 : ''; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'number' and 'string'. var r9 = true ? derived : derived2; - ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Derived' and 'Derived2'. function foo(t: T, u: U) { return true ? t : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. } function foo2(t: T, u: U) { // Error for referencing own type parameter ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. return true ? t : u; // Ok because BCT(T, U) = U - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. } function foo3(t: T, u: U) { @@ -46,6 +33,4 @@ tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfC ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. return true ? t : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. } \ No newline at end of file diff --git a/tests/baselines/reference/conditionalExpression1.errors.txt b/tests/baselines/reference/conditionalExpression1.errors.txt index 542b660ba42..30703c7169e 100644 --- a/tests/baselines/reference/conditionalExpression1.errors.txt +++ b/tests/baselines/reference/conditionalExpression1.errors.txt @@ -1,10 +1,9 @@ -tests/cases/compiler/conditionalExpression1.ts(1,5): error TS2323: Type '{}' is not assignable to type 'boolean'. -tests/cases/compiler/conditionalExpression1.ts(1,19): error TS2367: No best common type exists between 'number' and 'string'. +tests/cases/compiler/conditionalExpression1.ts(1,5): error TS2322: Type 'string | number' is not assignable to type 'boolean': + Type 'string' is not assignable to type 'boolean'. -==== tests/cases/compiler/conditionalExpression1.ts (2 errors) ==== +==== tests/cases/compiler/conditionalExpression1.ts (1 errors) ==== var x: boolean = (true ? 1 : ""); // should be an error ~ -!!! error TS2323: Type '{}' is not assignable to type 'boolean'. - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'number' and 'string'. \ No newline at end of file +!!! error TS2322: Type 'string | number' is not assignable to type 'boolean': +!!! error TS2322: Type 'string' is not assignable to type 'boolean'. \ No newline at end of file diff --git a/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt b/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt index 7db921cbe1a..33905a2cdad 100644 --- a/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt +++ b/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt @@ -1,20 +1,21 @@ -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(12,1): error TS2367: No best common type exists between 'A' and 'B'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(13,15): error TS2367: No best common type exists between 'A' and 'B'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,5): error TS2322: Type '{}' is not assignable to type 'A': - Property 'propertyA' is missing in type '{}'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,18): error TS2366: No best common type exists between 'A', 'A', and 'B'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(17,5): error TS2322: Type '{}' is not assignable to type 'B': - Property 'propertyB' is missing in type '{}'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(17,18): error TS2366: No best common type exists between 'B', 'A', and 'B'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,5): error TS2323: Type '{}' is not assignable to type '(t: X) => number'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,33): error TS2366: No best common type exists between '(t: X) => number', '(m: X) => number', and '(n: X) => string'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,5): error TS2323: Type '{}' is not assignable to type '(t: X) => string'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,33): error TS2366: No best common type exists between '(t: X) => string', '(m: X) => number', and '(n: X) => string'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(21,5): error TS2323: Type '{}' is not assignable to type '(t: X) => boolean'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(21,34): error TS2366: No best common type exists between '(t: X) => boolean', '(m: X) => number', and '(n: X) => string'. +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,5): error TS2322: Type 'A | B' is not assignable to type 'A': + Type 'B' is not assignable to type 'A': + Property 'propertyA' is missing in type 'B'. +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(17,5): error TS2322: Type 'A | B' is not assignable to type 'B': + Type 'A' is not assignable to type 'B': + Property 'propertyB' is missing in type 'A'. +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,5): error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => number': + Type '(n: X) => string' is not assignable to type '(t: X) => number': + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,5): error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => string': + Type '(m: X) => number' is not assignable to type '(t: X) => string': + Type 'number' is not assignable to type 'string'. +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(21,5): error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => boolean': + Type '(m: X) => number' is not assignable to type '(t: X) => boolean': + Type 'number' is not assignable to type 'boolean'. -==== tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts (12 errors) ==== +==== tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts (5 errors) ==== //Cond ? Expr1 : Expr2, Expr1 and Expr2 have no identical best common type class X { propertyX: any; propertyX1: number; propertyX2: string }; class A extends X { propertyA: number }; @@ -27,38 +28,32 @@ tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithou //Expect to have compiler errors //Be not contextually typed true ? a : b; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'A' and 'B'. var result1 = true ? a : b; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'A' and 'B'. //Be contextually typed and and bct is not identical var result2: A = true ? a : b; ~~~~~~~ -!!! error TS2322: Type '{}' is not assignable to type 'A': -!!! error TS2322: Property 'propertyA' is missing in type '{}'. - ~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between 'A', 'A', and 'B'. +!!! error TS2322: Type 'A | B' is not assignable to type 'A': +!!! error TS2322: Type 'B' is not assignable to type 'A': +!!! error TS2322: Property 'propertyA' is missing in type 'B'. var result3: B = true ? a : b; ~~~~~~~ -!!! error TS2322: Type '{}' is not assignable to type 'B': -!!! error TS2322: Property 'propertyB' is missing in type '{}'. - ~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between 'B', 'A', and 'B'. +!!! error TS2322: Type 'A | B' is not assignable to type 'B': +!!! error TS2322: Type 'A' is not assignable to type 'B': +!!! error TS2322: Property 'propertyB' is missing in type 'A'. var result4: (t: X) => number = true ? (m) => m.propertyX1 : (n) => n.propertyX2; ~~~~~~~ -!!! error TS2323: Type '{}' is not assignable to type '(t: X) => number'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between '(t: X) => number', '(m: X) => number', and '(n: X) => string'. +!!! error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => number': +!!! error TS2322: Type '(n: X) => string' is not assignable to type '(t: X) => number': +!!! error TS2322: Type 'string' is not assignable to type 'number'. var result5: (t: X) => string = true ? (m) => m.propertyX1 : (n) => n.propertyX2; ~~~~~~~ -!!! error TS2323: Type '{}' is not assignable to type '(t: X) => string'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between '(t: X) => string', '(m: X) => number', and '(n: X) => string'. +!!! error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => string': +!!! error TS2322: Type '(m: X) => number' is not assignable to type '(t: X) => string': +!!! error TS2322: Type 'number' is not assignable to type 'string'. var result6: (t: X) => boolean = true ? (m) => m.propertyX1 : (n) => n.propertyX2; ~~~~~~~ -!!! error TS2323: Type '{}' is not assignable to type '(t: X) => boolean'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between '(t: X) => boolean', '(m: X) => number', and '(n: X) => string'. \ No newline at end of file +!!! error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => boolean': +!!! error TS2322: Type '(m: X) => number' is not assignable to type '(t: X) => boolean': +!!! error TS2322: Type 'number' is not assignable to type 'boolean'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping21.errors.txt b/tests/baselines/reference/contextualTyping21.errors.txt index 999cfcbd769..620b0635d12 100644 --- a/tests/baselines/reference/contextualTyping21.errors.txt +++ b/tests/baselines/reference/contextualTyping21.errors.txt @@ -1,11 +1,13 @@ -tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type '{}[]' is not assignable to type '{ id: number; }[]': - Type '{}' is not assignable to type '{ id: number; }': - Property 'id' is missing in type '{}'. +tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type 'Array' is not assignable to type '{ id: number; }[]': + Type 'number | { id: number; }' is not assignable to type '{ id: number; }': + Type 'number' is not assignable to type '{ id: number; }': + Property 'id' is missing in type 'Number'. ==== tests/cases/compiler/contextualTyping21.ts (1 errors) ==== var foo:{id:number;}[] = [{id:1}]; foo = [{id:1}, 1]; ~~~ -!!! error TS2322: Type '{}[]' is not assignable to type '{ id: number; }[]': -!!! error TS2322: Type '{}' is not assignable to type '{ id: number; }': -!!! error TS2322: Property 'id' is missing in type '{}'. \ No newline at end of file +!!! error TS2322: Type 'Array' is not assignable to type '{ id: number; }[]': +!!! error TS2322: Type 'number | { id: number; }' is not assignable to type '{ id: number; }': +!!! error TS2322: Type 'number' is not assignable to type '{ id: number; }': +!!! error TS2322: Property 'id' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping30.errors.txt b/tests/baselines/reference/contextualTyping30.errors.txt index 3b2fbc8aac6..4c8d87d41b6 100644 --- a/tests/baselines/reference/contextualTyping30.errors.txt +++ b/tests/baselines/reference/contextualTyping30.errors.txt @@ -1,9 +1,11 @@ -tests/cases/compiler/contextualTyping30.ts(1,37): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. - Type '{}' is not assignable to type 'number'. +tests/cases/compiler/contextualTyping30.ts(1,37): error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. ==== tests/cases/compiler/contextualTyping30.ts (1 errors) ==== function foo(param:number[]){}; foo([1, "a"]); ~~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type '{}' is not assignable to type 'number'. \ No newline at end of file +!!! error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number': +!!! error TS2345: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping33.errors.txt b/tests/baselines/reference/contextualTyping33.errors.txt index 8f83fc37ab1..82799037ec6 100644 --- a/tests/baselines/reference/contextualTyping33.errors.txt +++ b/tests/baselines/reference/contextualTyping33.errors.txt @@ -1,9 +1,11 @@ -tests/cases/compiler/contextualTyping33.ts(1,66): error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'. - Type '{}' is not assignable to type '{ (): number; (i: number): number; }'. +tests/cases/compiler/contextualTyping33.ts(1,66): error TS2345: Argument of type 'Array<{ (): number; } | { (): string; }>' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'. + Type '{ (): number; } | { (): string; }' is not assignable to type '{ (): number; (i: number): number; }': + Type '() => string' is not assignable to type '{ (): number; (i: number): number; }'. ==== tests/cases/compiler/contextualTyping33.ts (1 errors) ==== function foo(param: {():number; (i:number):number; }[]) { }; foo([function(){return 1;}, function(){return "foo"}]); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'. -!!! error TS2345: Type '{}' is not assignable to type '{ (): number; (i: number): number; }'. \ No newline at end of file +!!! error TS2345: Argument of type 'Array<{ (): number; } | { (): string; }>' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'. +!!! error TS2345: Type '{ (): number; } | { (): string; }' is not assignable to type '{ (): number; (i: number): number; }': +!!! error TS2345: Type '() => string' is not assignable to type '{ (): number; (i: number): number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt b/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt index 0f9fc64536b..cb3b439681e 100644 --- a/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt +++ b/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt @@ -1,7 +1,8 @@ -tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type '{}[]' is not assignable to type 'I': +tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type 'Array' is not assignable to type 'I': Index signatures are incompatible: - Type '{}' is not assignable to type 'Date': - Property 'toDateString' is missing in type '{}'. + Type 'number | Date' is not assignable to type 'Date': + Type 'number' is not assignable to type 'Date': + Property 'toDateString' is missing in type 'Number'. ==== tests/cases/compiler/contextualTypingOfArrayLiterals1.ts (1 errors) ==== @@ -11,10 +12,11 @@ tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Typ var x3: I = [new Date(), 1]; ~~ -!!! error TS2322: Type '{}[]' is not assignable to type 'I': +!!! error TS2322: Type 'Array' is not assignable to type 'I': !!! error TS2322: Index signatures are incompatible: -!!! error TS2322: Type '{}' is not assignable to type 'Date': -!!! error TS2322: Property 'toDateString' is missing in type '{}'. +!!! error TS2322: Type 'number | Date' is not assignable to type 'Date': +!!! error TS2322: Type 'number' is not assignable to type 'Date': +!!! error TS2322: Property 'toDateString' is missing in type 'Number'. var r2 = x3[1]; r2.getDate(); \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingOfConditionalExpression2.errors.txt b/tests/baselines/reference/contextualTypingOfConditionalExpression2.errors.txt index c433bd1d8ca..574e25c6f45 100644 --- a/tests/baselines/reference/contextualTypingOfConditionalExpression2.errors.txt +++ b/tests/baselines/reference/contextualTypingOfConditionalExpression2.errors.txt @@ -1,8 +1,11 @@ -tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,5): error TS2323: Type '{}' is not assignable to type '(a: A) => void'. -tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,26): error TS2366: No best common type exists between '(a: A) => void', '(a: C) => number', and '(b: number) => void'. +tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,5): error TS2322: Type '{ (a: C): number; } | { (b: number): void; }' is not assignable to type '(a: A) => void': + Type '(b: number) => void' is not assignable to type '(a: A) => void': + Types of parameters 'b' and 'a' are incompatible: + Type 'number' is not assignable to type 'A': + Property 'foo' is missing in type 'Number'. -==== tests/cases/compiler/contextualTypingOfConditionalExpression2.ts (2 errors) ==== +==== tests/cases/compiler/contextualTypingOfConditionalExpression2.ts (1 errors) ==== class A { foo: number; } @@ -15,7 +18,9 @@ tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,26): error T var x2: (a: A) => void = true ? (a: C) => a.foo : (b: number) => { }; ~~ -!!! error TS2323: Type '{}' is not assignable to type '(a: A) => void'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between '(a: A) => void', '(a: C) => number', and '(b: number) => void'. +!!! error TS2322: Type '{ (a: C): number; } | { (b: number): void; }' is not assignable to type '(a: A) => void': +!!! error TS2322: Type '(b: number) => void' is not assignable to type '(a: A) => void': +!!! error TS2322: Types of parameters 'b' and 'a' are incompatible: +!!! error TS2322: Type 'number' is not assignable to type 'A': +!!! error TS2322: Property 'foo' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt index e4d8a82c47e..b8cd56acadd 100644 --- a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt +++ b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt @@ -1,9 +1,12 @@ tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(2,22): error TS2339: Property 'foo' does not exist on type 'string'. +tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(3,10): error TS2346: Supplied parameters do not match any signature of call target. -==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (1 errors) ==== +==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (2 errors) ==== var f10: (x: T, b: () => (a: T) => void, y: T) => T; f10('', () => a => a.foo, ''); // a is string, fixed by first parameter ~~~ !!! error TS2339: Property 'foo' does not exist on type 'string'. - var r9 = f10('', () => (a => a.foo), 1); // now a should be any \ No newline at end of file + var r9 = f10('', () => (a => a.foo), 1); // now a should be any + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/contextuallyTypingOrOperator.types b/tests/baselines/reference/contextuallyTypingOrOperator.types index ee1ac4b0bba..5a20b2b921e 100644 --- a/tests/baselines/reference/contextuallyTypingOrOperator.types +++ b/tests/baselines/reference/contextuallyTypingOrOperator.types @@ -17,10 +17,10 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; >s : string var v2 = (s: string) => s.length || function (s) { s.length }; ->v2 : (s: string) => {} ->(s: string) => s.length || function (s) { s.length } : (s: string) => {} +>v2 : (s: string) => number | { (s: any): void; } +>(s: string) => s.length || function (s) { s.length } : (s: string) => number | { (s: any): void; } >s : string ->s.length || function (s) { s.length } : {} +>s.length || function (s) { s.length } : number | { (s: any): void; } >s.length : number >s : string >length : number @@ -31,10 +31,10 @@ var v2 = (s: string) => s.length || function (s) { s.length }; >length : any var v3 = (s: string) => s.length || function (s: number) { return 1 }; ->v3 : (s: string) => {} ->(s: string) => s.length || function (s: number) { return 1 } : (s: string) => {} +>v3 : (s: string) => number | { (s: number): number; } +>(s: string) => s.length || function (s: number) { return 1 } : (s: string) => number | { (s: number): number; } >s : string ->s.length || function (s: number) { return 1 } : {} +>s.length || function (s: number) { return 1 } : number | { (s: number): number; } >s.length : number >s : string >length : number @@ -42,10 +42,10 @@ var v3 = (s: string) => s.length || function (s: number) { return 1 }; >s : number var v4 = (s: number) => 1 || function (s: string) { return s.length }; ->v4 : (s: number) => {} ->(s: number) => 1 || function (s: string) { return s.length } : (s: number) => {} +>v4 : (s: number) => number | { (s: string): number; } +>(s: number) => 1 || function (s: string) { return s.length } : (s: number) => number | { (s: string): number; } >s : number ->1 || function (s: string) { return s.length } : {} +>1 || function (s: string) { return s.length } : number | { (s: string): number; } >function (s: string) { return s.length } : (s: string) => number >s : string >s.length : number diff --git a/tests/baselines/reference/contextuallyTypingOrOperator2.types b/tests/baselines/reference/contextuallyTypingOrOperator2.types index 57c9992436d..b46d0c0aedb 100644 --- a/tests/baselines/reference/contextuallyTypingOrOperator2.types +++ b/tests/baselines/reference/contextuallyTypingOrOperator2.types @@ -17,10 +17,10 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; >s : string var v2 = (s: string) => s.length || function (s) { s.aaa }; ->v2 : (s: string) => {} ->(s: string) => s.length || function (s) { s.aaa } : (s: string) => {} +>v2 : (s: string) => number | { (s: any): void; } +>(s: string) => s.length || function (s) { s.aaa } : (s: string) => number | { (s: any): void; } >s : string ->s.length || function (s) { s.aaa } : {} +>s.length || function (s) { s.aaa } : number | { (s: any): void; } >s.length : number >s : string >length : number diff --git a/tests/baselines/reference/defaultBestCommonTypesHaveDecls.errors.txt b/tests/baselines/reference/defaultBestCommonTypesHaveDecls.errors.txt index ada7f83af3d..c03b31e9e27 100644 --- a/tests/baselines/reference/defaultBestCommonTypesHaveDecls.errors.txt +++ b/tests/baselines/reference/defaultBestCommonTypesHaveDecls.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(4,6): error TS2339: Property 'length' does not exist on type '{}'. tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(10,6): error TS2339: Property 'length' does not exist on type 'Object'. -tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(18,27): error TS2339: Property 'length' does not exist on type '{}'. +tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(16,14): error TS2346: Supplied parameters do not match any signature of call target. ==== tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts (3 errors) ==== @@ -24,8 +24,8 @@ tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(18,27): error TS2339: Pr function concat(x: T, y: T): T { return null; } var result = concat(1, ""); + ~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var elementCount = result.length; // would like to get an error by now - ~~~~~~ -!!! error TS2339: Property 'length' does not exist on type '{}'. \ No newline at end of file diff --git a/tests/baselines/reference/enumBasics.types b/tests/baselines/reference/enumBasics.types index f775295891a..696e68eded2 100644 --- a/tests/baselines/reference/enumBasics.types +++ b/tests/baselines/reference/enumBasics.types @@ -157,8 +157,8 @@ enum E9 { // (refer to .js to validate) // Enum constant members are propagated var doNotPropagate = [ ->doNotPropagate : {}[] ->[ E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z] : {}[] +>doNotPropagate : Array +>[ E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z] : Array E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z >E8.B : E8 @@ -183,8 +183,8 @@ var doNotPropagate = [ ]; // Enum computed members are not propagated var doPropagate = [ ->doPropagate : {}[] ->[ E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C] : {}[] +>doPropagate : Array +>[ E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C] : Array E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C >E9.A : E9 diff --git a/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.errors.txt b/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.errors.txt new file mode 100644 index 00000000000..d9416eb4c25 --- /dev/null +++ b/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts(2,1): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts (1 errors) ==== + function bar(item1: T, item2: T) { } + bar(1, ""); // Should be ok + ~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.types b/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.types deleted file mode 100644 index 95214571df9..00000000000 --- a/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.types +++ /dev/null @@ -1,13 +0,0 @@ -=== tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts === -function bar(item1: T, item2: T) { } ->bar : (item1: T, item2: T) => void ->T : T ->item1 : T ->T : T ->item2 : T ->T : T - -bar(1, ""); // Should be ok ->bar(1, "") : void ->bar : (item1: T, item2: T) => void - diff --git a/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt b/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt index b653bc01f55..66e8a2a66df 100644 --- a/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt +++ b/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt @@ -7,7 +7,7 @@ tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDec tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(40,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'I', but here has type 'C2'. tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(43,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'f' must be of type '(x: string) => number', but here has type '(x: number) => string'. tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(46,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. -tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(47,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '{}[]'. +tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(47,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'Array>'. tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(50,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'D[]', but here has type 'D[]'. tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(53,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'm' must be of type 'typeof M', but here has type 'typeof A'. @@ -79,7 +79,7 @@ tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDec !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. for( var arr = [new C(), new C2(), new D()];;){} ~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '{}[]'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'Array>'. for(var arr2 = [new D()];;){} for( var arr2 = new Array>();;){} diff --git a/tests/baselines/reference/generatedContextualTyping.types b/tests/baselines/reference/generatedContextualTyping.types index 57b5408eabe..c609c6aec9c 100644 --- a/tests/baselines/reference/generatedContextualTyping.types +++ b/tests/baselines/reference/generatedContextualTyping.types @@ -127,11 +127,11 @@ var x12: Genric = { func: n => { return [d1, d2]; } }; >x12 : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -243,11 +243,11 @@ class x24 { member: Genric = { func: n => { return [d1, d2]; } } } >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -359,11 +359,11 @@ class x36 { private member: Genric = { func: n => { return [d1, d2]; } } } >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -475,11 +475,11 @@ class x48 { public member: Genric = { func: n => { return [d1, d2]; } } } >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -591,11 +591,11 @@ class x60 { static member: Genric = { func: n => { return [d1, d2]; } } } >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -707,11 +707,11 @@ class x72 { private static member: Genric = { func: n => { return [d1, d2] >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -823,11 +823,11 @@ class x84 { public static member: Genric = { func: n => { return [d1, d2]; >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -939,11 +939,11 @@ class x96 { constructor(parm: Genric = { func: n => { return [d1, d2]; } } >parm : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1055,11 +1055,11 @@ class x108 { constructor(public parm: Genric = { func: n => { return [d1, >parm : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1171,11 +1171,11 @@ class x120 { constructor(private parm: Genric = { func: n => { return [d1, >parm : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1287,11 +1287,11 @@ function x132(parm: Genric = { func: n => { return [d1, d2]; } }) { } >parm : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1391,11 +1391,11 @@ function x144(): Genric { return { func: n => { return [d1, d2]; } }; } >x144 : () => Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1539,18 +1539,18 @@ function x156(): Genric { return { func: n => { return [d1, d2]; } }; retu >x156 : () => Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1661,12 +1661,12 @@ var x168: () => Genric = () => { return { func: n => { return [d1, d2]; } >x168 : () => Genric >Genric : Genric >Base : Base ->() => { return { func: n => { return [d1, d2]; } }; } : () => { func: (n: Base[]) => {}[]; } ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>() => { return { func: n => { return [d1, d2]; } }; } : () => { func: (n: Base[]) => Array; } +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1777,12 +1777,12 @@ var x180: () => Genric = function() { return { func: n => { return [d1, d2 >x180 : () => Genric >Genric : Genric >Base : Base ->function() { return { func: n => { return [d1, d2]; } }; } : () => { func: (n: Base[]) => {}[]; } ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>function() { return { func: n => { return [d1, d2]; } }; } : () => { func: (n: Base[]) => Array; } +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1894,11 +1894,11 @@ module x192 { var t: Genric = { func: n => { return [d1, d2]; } }; } >t : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2010,11 +2010,11 @@ module x204 { export var t: Genric = { func: n => { return [d1, d2]; } }; >t : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2098,11 +2098,11 @@ var x216 = >{ func: n => { return [d1, d2]; } }; >>{ func: n => { return [d1, d2]; } } : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2323,13 +2323,13 @@ var x236: Genric; x236 = { func: n => { return [d1, d2]; } }; >x236 : Genric >Genric : Genric >Base : Base ->x236 = { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } +>x236 = { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } >x236 : Genric ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2463,13 +2463,13 @@ var x248: { n: Genric; } = { n: { func: n => { return [d1, d2]; } } }; >n : Genric >Genric : Genric >Base : Base ->{ n: { func: n => { return [d1, d2]; } } } : { n: { func: (n: Base[]) => {}[]; }; } ->n : { func: (n: Base[]) => {}[]; } ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ n: { func: n => { return [d1, d2]; } } } : { n: { func: (n: Base[]) => Array; }; } +>n : { func: (n: Base[]) => Array; } +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2543,11 +2543,11 @@ var x260: Genric[] = [{ func: n => { return [d1, d2]; } }]; >Genric : Genric >Base : Base >[{ func: n => { return [d1, d2]; } }] : Genric[] ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2976,18 +2976,18 @@ var x296: Genric = true ? { func: n => { return [d1, d2]; } } : { func: n >Genric : Genric >Base : Base >true ? { func: n => { return [d1, d2]; } } : { func: n => { return [d1, d2]; } } : Genric ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3111,11 +3111,11 @@ var x308: Genric = true ? undefined : { func: n => { return [d1, d2]; } }; >Base : Base >true ? undefined : { func: n => { return [d1, d2]; } } : Genric >undefined : undefined ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3238,11 +3238,11 @@ var x320: Genric = true ? { func: n => { return [d1, d2]; } } : undefined; >Genric : Genric >Base : Base >true ? { func: n => { return [d1, d2]; } } : undefined : Genric ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3379,11 +3379,11 @@ function x332(n: Genric) { }; x332({ func: n => { return [d1, d2]; } }); >Base : Base >x332({ func: n => { return [d1, d2]; } }) : void >x332 : (n: Genric) => void ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3543,11 +3543,11 @@ var x344 = (n: Genric) => n; x344({ func: n => { return [d1, d2]; } }); >n : Genric >x344({ func: n => { return [d1, d2]; } }) : Genric >x344 : (n: Genric) => Genric ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3695,11 +3695,11 @@ var x356 = function(n: Genric) { }; x356({ func: n => { return [d1, d2]; } >Base : Base >x356({ func: n => { return [d1, d2]; } }) : void >x356 : (n: Genric) => void ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 diff --git a/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types b/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types index 2ac2483c405..f16e747d41e 100644 --- a/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types +++ b/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types @@ -49,7 +49,7 @@ _.all([true, 1, null, 'yes'], _.identity); >_.all : (list: T[], iterator?: Underscore.Iterator, context?: any) => boolean >_ : Underscore.Static >all : (list: T[], iterator?: Underscore.Iterator, context?: any) => boolean ->[true, 1, null, 'yes'] : {}[] +>[true, 1, null, 'yes'] : Array >_.identity : (value: T) => T >_ : Underscore.Static >identity : (value: T) => T diff --git a/tests/baselines/reference/genericCallWithArrayLiteralArgs.types b/tests/baselines/reference/genericCallWithArrayLiteralArgs.types index c79efb0792c..a6a75f9bd13 100644 --- a/tests/baselines/reference/genericCallWithArrayLiteralArgs.types +++ b/tests/baselines/reference/genericCallWithArrayLiteralArgs.types @@ -40,10 +40,10 @@ var r3 = foo([]); // number[] >[] : number[] var r4 = foo([1, '']); // {}[] ->r4 : {}[] ->foo([1, '']) : {}[] +>r4 : Array +>foo([1, '']) : Array >foo : (t: T) => T ->[1, ''] : {}[] +>[1, ''] : Array var r5 = foo([1, '']); // any[] >r5 : any[] diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt b/tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt new file mode 100644 index 00000000000..1a84c08dc32 --- /dev/null +++ b/tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt @@ -0,0 +1,58 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(26,18): error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(30,15): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(33,15): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(34,16): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(35,23): error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts (5 errors) ==== + // Generic functions used as arguments for function typed parameters are not used to make inferences from + // Using function arguments, no errors expected + + function foo(x: (a: T) => T) { + return x(null); + } + + var r = foo((x: U) => ''); // {} + var r2 = foo((x: U) => ''); // string + var r3 = foo(x => ''); // {} + + function foo2(x: T, cb: (a: T) => U) { + return cb(x); + } + + var r4 = foo2(1, function (a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions + var r5 = foo2(1, (a) => ''); // string + var r6 = foo2('', (a: Z) => 1); + + function foo3(x: T, cb: (a: T) => U, y: U) { + return cb(x); + } + + var r7 = foo3(1, (a: Z) => '', ''); // string + + var r8 = foo3(1, function (a) { return '' }, 1); // {} + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + var r9 = foo3(1, (a) => '', ''); // string + + function other(t: T, u: U) { + var r10 = foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r10 = foo2(1, (x) => ''); // string + + var r11 = foo3(1, (x: T) => '', ''); // string + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r11b = foo3(1, (x: T) => '', 1); // {} + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r12 = foo3(1, function (a) { return '' }, 1); // {} + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + } \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments.types b/tests/baselines/reference/genericCallWithFunctionTypedArguments.types deleted file mode 100644 index 2d3b234d0e1..00000000000 --- a/tests/baselines/reference/genericCallWithFunctionTypedArguments.types +++ /dev/null @@ -1,173 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts === -// Generic functions used as arguments for function typed parameters are not used to make inferences from -// Using function arguments, no errors expected - -function foo(x: (a: T) => T) { ->foo : (x: (a: T) => T) => T ->T : T ->x : (a: T) => T ->a : T ->T : T ->T : T - - return x(null); ->x(null) : T ->x : (a: T) => T -} - -var r = foo((x: U) => ''); // {} ->r : {} ->foo((x: U) => '') : {} ->foo : (x: (a: T) => T) => T ->(x: U) => '' : (x: U) => string ->U : U ->x : U ->U : U - -var r2 = foo((x: U) => ''); // string ->r2 : string ->foo((x: U) => '') : string ->foo : (x: (a: T) => T) => T ->(x: U) => '' : (x: U) => string ->U : U ->x : U ->U : U - -var r3 = foo(x => ''); // {} ->r3 : {} ->foo(x => '') : {} ->foo : (x: (a: T) => T) => T ->x => '' : (x: {}) => string ->x : {} - -function foo2(x: T, cb: (a: T) => U) { ->foo2 : (x: T, cb: (a: T) => U) => U ->T : T ->U : U ->x : T ->T : T ->cb : (a: T) => U ->a : T ->T : T ->U : U - - return cb(x); ->cb(x) : U ->cb : (a: T) => U ->x : T -} - -var r4 = foo2(1, function (a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions ->r4 : string ->foo2(1, function (a: Z) { return '' }) : string ->foo2 : (x: T, cb: (a: T) => U) => U ->function (a: Z) { return '' } : (a: Z) => string ->Z : Z ->a : Z ->Z : Z - -var r5 = foo2(1, (a) => ''); // string ->r5 : string ->foo2(1, (a) => '') : string ->foo2 : (x: T, cb: (a: T) => U) => U ->(a) => '' : (a: number) => string ->a : number - -var r6 = foo2('', (a: Z) => 1); ->r6 : number ->foo2('', (a: Z) => 1) : number ->foo2 : (x: T, cb: (a: T) => U) => U ->(a: Z) => 1 : (a: Z) => number ->Z : Z ->a : Z ->Z : Z - -function foo3(x: T, cb: (a: T) => U, y: U) { ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->T : T ->U : U ->x : T ->T : T ->cb : (a: T) => U ->a : T ->T : T ->U : U ->y : U ->U : U - - return cb(x); ->cb(x) : U ->cb : (a: T) => U ->x : T -} - -var r7 = foo3(1, (a: Z) => '', ''); // string ->r7 : string ->foo3(1, (a: Z) => '', '') : string ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(a: Z) => '' : (a: Z) => string ->Z : Z ->a : Z ->Z : Z - -var r8 = foo3(1, function (a) { return '' }, 1); // {} ->r8 : {} ->foo3(1, function (a) { return '' }, 1) : {} ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->function (a) { return '' } : (a: number) => string ->a : number - -var r9 = foo3(1, (a) => '', ''); // string ->r9 : string ->foo3(1, (a) => '', '') : string ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(a) => '' : (a: number) => string ->a : number - -function other(t: T, u: U) { ->other : (t: T, u: U) => void ->T : T ->U : U ->t : T ->T : T ->u : U ->U : U - - var r10 = foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made ->r10 : string ->foo2(1, (x: T) => '') : string ->foo2 : (x: T, cb: (a: T) => U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r10 = foo2(1, (x) => ''); // string ->r10 : string ->foo2(1, (x) => '') : string ->foo2 : (x: T, cb: (a: T) => U) => U ->(x) => '' : (x: number) => string ->x : number - - var r11 = foo3(1, (x: T) => '', ''); // string ->r11 : string ->foo3(1, (x: T) => '', '') : string ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r11b = foo3(1, (x: T) => '', 1); // {} ->r11b : {} ->foo3(1, (x: T) => '', 1) : {} ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r12 = foo3(1, function (a) { return '' }, 1); // {} ->r12 : {} ->foo3(1, function (a) { return '' }, 1) : {} ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->function (a) { return '' } : (a: number) => string ->a : number -} diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.errors.txt b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.errors.txt new file mode 100644 index 00000000000..6caeb1cd6d6 --- /dev/null +++ b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.errors.txt @@ -0,0 +1,50 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts(29,10): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts(40,10): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts (2 errors) ==== + // Generic functions used as arguments for function typed parameters are not used to make inferences from + // Using construct signature arguments, no errors expected + + function foo(x: new(a: T) => T) { + return new x(null); + } + + interface I { + new (x: T): T; + } + interface I2 { + new (x: T): T; + } + var i: I; + var i2: I2; + var a: { + new (x: T): T; + } + + var r = foo(i); // any + var r2 = foo(i); // string + var r3 = foo(i2); // string + var r3b = foo(a); // any + + function foo2(x: T, cb: new(a: T) => U) { + return new cb(x); + } + + var r4 = foo2(1, i2); // string, instantiated generic + ~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r4b = foo2(1, a); // any + var r5 = foo2(1, i); // any + var r6 = foo2('', i2); // string + + function foo3(x: T, cb: new(a: T) => U, y: U) { + return new cb(x); + } + + var r7 = foo3(null, i, ''); // any + var r7b = foo3(null, a, ''); // any + var r8 = foo3(1, i2, 1); // {} + ~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r9 = foo3('', i2, ''); // string \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.types b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.types deleted file mode 100644 index 89d7afd94e2..00000000000 --- a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.types +++ /dev/null @@ -1,161 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts === -// Generic functions used as arguments for function typed parameters are not used to make inferences from -// Using construct signature arguments, no errors expected - -function foo(x: new(a: T) => T) { ->foo : (x: new (a: T) => T) => T ->T : T ->x : new (a: T) => T ->a : T ->T : T ->T : T - - return new x(null); ->new x(null) : T ->x : new (a: T) => T -} - -interface I { ->I : I - - new (x: T): T; ->T : T ->x : T ->T : T ->T : T -} -interface I2 { ->I2 : I2 ->T : T - - new (x: T): T; ->x : T ->T : T ->T : T -} -var i: I; ->i : I ->I : I - -var i2: I2; ->i2 : I2 ->I2 : I2 - -var a: { ->a : new (x: T) => T - - new (x: T): T; ->T : T ->x : T ->T : T ->T : T -} - -var r = foo(i); // any ->r : any ->foo(i) : any ->foo : (x: new (a: T) => T) => T ->i : I - -var r2 = foo(i); // string ->r2 : string ->foo(i) : string ->foo : (x: new (a: T) => T) => T ->i : I - -var r3 = foo(i2); // string ->r3 : string ->foo(i2) : string ->foo : (x: new (a: T) => T) => T ->i2 : I2 - -var r3b = foo(a); // any ->r3b : any ->foo(a) : any ->foo : (x: new (a: T) => T) => T ->a : new (x: T) => T - -function foo2(x: T, cb: new(a: T) => U) { ->foo2 : (x: T, cb: new (a: T) => U) => U ->T : T ->U : U ->x : T ->T : T ->cb : new (a: T) => U ->a : T ->T : T ->U : U - - return new cb(x); ->new cb(x) : U ->cb : new (a: T) => U ->x : T -} - -var r4 = foo2(1, i2); // string, instantiated generic ->r4 : string ->foo2(1, i2) : string ->foo2 : (x: T, cb: new (a: T) => U) => U ->i2 : I2 - -var r4b = foo2(1, a); // any ->r4b : any ->foo2(1, a) : any ->foo2 : (x: T, cb: new (a: T) => U) => U ->a : new (x: T) => T - -var r5 = foo2(1, i); // any ->r5 : any ->foo2(1, i) : any ->foo2 : (x: T, cb: new (a: T) => U) => U ->i : I - -var r6 = foo2('', i2); // string ->r6 : string ->foo2('', i2) : string ->foo2 : (x: T, cb: new (a: T) => U) => U ->i2 : I2 - -function foo3(x: T, cb: new(a: T) => U, y: U) { ->foo3 : (x: T, cb: new (a: T) => U, y: U) => U ->T : T ->U : U ->x : T ->T : T ->cb : new (a: T) => U ->a : T ->T : T ->U : U ->y : U ->U : U - - return new cb(x); ->new cb(x) : U ->cb : new (a: T) => U ->x : T -} - -var r7 = foo3(null, i, ''); // any ->r7 : any ->foo3(null, i, '') : any ->foo3 : (x: T, cb: new (a: T) => U, y: U) => U ->i : I - -var r7b = foo3(null, a, ''); // any ->r7b : any ->foo3(null, a, '') : any ->foo3 : (x: T, cb: new (a: T) => U, y: U) => U ->a : new (x: T) => T - -var r8 = foo3(1, i2, 1); // {} ->r8 : {} ->foo3(1, i2, 1) : {} ->foo3 : (x: T, cb: new (a: T) => U, y: U) => U ->i2 : I2 - -var r9 = foo3('', i2, ''); // string ->r9 : string ->foo3('', i2, '') : string ->foo3 : (x: T, cb: new (a: T) => U, y: U) => U ->i2 : I2 - diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt index 7f4fa26aad1..1a4ad29fce8 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt @@ -1,10 +1,11 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(9,25): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(14,17): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(15,18): error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(24,19): error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(36,32): error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'. -==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts (4 errors) ==== +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts (5 errors) ==== // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, // the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. @@ -14,6 +15,8 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen } var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. function other2(x: T) { var r7 = foo((a: T) => a, (b: T) => b); // T => T diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt new file mode 100644 index 00000000000..691a3f1192c --- /dev/null +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt @@ -0,0 +1,42 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts(32,11): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts(33,11): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts (2 errors) ==== + // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, + // the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. + + function foo(x: T, a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + var r1 = foo('', (x: string) => '', (x: Object) => null); // any => any + var r1ii = foo('', (x) => '', (x) => null); // string => string + var r2 = foo('', (x: string) => '', (x: Object) => ''); // string => string + var r3 = foo(null, (x: Object) => '', (x: string) => ''); // Object => Object + var r4 = foo(null, (x) => '', (x) => ''); // any => any + var r5 = foo(new Object(), (x) => '', (x) => ''); // Object => Object + + enum E { A } + enum F { A } + + var r6 = foo(E.A, (x: number) => E.A, (x: F) => F.A); // number => number + + + function foo2(x: T, a: (x: T) => U, b: (x: T) => U) { + var r: (x: T) => U; + return r; + } + + var r8 = foo2('', (x) => '', (x) => null); // string => string + var r9 = foo2(null, (x) => '', (x) => ''); // any => any + var r10 = foo2(null, (x: Object) => '', (x: string) => ''); // Object => Object + + var x: (a: string) => boolean; + var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // {} => {} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // (string => boolean) => {} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.types b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.types deleted file mode 100644 index 2c0d21a5a07..00000000000 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.types +++ /dev/null @@ -1,202 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts === -// When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, -// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. - -function foo(x: T, a: (x: T) => T, b: (x: T) => T) { ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->T : T ->x : T ->T : T ->a : (x: T) => T ->x : T ->T : T ->T : T ->b : (x: T) => T ->x : T ->T : T ->T : T - - var r: (x: T) => T; ->r : (x: T) => T ->x : T ->T : T ->T : T - - return r; ->r : (x: T) => T -} - -var r1 = foo('', (x: string) => '', (x: Object) => null); // any => any ->r1 : (x: any) => any ->foo('', (x: string) => '', (x: Object) => null) : (x: any) => any ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: string) => '' : (x: string) => string ->x : string ->(x: Object) => null : (x: Object) => any ->x : Object ->Object : Object - -var r1ii = foo('', (x) => '', (x) => null); // string => string ->r1ii : (x: string) => string ->foo('', (x) => '', (x) => null) : (x: string) => string ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x) => '' : (x: string) => string ->x : string ->(x) => null : (x: string) => any ->x : string - -var r2 = foo('', (x: string) => '', (x: Object) => ''); // string => string ->r2 : (x: Object) => Object ->foo('', (x: string) => '', (x: Object) => '') : (x: Object) => Object ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: string) => '' : (x: string) => string ->x : string ->(x: Object) => '' : (x: Object) => string ->x : Object ->Object : Object - -var r3 = foo(null, (x: Object) => '', (x: string) => ''); // Object => Object ->r3 : (x: Object) => Object ->foo(null, (x: Object) => '', (x: string) => '') : (x: Object) => Object ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: Object) => '' : (x: Object) => string ->x : Object ->Object : Object ->(x: string) => '' : (x: string) => string ->x : string - -var r4 = foo(null, (x) => '', (x) => ''); // any => any ->r4 : (x: any) => any ->foo(null, (x) => '', (x) => '') : (x: any) => any ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x) => '' : (x: any) => string ->x : any ->(x) => '' : (x: any) => string ->x : any - -var r5 = foo(new Object(), (x) => '', (x) => ''); // Object => Object ->r5 : (x: Object) => Object ->foo(new Object(), (x) => '', (x) => '') : (x: Object) => Object ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->new Object() : Object ->Object : { (): any; (value: any): any; new (value?: any): Object; prototype: Object; getPrototypeOf(o: any): any; getOwnPropertyDescriptor(o: any, p: string): PropertyDescriptor; getOwnPropertyNames(o: any): string[]; create(o: any, properties?: PropertyDescriptorMap): any; defineProperty(o: any, p: string, attributes: PropertyDescriptor): any; defineProperties(o: any, properties: PropertyDescriptorMap): any; seal(o: any): any; freeze(o: any): any; preventExtensions(o: any): any; isSealed(o: any): boolean; isFrozen(o: any): boolean; isExtensible(o: any): boolean; keys(o: any): string[]; } ->(x) => '' : (x: Object) => string ->x : Object ->(x) => '' : (x: Object) => string ->x : Object - -enum E { A } ->E : E ->A : E - -enum F { A } ->F : F ->A : F - -var r6 = foo(E.A, (x: number) => E.A, (x: F) => F.A); // number => number ->r6 : (x: number) => number ->foo(E.A, (x: number) => E.A, (x: F) => F.A) : (x: number) => number ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->E.A : E ->E : typeof E ->A : E ->(x: number) => E.A : (x: number) => E ->x : number ->E.A : E ->E : typeof E ->A : E ->(x: F) => F.A : (x: F) => F ->x : F ->F : F ->F.A : F ->F : typeof F ->A : F - - -function foo2(x: T, a: (x: T) => U, b: (x: T) => U) { ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->T : T ->U : U ->x : T ->T : T ->a : (x: T) => U ->x : T ->T : T ->U : U ->b : (x: T) => U ->x : T ->T : T ->U : U - - var r: (x: T) => U; ->r : (x: T) => U ->x : T ->T : T ->U : U - - return r; ->r : (x: T) => U -} - -var r8 = foo2('', (x) => '', (x) => null); // string => string ->r8 : (x: string) => any ->foo2('', (x) => '', (x) => null) : (x: string) => any ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->(x) => '' : (x: string) => string ->x : string ->(x) => null : (x: string) => any ->x : string - -var r9 = foo2(null, (x) => '', (x) => ''); // any => any ->r9 : (x: any) => string ->foo2(null, (x) => '', (x) => '') : (x: any) => string ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->(x) => '' : (x: any) => string ->x : any ->(x) => '' : (x: any) => string ->x : any - -var r10 = foo2(null, (x: Object) => '', (x: string) => ''); // Object => Object ->r10 : (x: Object) => string ->foo2(null, (x: Object) => '', (x: string) => '') : (x: Object) => string ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->(x: Object) => '' : (x: Object) => string ->x : Object ->Object : Object ->(x: string) => '' : (x: string) => string ->x : string - -var x: (a: string) => boolean; ->x : (a: string) => boolean ->a : string - -var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // {} => {} ->r11 : (x: {}) => {} ->foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2) : (x: {}) => {} ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->x : (a: string) => boolean ->(a1: (y: string) => string) => (n: Object) => 1 : (a1: (y: string) => string) => (n: Object) => number ->a1 : (y: string) => string ->y : string ->(n: Object) => 1 : (n: Object) => number ->n : Object ->Object : Object ->(a2: (z: string) => string) => 2 : (a2: (z: string) => string) => number ->a2 : (z: string) => string ->z : string - -var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // (string => boolean) => {} ->r12 : (x: (a: string) => boolean) => {} ->foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2) : (x: (a: string) => boolean) => {} ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->x : (a: string) => boolean ->(a1: (y: string) => boolean) => (n: Object) => 1 : (a1: (y: string) => boolean) => (n: Object) => number ->a1 : (y: string) => boolean ->y : string ->(n: Object) => 1 : (n: Object) => number ->n : Object ->Object : Object ->(a2: (z: string) => boolean) => 2 : (a2: (z: string) => boolean) => number ->a2 : (z: string) => boolean ->z : string - diff --git a/tests/baselines/reference/genericCallWithObjectLiteralArgs.errors.txt b/tests/baselines/reference/genericCallWithObjectLiteralArgs.errors.txt new file mode 100644 index 00000000000..092540b4994 --- /dev/null +++ b/tests/baselines/reference/genericCallWithObjectLiteralArgs.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts(5,9): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts (1 errors) ==== + function foo(x: { bar: T; baz: T }) { + return x; + } + + var r = foo({ bar: 1, baz: '' }); // T = {} + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r2 = foo({ bar: 1, baz: 1 }); // T = number + var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo + var r4 = foo({ bar: 1, baz: '' }); // T = Object \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithObjectLiteralArgs.types b/tests/baselines/reference/genericCallWithObjectLiteralArgs.types deleted file mode 100644 index d23445ecbca..00000000000 --- a/tests/baselines/reference/genericCallWithObjectLiteralArgs.types +++ /dev/null @@ -1,49 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts === -function foo(x: { bar: T; baz: T }) { ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->T : T ->x : { bar: T; baz: T; } ->bar : T ->T : T ->baz : T ->T : T - - return x; ->x : { bar: T; baz: T; } -} - -var r = foo({ bar: 1, baz: '' }); // T = {} ->r : { bar: {}; baz: {}; } ->foo({ bar: 1, baz: '' }) : { bar: {}; baz: {}; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->{ bar: 1, baz: '' } : { bar: number; baz: string; } ->bar : number ->baz : string - -var r2 = foo({ bar: 1, baz: 1 }); // T = number ->r2 : { bar: number; baz: number; } ->foo({ bar: 1, baz: 1 }) : { bar: number; baz: number; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->{ bar: 1, baz: 1 } : { bar: number; baz: number; } ->bar : number ->baz : number - -var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo ->r3 : { bar: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; baz: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; } ->foo({ bar: foo, baz: foo }) : { bar: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; baz: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->{ bar: foo, baz: foo } : { bar: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; baz: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; } ->bar : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->baz : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } - -var r4 = foo({ bar: 1, baz: '' }); // T = Object ->r4 : { bar: Object; baz: Object; } ->foo({ bar: 1, baz: '' }) : { bar: Object; baz: Object; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->Object : Object ->{ bar: 1, baz: '' } : { bar: number; baz: string; } ->bar : number ->baz : string - diff --git a/tests/baselines/reference/genericCallWithObjectLiteralArguments1.errors.txt b/tests/baselines/reference/genericCallWithObjectLiteralArguments1.errors.txt index 3b3f8d43ff9..4ac64500bd1 100644 --- a/tests/baselines/reference/genericCallWithObjectLiteralArguments1.errors.txt +++ b/tests/baselines/reference/genericCallWithObjectLiteralArguments1.errors.txt @@ -1,3 +1,4 @@ +tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts(2,9): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts(4,22): error TS2345: Argument of type '{ x: number; y: string; }' is not assignable to parameter of type '{ x: number; y: number; }'. Types of property 'y' are incompatible: Type 'string' is not assignable to type 'number'. @@ -12,9 +13,11 @@ tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts(7,22): error TS23 Type 'number' is not assignable to type 'string'. -==== tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts (4 errors) ==== +==== tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts (5 errors) ==== function foo(n: { x: T; y: T }, m: T) { return m; } var x = foo({ x: 3, y: "" }, 4); // no error, x is Object, the best common type + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. // these are all errors var x2 = foo({ x: 3, y: "" }, 4); ~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgs.errors.txt b/tests/baselines/reference/genericCallWithObjectTypeArgs.errors.txt new file mode 100644 index 00000000000..dce9562a8f5 --- /dev/null +++ b/tests/baselines/reference/genericCallWithObjectTypeArgs.errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs.ts(20,9): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs.ts (1 errors) ==== + class C { + private x: string; + } + + class D { + private x: string; + } + + class X { + x: T; + } + + function foo(t: X, t2: X) { + var x: T; + return x; + } + + var c1 = new X(); + var d1 = new X(); + var r = foo(c1, d1); // error + ~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r2 = foo(c1, c1); // ok \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgs.types b/tests/baselines/reference/genericCallWithObjectTypeArgs.types deleted file mode 100644 index ddbd7d83054..00000000000 --- a/tests/baselines/reference/genericCallWithObjectTypeArgs.types +++ /dev/null @@ -1,68 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs.ts === -class C { ->C : C - - private x: string; ->x : string -} - -class D { ->D : D - - private x: string; ->x : string -} - -class X { ->X : X ->T : T - - x: T; ->x : T ->T : T -} - -function foo(t: X, t2: X) { ->foo : (t: X, t2: X) => T ->T : T ->t : X ->X : X ->T : T ->t2 : X ->X : X ->T : T - - var x: T; ->x : T ->T : T - - return x; ->x : T -} - -var c1 = new X(); ->c1 : X ->new X() : X ->X : typeof X ->C : C - -var d1 = new X(); ->d1 : X ->new X() : X ->X : typeof X ->D : D - -var r = foo(c1, d1); // error ->r : {} ->foo(c1, d1) : {} ->foo : (t: X, t2: X) => T ->c1 : X ->d1 : X - -var r2 = foo(c1, c1); // ok ->r2 : C ->foo(c1, c1) : C ->foo : (t: X, t2: X) => T ->c1 : X ->c1 : X - diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgs2.types b/tests/baselines/reference/genericCallWithObjectTypeArgs2.types index 0065811fdc1..6c8ed4e468a 100644 --- a/tests/baselines/reference/genericCallWithObjectTypeArgs2.types +++ b/tests/baselines/reference/genericCallWithObjectTypeArgs2.types @@ -22,7 +22,7 @@ class Derived2 extends Base { // returns {}[] function f(a: { x: T; y: U }) { ->f : (a: { x: T; y: U; }) => {}[] +>f : (a: { x: T; y: U; }) => Array >T : T >Base : Base >U : U @@ -34,7 +34,7 @@ function f(a: { x: T; y: U }) { >U : U return [a.x, a.y]; ->[a.x, a.y] : {}[] +>[a.x, a.y] : Array >a.x : T >a : { x: T; y: U; } >x : T @@ -44,9 +44,9 @@ function f(a: { x: T; y: U }) { } var r = f({ x: new Derived(), y: new Derived2() }); // {}[] ->r : {}[] ->f({ x: new Derived(), y: new Derived2() }) : {}[] ->f : (a: { x: T; y: U; }) => {}[] +>r : Array +>f({ x: new Derived(), y: new Derived2() }) : Array +>f : (a: { x: T; y: U; }) => Array >{ x: new Derived(), y: new Derived2() } : { x: Derived; y: Derived2; } >x : Derived >new Derived() : Derived @@ -56,9 +56,9 @@ var r = f({ x: new Derived(), y: new Derived2() }); // {}[] >Derived2 : typeof Derived2 var r2 = f({ x: new Base(), y: new Derived2() }); // {}[] ->r2 : {}[] ->f({ x: new Base(), y: new Derived2() }) : {}[] ->f : (a: { x: T; y: U; }) => {}[] +>r2 : Base[] +>f({ x: new Base(), y: new Derived2() }) : Base[] +>f : (a: { x: T; y: U; }) => Array >{ x: new Base(), y: new Derived2() } : { x: Base; y: Derived2; } >x : Base >new Base() : Base diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints3.errors.txt b/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints3.errors.txt index c41ca0e8875..9cb190ddecd 100644 --- a/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints3.errors.txt +++ b/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints3.errors.txt @@ -1,7 +1,8 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts(18,10): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts(20,29): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts (1 errors) ==== +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts (2 errors) ==== // Generic call with constraints infering type parameter from object member properties class Base { @@ -20,6 +21,8 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObj } var r1 = f({ x: new Derived(), y: new Derived2() }); // ok, both extend Base + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. function f2(a: U) { ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.errors.txt b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.errors.txt new file mode 100644 index 00000000000..b5a423ac07b --- /dev/null +++ b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.errors.txt @@ -0,0 +1,54 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts(36,14): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts (1 errors) ==== + // Function typed arguments with multiple signatures must be passed an implementation that matches all of them + // Inferences are made quadratic-pairwise to and from these overload sets + + module NonGenericParameter { + var a: { + new(x: boolean): boolean; + new(x: string): string; + } + + function foo4(cb: typeof a) { + return new cb(null); + } + + var r = foo4(a); + var b: { new (x: T): T }; + var r2 = foo4(b); + } + + module GenericParameter { + function foo5(cb: { new(x: T): string; new(x: number): T }) { + return cb; + } + + var a: { + new (x: boolean): string; + new (x: number): boolean; + } + var r5 = foo5(a); // new{} => string; new(x:number) => {} + var b: { new(x: T): string; new(x: number): T; } + var r7 = foo5(b); // new any => string; new(x:number) => any + + function foo6(cb: { new(x: T): string; new(x: T, y?: T): string }) { + return cb; + } + + var r8 = foo6(a); // new{} => string; new(x:{}, y?:{}) => string + ~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r9 = foo6(b); // new any => string; new(x:any, y?:any) => string + + function foo7(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }) { + return cb; + } + + var r13 = foo7(1, b); // new any => string; new(x:any, y?:any) => string + var c: { new (x: T): string; (x: number): T; } + var c2: { new (x: T): string; new(x: number): T; } + var r14 = foo7(1, c); // new any => string; new(x:any, y?:any) => string + var r15 = foo7(1, c2); // new any => string; new(x:any, y?:any) => string + } \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.types b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.types deleted file mode 100644 index 6c16ad0259c..00000000000 --- a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.types +++ /dev/null @@ -1,173 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts === -// Function typed arguments with multiple signatures must be passed an implementation that matches all of them -// Inferences are made quadratic-pairwise to and from these overload sets - -module NonGenericParameter { ->NonGenericParameter : typeof NonGenericParameter - - var a: { ->a : { new (x: boolean): boolean; new (x: string): string; } - - new(x: boolean): boolean; ->x : boolean - - new(x: string): string; ->x : string - } - - function foo4(cb: typeof a) { ->foo4 : (cb: { new (x: boolean): boolean; new (x: string): string; }) => boolean ->cb : { new (x: boolean): boolean; new (x: string): string; } ->a : { new (x: boolean): boolean; new (x: string): string; } - - return new cb(null); ->new cb(null) : boolean ->cb : { new (x: boolean): boolean; new (x: string): string; } - } - - var r = foo4(a); ->r : boolean ->foo4(a) : boolean ->foo4 : (cb: { new (x: boolean): boolean; new (x: string): string; }) => boolean ->a : { new (x: boolean): boolean; new (x: string): string; } - - var b: { new (x: T): T }; ->b : new (x: T) => T ->T : T ->x : T ->T : T ->T : T - - var r2 = foo4(b); ->r2 : boolean ->foo4(b) : boolean ->foo4 : (cb: { new (x: boolean): boolean; new (x: string): string; }) => boolean ->b : new (x: T) => T -} - -module GenericParameter { ->GenericParameter : typeof GenericParameter - - function foo5(cb: { new(x: T): string; new(x: number): T }) { ->foo5 : (cb: { new (x: T): string; new (x: number): T; }) => { new (x: T): string; new (x: number): T; } ->T : T ->cb : { new (x: T): string; new (x: number): T; } ->x : T ->T : T ->x : number ->T : T - - return cb; ->cb : { new (x: T): string; new (x: number): T; } - } - - var a: { ->a : { new (x: boolean): string; new (x: number): boolean; } - - new (x: boolean): string; ->x : boolean - - new (x: number): boolean; ->x : number - } - var r5 = foo5(a); // new{} => string; new(x:number) => {} ->r5 : { new (x: boolean): string; new (x: number): boolean; } ->foo5(a) : { new (x: boolean): string; new (x: number): boolean; } ->foo5 : (cb: { new (x: T): string; new (x: number): T; }) => { new (x: T): string; new (x: number): T; } ->a : { new (x: boolean): string; new (x: number): boolean; } - - var b: { new(x: T): string; new(x: number): T; } ->b : { new (x: T): string; new (x: number): T; } ->T : T ->x : T ->T : T ->T : T ->x : number ->T : T - - var r7 = foo5(b); // new any => string; new(x:number) => any ->r7 : { new (x: any): string; new (x: number): any; } ->foo5(b) : { new (x: any): string; new (x: number): any; } ->foo5 : (cb: { new (x: T): string; new (x: number): T; }) => { new (x: T): string; new (x: number): T; } ->b : { new (x: T): string; new (x: number): T; } - - function foo6(cb: { new(x: T): string; new(x: T, y?: T): string }) { ->foo6 : (cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->T : T ->cb : { new (x: T): string; new (x: T, y?: T): string; } ->x : T ->T : T ->x : T ->T : T ->y : T ->T : T - - return cb; ->cb : { new (x: T): string; new (x: T, y?: T): string; } - } - - var r8 = foo6(a); // new{} => string; new(x:{}, y?:{}) => string ->r8 : { new (x: {}): string; new (x: {}, y?: {}): string; } ->foo6(a) : { new (x: {}): string; new (x: {}, y?: {}): string; } ->foo6 : (cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->a : { new (x: boolean): string; new (x: number): boolean; } - - var r9 = foo6(b); // new any => string; new(x:any, y?:any) => string ->r9 : { new (x: any): string; new (x: any, y?: any): string; } ->foo6(b) : { new (x: any): string; new (x: any, y?: any): string; } ->foo6 : (cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->b : { new (x: T): string; new (x: number): T; } - - function foo7(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }) { ->foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->T : T ->x : T ->T : T ->cb : { new (x: T): string; new (x: T, y?: T): string; } ->x : T ->T : T ->x : T ->T : T ->y : T ->T : T - - return cb; ->cb : { new (x: T): string; new (x: T, y?: T): string; } - } - - var r13 = foo7(1, b); // new any => string; new(x:any, y?:any) => string ->r13 : { new (x: any): string; new (x: any, y?: any): string; } ->foo7(1, b) : { new (x: any): string; new (x: any, y?: any): string; } ->foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->b : { new (x: T): string; new (x: number): T; } - - var c: { new (x: T): string; (x: number): T; } ->c : { (x: number): T; new (x: T): string; } ->T : T ->x : T ->T : T ->T : T ->x : number ->T : T - - var c2: { new (x: T): string; new(x: number): T; } ->c2 : { new (x: T): string; new (x: number): T; } ->T : T ->x : T ->T : T ->T : T ->x : number ->T : T - - var r14 = foo7(1, c); // new any => string; new(x:any, y?:any) => string ->r14 : { new (x: any): string; new (x: any, y?: any): string; } ->foo7(1, c) : { new (x: any): string; new (x: any, y?: any): string; } ->foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->c : { (x: number): T; new (x: T): string; } - - var r15 = foo7(1, c2); // new any => string; new(x:any, y?:any) => string ->r15 : { new (x: any): string; new (x: any, y?: any): string; } ->foo7(1, c2) : { new (x: any): string; new (x: any, y?: any): string; } ->foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->c2 : { new (x: T): string; new (x: number): T; } -} diff --git a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.errors.txt b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.errors.txt new file mode 100644 index 00000000000..63ac5002f8a --- /dev/null +++ b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.errors.txt @@ -0,0 +1,81 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts(57,19): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts(60,19): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts(61,20): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts(62,30): error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts (4 errors) ==== + // Generic functions used as arguments for function typed parameters are not used to make inferences from + // Using function arguments, no errors expected + + module ImmediatelyFix { + class C { + foo(x: (a: T) => T) { + return x(null); + } + } + + var c = new C(); + var r = c.foo((x: U) => ''); // {} + var r2 = c.foo((x: U) => ''); // string + var r3 = c.foo(x => ''); // {} + + class C2 { + foo(x: (a: T) => T) { + return x(null); + } + } + + var c2 = new C2(); + var ra = c2.foo((x: U) => 1); // number + var r3a = c2.foo(x => 1); // number + } + + module WithCandidates { + class C { + foo2(x: T, cb: (a: T) => U) { + return cb(x); + } + } + + var c: C; + var r4 = c.foo2(1, function (a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions + var r5 = c.foo2(1, (a) => ''); // string + var r6 = c.foo2('', (a: Z) => 1); // number + + class C2 { + foo3(x: T, cb: (a: T) => U, y: U) { + return cb(x); + } + } + + var c2: C2; + var r7 = c2.foo3(1, (a: Z) => '', ''); // string + var r8 = c2.foo3(1, function (a) { return '' }, ''); // string + + class C3 { + foo3(x: T, cb: (a: T) => U, y: U) { + return cb(x); + } + } + var c3: C3; + + function other(t: T, u: U) { + var r10 = c.foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r10 = c.foo2(1, (x) => ''); // string + + var r11 = c3.foo3(1, (x: T) => '', ''); // string + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r11b = c3.foo3(1, (x: T) => '', 1); // {} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r12 = c3.foo3(1, function (a) { return '' }, 1); // {} + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.types b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.types deleted file mode 100644 index 68b94d81d02..00000000000 --- a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.types +++ /dev/null @@ -1,297 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts === -// Generic functions used as arguments for function typed parameters are not used to make inferences from -// Using function arguments, no errors expected - -module ImmediatelyFix { ->ImmediatelyFix : typeof ImmediatelyFix - - class C { ->C : C ->T : T - - foo(x: (a: T) => T) { ->foo : (x: (a: T) => T) => T ->T : T ->x : (a: T) => T ->a : T ->T : T ->T : T - - return x(null); ->x(null) : T ->x : (a: T) => T - } - } - - var c = new C(); ->c : C ->new C() : C ->C : typeof C - - var r = c.foo((x: U) => ''); // {} ->r : {} ->c.foo((x: U) => '') : {} ->c.foo : (x: (a: T) => T) => T ->c : C ->foo : (x: (a: T) => T) => T ->(x: U) => '' : (x: U) => string ->U : U ->x : U ->U : U - - var r2 = c.foo((x: U) => ''); // string ->r2 : string ->c.foo((x: U) => '') : string ->c.foo : (x: (a: T) => T) => T ->c : C ->foo : (x: (a: T) => T) => T ->(x: U) => '' : (x: U) => string ->U : U ->x : U ->U : U - - var r3 = c.foo(x => ''); // {} ->r3 : {} ->c.foo(x => '') : {} ->c.foo : (x: (a: T) => T) => T ->c : C ->foo : (x: (a: T) => T) => T ->x => '' : (x: {}) => string ->x : {} - - class C2 { ->C2 : C2 ->T : T - - foo(x: (a: T) => T) { ->foo : (x: (a: T) => T) => T ->x : (a: T) => T ->a : T ->T : T ->T : T - - return x(null); ->x(null) : T ->x : (a: T) => T - } - } - - var c2 = new C2(); ->c2 : C2 ->new C2() : C2 ->C2 : typeof C2 - - var ra = c2.foo((x: U) => 1); // number ->ra : number ->c2.foo((x: U) => 1) : number ->c2.foo : (x: (a: number) => number) => number ->c2 : C2 ->foo : (x: (a: number) => number) => number ->(x: U) => 1 : (x: U) => number ->U : U ->x : U ->U : U - - var r3a = c2.foo(x => 1); // number ->r3a : number ->c2.foo(x => 1) : number ->c2.foo : (x: (a: number) => number) => number ->c2 : C2 ->foo : (x: (a: number) => number) => number ->x => 1 : (x: number) => number ->x : number -} - -module WithCandidates { ->WithCandidates : typeof WithCandidates - - class C { ->C : C ->T : T - - foo2(x: T, cb: (a: T) => U) { ->foo2 : (x: T, cb: (a: T) => U) => U ->T : T ->U : U ->x : T ->T : T ->cb : (a: T) => U ->a : T ->T : T ->U : U - - return cb(x); ->cb(x) : U ->cb : (a: T) => U ->x : T - } - } - - var c: C; ->c : C ->C : C - - var r4 = c.foo2(1, function (a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions ->r4 : string ->c.foo2(1, function (a: Z) { return '' }) : string ->c.foo2 : (x: T, cb: (a: T) => U) => U ->c : C ->foo2 : (x: T, cb: (a: T) => U) => U ->function (a: Z) { return '' } : (a: Z) => string ->Z : Z ->a : Z ->Z : Z - - var r5 = c.foo2(1, (a) => ''); // string ->r5 : string ->c.foo2(1, (a) => '') : string ->c.foo2 : (x: T, cb: (a: T) => U) => U ->c : C ->foo2 : (x: T, cb: (a: T) => U) => U ->(a) => '' : (a: number) => string ->a : number - - var r6 = c.foo2('', (a: Z) => 1); // number ->r6 : number ->c.foo2('', (a: Z) => 1) : number ->c.foo2 : (x: T, cb: (a: T) => U) => U ->c : C ->foo2 : (x: T, cb: (a: T) => U) => U ->(a: Z) => 1 : (a: Z) => number ->Z : Z ->a : Z ->Z : Z - - class C2 { ->C2 : C2 ->T : T ->U : U - - foo3(x: T, cb: (a: T) => U, y: U) { ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->x : T ->T : T ->cb : (a: T) => U ->a : T ->T : T ->U : U ->y : U ->U : U - - return cb(x); ->cb(x) : U ->cb : (a: T) => U ->x : T - } - } - - var c2: C2; ->c2 : C2 ->C2 : C2 - - var r7 = c2.foo3(1, (a: Z) => '', ''); // string ->r7 : string ->c2.foo3(1, (a: Z) => '', '') : string ->c2.foo3 : (x: number, cb: (a: number) => string, y: string) => string ->c2 : C2 ->foo3 : (x: number, cb: (a: number) => string, y: string) => string ->(a: Z) => '' : (a: Z) => string ->Z : Z ->a : Z ->Z : Z - - var r8 = c2.foo3(1, function (a) { return '' }, ''); // string ->r8 : string ->c2.foo3(1, function (a) { return '' }, '') : string ->c2.foo3 : (x: number, cb: (a: number) => string, y: string) => string ->c2 : C2 ->foo3 : (x: number, cb: (a: number) => string, y: string) => string ->function (a) { return '' } : (a: number) => string ->a : number - - class C3 { ->C3 : C3 ->T : T ->U : U - - foo3(x: T, cb: (a: T) => U, y: U) { ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->T : T ->U : U ->x : T ->T : T ->cb : (a: T) => U ->a : T ->T : T ->U : U ->y : U ->U : U - - return cb(x); ->cb(x) : U ->cb : (a: T) => U ->x : T - } - } - var c3: C3; ->c3 : C3 ->C3 : C3 - - function other(t: T, u: U) { ->other : (t: T, u: U) => void ->T : T ->U : U ->t : T ->T : T ->u : U ->U : U - - var r10 = c.foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made ->r10 : string ->c.foo2(1, (x: T) => '') : string ->c.foo2 : (x: T, cb: (a: T) => U) => U ->c : C ->foo2 : (x: T, cb: (a: T) => U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r10 = c.foo2(1, (x) => ''); // string ->r10 : string ->c.foo2(1, (x) => '') : string ->c.foo2 : (x: T, cb: (a: T) => U) => U ->c : C ->foo2 : (x: T, cb: (a: T) => U) => U ->(x) => '' : (x: number) => string ->x : number - - var r11 = c3.foo3(1, (x: T) => '', ''); // string ->r11 : string ->c3.foo3(1, (x: T) => '', '') : string ->c3.foo3 : (x: T, cb: (a: T) => U, y: U) => U ->c3 : C3 ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r11b = c3.foo3(1, (x: T) => '', 1); // {} ->r11b : {} ->c3.foo3(1, (x: T) => '', 1) : {} ->c3.foo3 : (x: T, cb: (a: T) => U, y: U) => U ->c3 : C3 ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r12 = c3.foo3(1, function (a) { return '' }, 1); // {} ->r12 : {} ->c3.foo3(1, function (a) { return '' }, 1) : {} ->c3.foo3 : (x: T, cb: (a: T) => U, y: U) => U ->c3 : C3 ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->function (a) { return '' } : (a: number) => string ->a : number - } -} diff --git a/tests/baselines/reference/genericRestArgs.errors.txt b/tests/baselines/reference/genericRestArgs.errors.txt index db36a9a0162..49f61de325f 100644 --- a/tests/baselines/reference/genericRestArgs.errors.txt +++ b/tests/baselines/reference/genericRestArgs.errors.txt @@ -1,10 +1,14 @@ +tests/cases/compiler/genericRestArgs.ts(2,12): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/genericRestArgs.ts(5,34): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. +tests/cases/compiler/genericRestArgs.ts(10,12): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/genericRestArgs.ts(12,30): error TS2345: Argument of type 'number' is not assignable to parameter of type 'any[]'. -==== tests/cases/compiler/genericRestArgs.ts (2 errors) ==== +==== tests/cases/compiler/genericRestArgs.ts (4 errors) ==== function makeArrayG(...items: T[]): T[] { return items; } var a1Ga = makeArrayG(1, ""); // no error + ~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var a1Gb = makeArrayG(1, ""); var a1Gc = makeArrayG(1, ""); var a1Gd = makeArrayG(1, ""); // error @@ -15,6 +19,8 @@ tests/cases/compiler/genericRestArgs.ts(12,30): error TS2345: Argument of type ' return [item1, item2, item3]; } var a2Ga = makeArrayGOpt(1, ""); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var a2Gb = makeArrayG(1, ""); var a2Gc = makeArrayG(1, ""); // error ~ diff --git a/tests/baselines/reference/genericTypeArgumentInference1.types b/tests/baselines/reference/genericTypeArgumentInference1.types index 20a9a0ca8f9..c7d932befb8 100644 --- a/tests/baselines/reference/genericTypeArgumentInference1.types +++ b/tests/baselines/reference/genericTypeArgumentInference1.types @@ -42,12 +42,12 @@ declare var _: Underscore.Static; >Static : Underscore.Static var r = _.all([true, 1, null, 'yes'], _.identity); ->r : {} ->_.all([true, 1, null, 'yes'], _.identity) : {} +>r : string | number | boolean +>_.all([true, 1, null, 'yes'], _.identity) : string | number | boolean >_.all : (list: T[], iterator?: Underscore.Iterator, context?: any) => T >_ : Underscore.Static >all : (list: T[], iterator?: Underscore.Iterator, context?: any) => T ->[true, 1, null, 'yes'] : {}[] +>[true, 1, null, 'yes'] : Array >_.identity : (value: T) => T >_ : Underscore.Static >identity : (value: T) => T diff --git a/tests/baselines/reference/genericsManyTypeParameters.types b/tests/baselines/reference/genericsManyTypeParameters.types index 65f9a7c115e..df2144de866 100644 --- a/tests/baselines/reference/genericsManyTypeParameters.types +++ b/tests/baselines/reference/genericsManyTypeParameters.types @@ -1,6 +1,6 @@ === tests/cases/compiler/genericsManyTypeParameters.ts === function Foo< ->Foo : (x1: a1, y1: a21, z1: a31, a1: a41, b1: a51, c1: a61, x2: a119, y2: a22, z2: a32, a2: a42, b2: a52, c2: a62, x3: a219, y3: a23, z3: a33, a3: a43, b3: a53, c3: a63, x4: a319, y4: a24, z4: a34, a4: a44, b4: a54, c4: a64, x5: a419, y5: a25, z5: a35, a5: a45, b5: a55, c5: a65, x6: a519, y6: a26, z6: a36, a6: a46, b6: a56, c6: a66, x7: a619, y7: a27, z7: a37, a7: a47, b7: a57, c7: a67, x8: a71, y8: a28, z8: a38, a8: a48, b8: a58, c8: a68, x9: a81, y9: a29, z9: a39, a9: a49, b9: a59, c9: a69, x10: a91, y12: a210, z10: a310, a10: a410, b10: a510, c10: a610, x11: a111, y13: a211, z11: a311, a11: a411, b11: a511, c11: a611, x12: a112, y14: a212, z12: a312, a12: a412, b12: a512, c12: a612, x13: a113, y15: a213, z13: a313, a13: a413, b13: a513, c13: a613, x14: a114, y16: a214, z14: a314, a14: a414, b14: a514, c14: a614, x15: a115, y17: a215, z15: a315, a15: a415, b15: a515, c15: a615, x16: a116, y18: a216, z16: a316, a16: a416, b16: a516, c16: a616, x17: a117, y19: a217, z17: a317, a17: a417, b17: a517, c17: a617, x18: a118, y10: a218, z18: a318, a18: a418, b18: a518, c18: a618) => {}[] +>Foo : (x1: a1, y1: a21, z1: a31, a1: a41, b1: a51, c1: a61, x2: a119, y2: a22, z2: a32, a2: a42, b2: a52, c2: a62, x3: a219, y3: a23, z3: a33, a3: a43, b3: a53, c3: a63, x4: a319, y4: a24, z4: a34, a4: a44, b4: a54, c4: a64, x5: a419, y5: a25, z5: a35, a5: a45, b5: a55, c5: a65, x6: a519, y6: a26, z6: a36, a6: a46, b6: a56, c6: a66, x7: a619, y7: a27, z7: a37, a7: a47, b7: a57, c7: a67, x8: a71, y8: a28, z8: a38, a8: a48, b8: a58, c8: a68, x9: a81, y9: a29, z9: a39, a9: a49, b9: a59, c9: a69, x10: a91, y12: a210, z10: a310, a10: a410, b10: a510, c10: a610, x11: a111, y13: a211, z11: a311, a11: a411, b11: a511, c11: a611, x12: a112, y14: a212, z12: a312, a12: a412, b12: a512, c12: a612, x13: a113, y15: a213, z13: a313, a13: a413, b13: a513, c13: a613, x14: a114, y16: a214, z14: a314, a14: a414, b14: a514, c14: a614, x15: a115, y17: a215, z15: a315, a15: a415, b15: a515, c15: a615, x16: a116, y18: a216, z16: a316, a16: a416, b16: a516, c16: a616, x17: a117, y19: a217, z17: a317, a17: a417, b17: a517, c17: a617, x18: a118, y10: a218, z18: a318, a18: a418, b18: a518, c18: a618) => Array a1, a21, a31, a41, a51, a61, >a1 : a1 @@ -402,7 +402,7 @@ function Foo< ) { return [x1 , y1 , z1 , a1 , b1 , c1, ->[x1 , y1 , z1 , a1 , b1 , c1, x2 , y2 , z2 , a2 , b2 , c2, x3 , y3 , z3 , a3 , b3 , c3, x4 , y4 , z4 , a4 , b4 , c4, x5 , y5 , z5 , a5 , b5 , c5, x6 , y6 , z6 , a6 , b6 , c6, x7 , y7 , z7 , a7 , b7 , c7, x8 , y8 , z8 , a8 , b8 , c8, x9 , y9 , z9 , a9 , b9 , c9, x10 , y12 , z10 , a10 , b10 , c10, x11 , y13 , z11 , a11 , b11 , c11, x12 , y14 , z12 , a12 , b12 , c12, x13 , y15 , z13 , a13 , b13 , c13, x14 , y16 , z14 , a14 , b14 , c14, x15 , y17 , z15 , a15 , b15 , c15, x16 , y18 , z16 , a16 , b16 , c16, x17 , y19 , z17 , a17 , b17 , c17, x18 , y10 , z18 , a18 , b18 , c18] : {}[] +>[x1 , y1 , z1 , a1 , b1 , c1, x2 , y2 , z2 , a2 , b2 , c2, x3 , y3 , z3 , a3 , b3 , c3, x4 , y4 , z4 , a4 , b4 , c4, x5 , y5 , z5 , a5 , b5 , c5, x6 , y6 , z6 , a6 , b6 , c6, x7 , y7 , z7 , a7 , b7 , c7, x8 , y8 , z8 , a8 , b8 , c8, x9 , y9 , z9 , a9 , b9 , c9, x10 , y12 , z10 , a10 , b10 , c10, x11 , y13 , z11 , a11 , b11 , c11, x12 , y14 , z12 , a12 , b12 , c12, x13 , y15 , z13 , a13 , b13 , c13, x14 , y16 , z14 , a14 , b14 , c14, x15 , y17 , z15 , a15 , b15 , c15, x16 , y18 , z16 , a16 , b16 , c16, x17 , y19 , z17 , a17 , b17 , c17, x18 , y10 , z18 , a18 , b18 , c18] : Array >x1 : a1 >y1 : a21 >z1 : a31 diff --git a/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt b/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt index 072d06e8686..985aaa7948c 100644 --- a/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt +++ b/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt @@ -1,5 +1,6 @@ -tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,19): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'string[]'. - Type '{}' is not assignable to type 'string'. +tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,19): error TS2345: Argument of type 'Array' is not assignable to parameter of type 'string[]'. + Type 'string | number' is not assignable to type 'string': + Type 'number' is not assignable to type 'string'. ==== tests/cases/compiler/heterogeneousArrayAndOverloads.ts (1 errors) ==== @@ -13,7 +14,8 @@ tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,19): error TS2345: Argu this.test([]); this.test([1, 2, "hi", 5]); // Error ~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'string[]'. -!!! error TS2345: Type '{}' is not assignable to type 'string'. +!!! error TS2345: Argument of type 'Array' is not assignable to parameter of type 'string[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'string': +!!! error TS2345: Type 'number' is not assignable to type 'string'. } } \ No newline at end of file diff --git a/tests/baselines/reference/heterogeneousArrayLiterals.types b/tests/baselines/reference/heterogeneousArrayLiterals.types index 81770731633..882fe1e8295 100644 --- a/tests/baselines/reference/heterogeneousArrayLiterals.types +++ b/tests/baselines/reference/heterogeneousArrayLiterals.types @@ -2,16 +2,16 @@ // type of an array is the best common type of its elements (plus its contextual type if it exists) var a = [1, '']; // {}[] ->a : {}[] ->[1, ''] : {}[] +>a : Array +>[1, ''] : Array var b = [1, null]; // number[] >b : number[] >[1, null] : number[] var c = [1, '', null]; // {}[] ->c : {}[] ->[1, '', null] : {}[] +>c : Array +>[1, '', null] : Array var d = [{}, 1]; // {}[] >d : {}[] @@ -31,8 +31,8 @@ var f = [[], [1]]; // number[][] >[1] : number[] var g = [[1], ['']]; // {}[] ->g : {}[] ->[[1], ['']] : {}[] +>g : Array +>[[1], ['']] : Array >[1] : number[] >[''] : string[] @@ -46,8 +46,8 @@ var h = [{ foo: 1, bar: '' }, { foo: 2 }]; // {foo: number}[] >foo : number var i = [{ foo: 1, bar: '' }, { foo: '' }]; // {}[] ->i : {}[] ->[{ foo: 1, bar: '' }, { foo: '' }] : {}[] +>i : Array<{ foo: number; bar: string; } | { foo: string; }> +>[{ foo: 1, bar: '' }, { foo: '' }] : Array<{ foo: number; bar: string; } | { foo: string; }> >{ foo: 1, bar: '' } : { foo: number; bar: string; } >foo : number >bar : string @@ -55,8 +55,8 @@ var i = [{ foo: 1, bar: '' }, { foo: '' }]; // {}[] >foo : string var j = [() => 1, () => '']; // {}[] ->j : {}[] ->[() => 1, () => ''] : {}[] +>j : Array<{ (): number; } | { (): string; }> +>[() => 1, () => ''] : Array<{ (): number; } | { (): string; }> >() => 1 : () => number >() => '' : () => string @@ -80,8 +80,8 @@ var m = [() => 1, () => '', () => null]; // { (): any }[] >() => null : () => any var n = [[() => 1], [() => '']]; // {}[] ->n : {}[] ->[[() => 1], [() => '']] : {}[] +>n : Array<{ (): number; }[] | { (): string; }[]> +>[[() => 1], [() => '']] : Array<{ (): number; }[] | { (): string; }[]> >[() => 1] : { (): number; }[] >() => 1 : () => number >[() => ''] : { (): string; }[] @@ -129,8 +129,8 @@ module Derived { >base : Base var i = [{ foo: base, basear: derived }, { foo: derived }]; // {foo: Derived}[] ->i : {}[] ->[{ foo: base, basear: derived }, { foo: derived }] : {}[] +>i : Array<{ foo: Base; basear: Derived; } | { foo: Derived; }> +>[{ foo: base, basear: derived }, { foo: derived }] : Array<{ foo: Base; basear: Derived; } | { foo: Derived; }> >{ foo: base, basear: derived } : { foo: Base; basear: Derived; } >foo : Base >base : Base @@ -149,8 +149,8 @@ module Derived { >derived : Derived var k = [() => base, () => 1]; // {}[]~ ->k : {}[] ->[() => base, () => 1] : {}[] +>k : Array<{ (): Base; } | { (): number; }> +>[() => base, () => 1] : Array<{ (): Base; } | { (): number; }> >() => base : () => Base >base : Base >() => 1 : () => number @@ -182,8 +182,8 @@ module Derived { >derived : Derived var o = [derived, derived2]; // {}[] ->o : {}[] ->[derived, derived2] : {}[] +>o : Array +>[derived, derived2] : Array >derived : Derived >derived2 : Derived2 @@ -195,8 +195,8 @@ module Derived { >base : Base var q = [[() => derived2], [() => derived]]; // {}[] ->q : {}[] ->[[() => derived2], [() => derived]] : {}[] +>q : Array<{ (): Derived2; }[] | { (): Derived; }[]> +>[[() => derived2], [() => derived]] : Array<{ (): Derived2; }[] | { (): Derived; }[]> >[() => derived2] : { (): Derived2; }[] >() => derived2 : () => Derived2 >derived2 : Derived2 @@ -257,19 +257,19 @@ function foo(t: T, u: U) { >t : T var c = [t, u]; // {}[] ->c : {}[] ->[t, u] : {}[] +>c : Array +>[t, u] : Array >t : T >u : U var d = [t, 1]; // {}[] ->d : {}[] ->[t, 1] : {}[] +>d : Array +>[t, 1] : Array >t : T var e = [() => t, () => u]; // {}[] ->e : {}[] ->[() => t, () => u] : {}[] +>e : Array<{ (): T; } | { (): U; }> +>[() => t, () => u] : Array<{ (): T; } | { (): U; }> >() => t : () => T >t : T >() => u : () => U @@ -308,19 +308,19 @@ function foo2(t: T, u: U) { >t : T var c = [t, u]; // {}[] ->c : {}[] ->[t, u] : {}[] +>c : Array +>[t, u] : Array >t : T >u : U var d = [t, 1]; // {}[] ->d : {}[] ->[t, 1] : {}[] +>d : Array +>[t, 1] : Array >t : T var e = [() => t, () => u]; // {}[] ->e : {}[] ->[() => t, () => u] : {}[] +>e : Array<{ (): T; } | { (): U; }> +>[() => t, () => u] : Array<{ (): T; } | { (): U; }> >() => t : () => T >t : T >() => u : () => U @@ -342,8 +342,8 @@ function foo2(t: T, u: U) { >base : Base var h = [t, derived]; // Derived[] ->h : {}[] ->[t, derived] : {}[] +>h : Array +>[t, derived] : Array >t : T >derived : Derived @@ -383,19 +383,19 @@ function foo3(t: T, u: U) { >t : T var c = [t, u]; // {}[] ->c : {}[] ->[t, u] : {}[] +>c : Array +>[t, u] : Array >t : T >u : U var d = [t, 1]; // {}[] ->d : {}[] ->[t, 1] : {}[] +>d : Array +>[t, 1] : Array >t : T var e = [() => t, () => u]; // {}[] ->e : {}[] ->[() => t, () => u] : {}[] +>e : Array<{ (): T; } | { (): U; }> +>[() => t, () => u] : Array<{ (): T; } | { (): U; }> >() => t : () => T >t : T >() => u : () => U @@ -458,19 +458,19 @@ function foo4(t: T, u: U) { >t : T var c = [t, u]; // BUG 821629 ->c : {}[] ->[t, u] : {}[] +>c : Array +>[t, u] : Array >t : T >u : U var d = [t, 1]; // {}[] ->d : {}[] ->[t, 1] : {}[] +>d : Array +>[t, 1] : Array >t : T var e = [() => t, () => u]; // {}[] ->e : {}[] ->[() => t, () => u] : {}[] +>e : Array<{ (): T; } | { (): U; }> +>[() => t, () => u] : Array<{ (): T; } | { (): U; }> >() => t : () => T >t : T >() => u : () => U @@ -492,8 +492,8 @@ function foo4(t: T, u: U) { >base : Base var h = [t, derived]; // Derived[] ->h : {}[] ->[t, derived] : {}[] +>h : Array +>[t, derived] : Array >t : T >derived : Derived @@ -504,8 +504,8 @@ function foo4(t: T, u: U) { >base : Base var j = [u, derived]; // Derived[] ->j : {}[] ->[u, derived] : {}[] +>j : Array +>[u, derived] : Array >u : U >derived : Derived diff --git a/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt b/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt index 0a4761994dd..b82c82b9eb5 100644 --- a/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt +++ b/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt @@ -7,7 +7,7 @@ tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDec tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(40,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'I', but here has type 'C2'. tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(43,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'f' must be of type '(x: string) => number', but here has type '(x: number) => string'. tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(46,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. -tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(47,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '{}[]'. +tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(47,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'Array>'. tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(50,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'D[]', but here has type 'D[]'. tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(53,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'm' must be of type 'typeof M', but here has type 'typeof A'. @@ -79,7 +79,7 @@ tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDec !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. var arr = [new C(), new C2(), new D()]; ~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '{}[]'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'Array>'. var arr2 = [new D()]; var arr2 = new Array>(); diff --git a/tests/baselines/reference/logicalOrOperatorWithEveryType.types b/tests/baselines/reference/logicalOrOperatorWithEveryType.types index 3cf0399f437..3e3b0dcf37f 100644 --- a/tests/baselines/reference/logicalOrOperatorWithEveryType.types +++ b/tests/baselines/reference/logicalOrOperatorWithEveryType.types @@ -108,38 +108,38 @@ var rb2 = a2 || a2; // boolean || boolean is boolean >a2 : boolean var rb3 = a3 || a2; // number || boolean is {} ->rb3 : {} ->a3 || a2 : {} +>rb3 : number | boolean +>a3 || a2 : number | boolean >a3 : number >a2 : boolean var rb4 = a4 || a2; // string || boolean is {} ->rb4 : {} ->a4 || a2 : {} +>rb4 : string | boolean +>a4 || a2 : string | boolean >a4 : string >a2 : boolean var rb5 = a5 || a2; // void || boolean is {} ->rb5 : {} ->a5 || a2 : {} +>rb5 : boolean | void +>a5 || a2 : boolean | void >a5 : void >a2 : boolean var rb6 = a6 || a2; // enum || boolean is {} ->rb6 : {} ->a6 || a2 : {} +>rb6 : boolean | E +>a6 || a2 : boolean | E >a6 : E >a2 : boolean var rb7 = a7 || a2; // object || boolean is {} ->rb7 : {} ->a7 || a2 : {} +>rb7 : boolean | { a: string; } +>a7 || a2 : boolean | { a: string; } >a7 : { a: string; } >a2 : boolean var rb8 = a8 || a2; // array || boolean is {} ->rb8 : {} ->a8 || a2 : {} +>rb8 : boolean | string[] +>a8 || a2 : boolean | string[] >a8 : string[] >a2 : boolean @@ -161,8 +161,8 @@ var rc1 = a1 || a3; // any || number is any >a3 : number var rc2 = a2 || a3; // boolean || number is {} ->rc2 : {} ->a2 || a3 : {} +>rc2 : number | boolean +>a2 || a3 : number | boolean >a2 : boolean >a3 : number @@ -173,14 +173,14 @@ var rc3 = a3 || a3; // number || number is number >a3 : number var rc4 = a4 || a3; // string || number is {} ->rc4 : {} ->a4 || a3 : {} +>rc4 : string | number +>a4 || a3 : string | number >a4 : string >a3 : number var rc5 = a5 || a3; // void || number is {} ->rc5 : {} ->a5 || a3 : {} +>rc5 : number | void +>a5 || a3 : number | void >a5 : void >a3 : number @@ -191,14 +191,14 @@ var rc6 = a6 || a3; // enum || number is number >a3 : number var rc7 = a7 || a3; // object || number is {} ->rc7 : {} ->a7 || a3 : {} +>rc7 : number | { a: string; } +>a7 || a3 : number | { a: string; } >a7 : { a: string; } >a3 : number var rc8 = a8 || a3; // array || number is {} ->rc8 : {} ->a8 || a3 : {} +>rc8 : number | string[] +>a8 || a3 : number | string[] >a8 : string[] >a3 : number @@ -220,14 +220,14 @@ var rd1 = a1 || a4; // any || string is any >a4 : string var rd2 = a2 || a4; // boolean || string is {} ->rd2 : {} ->a2 || a4 : {} +>rd2 : string | boolean +>a2 || a4 : string | boolean >a2 : boolean >a4 : string var rd3 = a3 || a4; // number || string is {} ->rd3 : {} ->a3 || a4 : {} +>rd3 : string | number +>a3 || a4 : string | number >a3 : number >a4 : string @@ -238,26 +238,26 @@ var rd4 = a4 || a4; // string || string is string >a4 : string var rd5 = a5 || a4; // void || string is {} ->rd5 : {} ->a5 || a4 : {} +>rd5 : string | void +>a5 || a4 : string | void >a5 : void >a4 : string var rd6 = a6 || a4; // enum || string is {} ->rd6 : {} ->a6 || a4 : {} +>rd6 : string | E +>a6 || a4 : string | E >a6 : E >a4 : string var rd7 = a7 || a4; // object || string is {} ->rd7 : {} ->a7 || a4 : {} +>rd7 : string | { a: string; } +>a7 || a4 : string | { a: string; } >a7 : { a: string; } >a4 : string var rd8 = a8 || a4; // array || string is {} ->rd8 : {} ->a8 || a4 : {} +>rd8 : string | string[] +>a8 || a4 : string | string[] >a8 : string[] >a4 : string @@ -279,20 +279,20 @@ var re1 = a1 || a5; // any || void is any >a5 : void var re2 = a2 || a5; // boolean || void is {} ->re2 : {} ->a2 || a5 : {} +>re2 : boolean | void +>a2 || a5 : boolean | void >a2 : boolean >a5 : void var re3 = a3 || a5; // number || void is {} ->re3 : {} ->a3 || a5 : {} +>re3 : number | void +>a3 || a5 : number | void >a3 : number >a5 : void var re4 = a4 || a5; // string || void is {} ->re4 : {} ->a4 || a5 : {} +>re4 : string | void +>a4 || a5 : string | void >a4 : string >a5 : void @@ -303,20 +303,20 @@ var re5 = a5 || a5; // void || void is void >a5 : void var re6 = a6 || a5; // enum || void is {} ->re6 : {} ->a6 || a5 : {} +>re6 : void | E +>a6 || a5 : void | E >a6 : E >a5 : void var re7 = a7 || a5; // object || void is {} ->re7 : {} ->a7 || a5 : {} +>re7 : void | { a: string; } +>a7 || a5 : void | { a: string; } >a7 : { a: string; } >a5 : void var re8 = a8 || a5; // array || void is {} ->re8 : {} ->a8 || a5 : {} +>re8 : void | string[] +>a8 || a5 : void | string[] >a8 : string[] >a5 : void @@ -338,8 +338,8 @@ var rg1 = a1 || a6; // any || enum is any >a6 : E var rg2 = a2 || a6; // boolean || enum is {} ->rg2 : {} ->a2 || a6 : {} +>rg2 : boolean | E +>a2 || a6 : boolean | E >a2 : boolean >a6 : E @@ -350,14 +350,14 @@ var rg3 = a3 || a6; // number || enum is number >a6 : E var rg4 = a4 || a6; // string || enum is {} ->rg4 : {} ->a4 || a6 : {} +>rg4 : string | E +>a4 || a6 : string | E >a4 : string >a6 : E var rg5 = a5 || a6; // void || enum is {} ->rg5 : {} ->a5 || a6 : {} +>rg5 : void | E +>a5 || a6 : void | E >a5 : void >a6 : E @@ -368,14 +368,14 @@ var rg6 = a6 || a6; // enum || enum is E >a6 : E var rg7 = a7 || a6; // object || enum is {} ->rg7 : {} ->a7 || a6 : {} +>rg7 : E | { a: string; } +>a7 || a6 : E | { a: string; } >a7 : { a: string; } >a6 : E var rg8 = a8 || a6; // array || enum is {} ->rg8 : {} ->a8 || a6 : {} +>rg8 : string[] | E +>a8 || a6 : string[] | E >a8 : string[] >a6 : E @@ -397,32 +397,32 @@ var rh1 = a1 || a7; // any || object is any >a7 : { a: string; } var rh2 = a2 || a7; // boolean || object is {} ->rh2 : {} ->a2 || a7 : {} +>rh2 : boolean | { a: string; } +>a2 || a7 : boolean | { a: string; } >a2 : boolean >a7 : { a: string; } var rh3 = a3 || a7; // number || object is {} ->rh3 : {} ->a3 || a7 : {} +>rh3 : number | { a: string; } +>a3 || a7 : number | { a: string; } >a3 : number >a7 : { a: string; } var rh4 = a4 || a7; // string || object is {} ->rh4 : {} ->a4 || a7 : {} +>rh4 : string | { a: string; } +>a4 || a7 : string | { a: string; } >a4 : string >a7 : { a: string; } var rh5 = a5 || a7; // void || object is {} ->rh5 : {} ->a5 || a7 : {} +>rh5 : void | { a: string; } +>a5 || a7 : void | { a: string; } >a5 : void >a7 : { a: string; } var rh6 = a6 || a7; // enum || object is {} ->rh6 : {} ->a6 || a7 : {} +>rh6 : E | { a: string; } +>a6 || a7 : E | { a: string; } >a6 : E >a7 : { a: string; } @@ -433,8 +433,8 @@ var rh7 = a7 || a7; // object || object is object >a7 : { a: string; } var rh8 = a8 || a7; // array || object is {} ->rh8 : {} ->a8 || a7 : {} +>rh8 : string[] | { a: string; } +>a8 || a7 : string[] | { a: string; } >a8 : string[] >a7 : { a: string; } @@ -456,38 +456,38 @@ var ri1 = a1 || a8; // any || array is any >a8 : string[] var ri2 = a2 || a8; // boolean || array is {} ->ri2 : {} ->a2 || a8 : {} +>ri2 : boolean | string[] +>a2 || a8 : boolean | string[] >a2 : boolean >a8 : string[] var ri3 = a3 || a8; // number || array is {} ->ri3 : {} ->a3 || a8 : {} +>ri3 : number | string[] +>a3 || a8 : number | string[] >a3 : number >a8 : string[] var ri4 = a4 || a8; // string || array is {} ->ri4 : {} ->a4 || a8 : {} +>ri4 : string | string[] +>a4 || a8 : string | string[] >a4 : string >a8 : string[] var ri5 = a5 || a8; // void || array is {} ->ri5 : {} ->a5 || a8 : {} +>ri5 : void | string[] +>a5 || a8 : void | string[] >a5 : void >a8 : string[] var ri6 = a6 || a8; // enum || array is {} ->ri6 : {} ->a6 || a8 : {} +>ri6 : string[] | E +>a6 || a8 : string[] | E >a6 : E >a8 : string[] var ri7 = a7 || a8; // object || array is {} ->ri7 : {} ->a7 || a8 : {} +>ri7 : string[] | { a: string; } +>a7 || a8 : string[] | { a: string; } >a7 : { a: string; } >a8 : string[] diff --git a/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types b/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types index ff0e0ce568a..9a450b87784 100644 --- a/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types +++ b/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types @@ -22,8 +22,8 @@ function fn1(t: T, u: U) { >t : T var r3 = t || u; ->r3 : {} ->t || u : {} +>r3 : T | U +>t || u : T | U >t : T >u : U @@ -47,8 +47,8 @@ function fn2(t: T, u: U, v: V) { >V : V var r1 = t || u; ->r1 : {} ->t || u : {} +>r1 : T | U +>t || u : T | U >t : T >u : U @@ -67,8 +67,8 @@ function fn2(t: T, u: U, v: V) { >u : U var r5 = u || v; ->r5 : {} ->u || v : {} +>r5 : U | V +>u || v : U | V >u : U >v : V @@ -95,8 +95,8 @@ function fn3U : U var r1 = t || u; ->r1 : {} ->t || u : {} +>r1 : T | U +>t || u : T | U >t : T >u : U diff --git a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt index 557f60967a6..ed4f45ec1de 100644 --- a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt +++ b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt @@ -1,5 +1,6 @@ -tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(10,30): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. - Type '{}' is not assignable to type 'number'. +tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(10,30): error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): error TS2346: Supplied parameters do not match any signature of call target. @@ -15,8 +16,9 @@ tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): e var r6 = map([1, ""], (x) => x.toString()); var r7 = map([1, ""], (x) => x.toString()); // error ~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type '{}' is not assignable to type 'number'. +!!! error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number': +!!! error TS2345: Type 'string' is not assignable to type 'number'. var r7b = map([1, ""], (x) => x.toString()); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. diff --git a/tests/baselines/reference/nonContextuallyTypedLogicalOr.errors.txt b/tests/baselines/reference/nonContextuallyTypedLogicalOr.errors.txt deleted file mode 100644 index ca4dc9f67e3..00000000000 --- a/tests/baselines/reference/nonContextuallyTypedLogicalOr.errors.txt +++ /dev/null @@ -1,22 +0,0 @@ -tests/cases/compiler/nonContextuallyTypedLogicalOr.ts(16,10): error TS2339: Property 'dummy' does not exist on type '{}'. - - -==== tests/cases/compiler/nonContextuallyTypedLogicalOr.ts (1 errors) ==== - interface Contextual { - dummy; - p?: number; - } - - interface Ellement { - dummy; - p: any; - } - - var c: Contextual; - var e: Ellement; - - // This should error. Even though we are contextually typing e with Contextual, the RHS still - // needs to be a supertype of the LHS to win as the best common type. - (c || e).dummy; - ~~~~~ -!!! error TS2339: Property 'dummy' does not exist on type '{}'. \ No newline at end of file diff --git a/tests/baselines/reference/nonContextuallyTypedLogicalOr.types b/tests/baselines/reference/nonContextuallyTypedLogicalOr.types new file mode 100644 index 00000000000..4d15083c3b7 --- /dev/null +++ b/tests/baselines/reference/nonContextuallyTypedLogicalOr.types @@ -0,0 +1,39 @@ +=== tests/cases/compiler/nonContextuallyTypedLogicalOr.ts === +interface Contextual { +>Contextual : Contextual + + dummy; +>dummy : any + + p?: number; +>p : number +} + +interface Ellement { +>Ellement : Ellement + + dummy; +>dummy : any + + p: any; +>p : any +} + +var c: Contextual; +>c : Contextual +>Contextual : Contextual + +var e: Ellement; +>e : Ellement +>Ellement : Ellement + +// This should error. Even though we are contextually typing e with Contextual, the RHS still +// needs to be a supertype of the LHS to win as the best common type. +(c || e).dummy; +>(c || e).dummy : any +>(c || e) : Contextual | Ellement +>c || e : Contextual | Ellement +>c : Contextual +>e : Ellement +>dummy : any + diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt index fd23cab9956..7fb3d450f01 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt @@ -10,9 +10,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(55,5): error TS2412: Property '"4.0"' of type 'number' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(68,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(73,5): error TS2412: Property '"4.0"' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: number]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: unknown; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }': +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: unknown; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }': Index signatures are incompatible: - Type '{}' is not assignable to type 'string'. + Type 'string | number' is not assignable to type 'string': + Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(88,9): error TS2304: Cannot find name 'Myn'. @@ -116,9 +117,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo // error var b: { [x: number]: string; } = { ~ -!!! error TS2322: Type '{ [x: number]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: unknown; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }': +!!! error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: unknown; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }': !!! error TS2322: Index signatures are incompatible: -!!! error TS2322: Type '{}' is not assignable to type 'string'. +!!! error TS2322: Type 'string | number' is not assignable to type 'string': +!!! error TS2322: Type 'number' is not assignable to type 'string'. a: '', b: 1, c: () => { }, diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt index 0e9cff15560..4d0488ec80f 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt @@ -4,10 +4,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(26,5): error TS2412: Property '"4.0"' of type 'string' is not assignable to numeric index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(34,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(35,5): error TS2412: Property '"4.0"' of type 'string' is not assignable to numeric index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(39,5): error TS2322: Type '{ [x: number]: {}; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }': +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(39,5): error TS2322: Type '{ [x: number]: string | number | A; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }': Index signatures are incompatible: - Type '{}' is not assignable to type 'A': - Property 'foo' is missing in type '{}'. + Type 'string | number | A' is not assignable to type 'A': + Type 'string' is not assignable to type 'A'. ==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts (7 errors) ==== @@ -63,10 +63,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo // error var b: { [x: number]: A } = { ~ -!!! error TS2322: Type '{ [x: number]: {}; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }': +!!! error TS2322: Type '{ [x: number]: string | number | A; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }': !!! error TS2322: Index signatures are incompatible: -!!! error TS2322: Type '{}' is not assignable to type 'A': -!!! error TS2322: Property 'foo' is missing in type '{}'. +!!! error TS2322: Type 'string | number | A' is not assignable to type 'A': +!!! error TS2322: Type 'string' is not assignable to type 'A'. 1.0: new A(), 2.0: new B(), "2.5": new B(), diff --git a/tests/baselines/reference/parser15.4.4.14-9-2.errors.txt b/tests/baselines/reference/parser15.4.4.14-9-2.errors.txt index ab9bab7890c..237541b40f7 100644 --- a/tests/baselines/reference/parser15.4.4.14-9-2.errors.txt +++ b/tests/baselines/reference/parser15.4.4.14-9-2.errors.txt @@ -1,7 +1,8 @@ +tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(16,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(25,1): error TS2304: Cannot find name 'runTestCase'. -==== tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts (2 errors) ==== /// Copyright (c) 2012 Ecma International. All rights reserved. /// Ecma International makes this code available under the terms and conditions set /// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the @@ -18,6 +19,8 @@ tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(25,1): error T var one = 1; var _float = -(4/3); var a = new Array(false,undefined,null,"0",obj,-1.3333333333333, "str",-0,true,+0, one, 1,0, false, _float, -(4/3)); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. if (a.indexOf(-(4/3)) === 14 && // a[14]=_float===-(4/3) a.indexOf(0) === 7 && // a[7] = +0, 0===+0 a.indexOf(-0) === 7 && // a[7] = +0, -0===+0 diff --git a/tests/baselines/reference/promisePermutations.errors.txt b/tests/baselines/reference/promisePermutations.errors.txt index ee723821cce..4ee3ea31de6 100644 --- a/tests/baselines/reference/promisePermutations.errors.txt +++ b/tests/baselines/reference/promisePermutations.errors.txt @@ -1,3 +1,4 @@ +tests/cases/compiler/promisePermutations.ts(74,70): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. tests/cases/compiler/promisePermutations.ts(79,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations.ts(82,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations.ts(83,19): error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. @@ -19,13 +20,20 @@ tests/cases/compiler/promisePermutations.ts(120,19): error TS2345: Argument of t tests/cases/compiler/promisePermutations.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations.ts(122,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations.ts(126,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(129,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/promisePermutations.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations.ts(134,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(137,11): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations.ts(144,12): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations.ts(152,12): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations.ts(156,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(159,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. -==== tests/cases/compiler/promisePermutations.ts (25 errors) ==== +==== tests/cases/compiler/promisePermutations.ts (33 errors) ==== interface Promise { then(success?: (value: T) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; then(success?: (value: T) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; @@ -100,6 +108,8 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); + ~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -197,6 +207,8 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -211,6 +223,8 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); @@ -218,6 +232,8 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -226,16 +242,24 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/baselines/reference/promisePermutations2.errors.txt b/tests/baselines/reference/promisePermutations2.errors.txt index f85a3eb925f..6c127f85f03 100644 --- a/tests/baselines/reference/promisePermutations2.errors.txt +++ b/tests/baselines/reference/promisePermutations2.errors.txt @@ -20,15 +20,20 @@ tests/cases/compiler/promisePermutations2.ts(119,19): error TS2345: Argument of tests/cases/compiler/promisePermutations2.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations2.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(125,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(128,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/promisePermutations2.ts(131,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations2.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(136,11): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations2.ts(143,12): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations2.ts(151,12): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations2.ts(155,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(157,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(158,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. -==== tests/cases/compiler/promisePermutations2.ts (28 errors) ==== +==== tests/cases/compiler/promisePermutations2.ts (33 errors) ==== // same as promisePermutations but without the same overloads in Promise interface Promise { @@ -201,6 +206,8 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -215,6 +222,8 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); @@ -222,6 +231,8 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -230,10 +241,14 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok ~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/promisePermutations3.errors.txt b/tests/baselines/reference/promisePermutations3.errors.txt index edd5f879043..636e89645b6 100644 --- a/tests/baselines/reference/promisePermutations3.errors.txt +++ b/tests/baselines/reference/promisePermutations3.errors.txt @@ -1,4 +1,5 @@ tests/cases/compiler/promisePermutations3.ts(68,69): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(73,70): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. tests/cases/compiler/promisePermutations3.ts(78,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations3.ts(81,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations3.ts(82,19): error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. @@ -20,15 +21,21 @@ tests/cases/compiler/promisePermutations3.ts(119,19): error TS2345: Argument of tests/cases/compiler/promisePermutations3.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations3.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(125,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(128,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/promisePermutations3.ts(131,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations3.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(136,11): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations3.ts(143,12): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations3.ts(151,12): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/promisePermutations3.ts(155,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(157,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(158,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations3.ts(159,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of type '{ (x: T): IPromise; (x: T, y: T): Promise; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise'. -==== tests/cases/compiler/promisePermutations3.ts (28 errors) ==== +==== tests/cases/compiler/promisePermutations3.ts (35 errors) ==== // same as promisePermutations but without the same overloads in IPromise interface Promise { @@ -104,6 +111,8 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); + ~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -201,6 +210,8 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -215,6 +226,8 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); @@ -222,6 +235,8 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -230,6 +245,8 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; @@ -241,7 +258,11 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt index a731dcca188..b71b04263b1 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt @@ -24,9 +24,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(71,5): error TS2411: Property 'foo' of type '() => string' is not assignable to string index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(73,5): error TS2411: Property '"4.0"' of type 'number' is not assignable to string index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(74,5): error TS2411: Property 'f' of type 'MyString' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: string]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: string]: string | number | MyString | { (): void; }; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': Index signatures are incompatible: - Type '{}' is not assignable to type 'string'. + Type 'string | number | MyString | { (): void; }' is not assignable to type 'string': + Type 'number' is not assignable to type 'string'. ==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts (27 errors) ==== @@ -159,9 +160,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon // error var b: { [x: string]: string; } = { ~ -!!! error TS2322: Type '{ [x: string]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': +!!! error TS2322: Type '{ [x: string]: string | number | MyString | { (): void; }; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': !!! error TS2322: Index signatures are incompatible: -!!! error TS2322: Type '{}' is not assignable to type 'string'. +!!! error TS2322: Type 'string | number | MyString | { (): void; }' is not assignable to type 'string': +!!! error TS2322: Type 'number' is not assignable to type 'string'. a: '', b: 1, c: () => { }, diff --git a/tests/baselines/reference/subtypesOfTypeParameter.errors.txt b/tests/baselines/reference/subtypesOfTypeParameter.errors.txt index a986258bf11..bdb3c9a056f 100644 --- a/tests/baselines/reference/subtypesOfTypeParameter.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameter.errors.txt @@ -1,46 +1,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(7,7): error TS2416: Class 'D1' incorrectly extends base class 'C3': Types of property 'foo' are incompatible: Type 'U' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(12,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(13,13): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(38,14): error TS2367: No best common type exists between 'number' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(39,14): error TS2367: No best common type exists between 'T' and 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(41,14): error TS2367: No best common type exists between 'string' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(42,14): error TS2367: No best common type exists between 'T' and 'string'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(44,14): error TS2367: No best common type exists between 'boolean' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(45,14): error TS2367: No best common type exists between 'T' and 'boolean'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(47,14): error TS2367: No best common type exists between 'Date' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(48,14): error TS2367: No best common type exists between 'T' and 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(50,14): error TS2367: No best common type exists between 'RegExp' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(51,14): error TS2367: No best common type exists between 'T' and 'RegExp'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(53,14): error TS2367: No best common type exists between '{ foo: number; }' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(54,14): error TS2367: No best common type exists between 'T' and '{ foo: number; }'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(56,14): error TS2367: No best common type exists between '() => void' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(57,14): error TS2367: No best common type exists between 'T' and '() => void'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(59,14): error TS2367: No best common type exists between '(x: T) => T' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(60,15): error TS2367: No best common type exists between 'T' and '(x: T) => T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(63,14): error TS2367: No best common type exists between 'I1' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(64,14): error TS2367: No best common type exists between 'T' and 'I1'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(67,15): error TS2367: No best common type exists between 'C1' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(68,15): error TS2367: No best common type exists between 'T' and 'C1'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(72,15): error TS2367: No best common type exists between 'C2' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(73,15): error TS2367: No best common type exists between 'T' and 'C2'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(76,15): error TS2367: No best common type exists between 'typeof E' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(77,15): error TS2367: No best common type exists between 'T' and 'typeof E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(79,15): error TS2367: No best common type exists between 'E' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(80,15): error TS2367: No best common type exists between 'T' and 'E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(83,15): error TS2367: No best common type exists between 'typeof f' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(84,15): error TS2367: No best common type exists between 'T' and 'typeof f'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(87,15): error TS2367: No best common type exists between 'typeof c' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(88,15): error TS2367: No best common type exists between 'T' and 'typeof c'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(91,19): error TS2367: No best common type exists between 'T' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(92,19): error TS2367: No best common type exists between 'T' and 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(95,21): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(96,19): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(97,19): error TS2367: No best common type exists between 'U' and 'T'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts (38 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts (2 errors) ==== // checking whether other types are subtypes of type parameters class C3 { @@ -57,11 +21,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf function f1(x: T, y: U) { var r = true ? x : y; // error - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? y : x; // error - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. } interface I1 { foo: number; } @@ -87,135 +47,67 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf var r0b = true ? x : u; var r1 = true ? 1 : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'number' and 'T'. var r1 = true ? x : 1; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'number'. var r2 = true ? '' : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'string' and 'T'. var r2 = true ? x : ''; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'string'. var r3 = true ? true : x; - ~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'boolean' and 'T'. var r3 = true ? x : true; - ~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'boolean'. var r4 = true ? new Date() : x; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Date' and 'T'. var r4 = true ? x : new Date(); - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'Date'. var r5 = true ? /1/ : x; - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'RegExp' and 'T'. var r5 = true ? x : /1/; - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'RegExp'. var r6 = true ? { foo: 1 } : x; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between '{ foo: number; }' and 'T'. var r6 = true ? x : { foo: 1 }; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and '{ foo: number; }'. var r7 = true ? () => { } : x; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between '() => void' and 'T'. var r7 = true ? x : () => { }; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and '() => void'. var r8 = true ? (x: T) => { return x } : x; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between '(x: T) => T' and 'T'. var r8b = true ? x : (x: T) => { return x }; // type parameters not identical across declarations - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and '(x: T) => T'. var i1: I1; var r9 = true ? i1 : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'I1' and 'T'. var r9 = true ? x : i1; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'I1'. var c1: C1; var r10 = true ? c1 : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'C1' and 'T'. var r10 = true ? x : c1; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'C1'. var c2: C2; var r12 = true ? c2 : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'C2' and 'T'. var r12 = true ? x : c2; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'C2'. var r13 = true ? E : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'typeof E' and 'T'. var r13 = true ? x : E; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'typeof E'. var r14 = true ? E.A : x; - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'E' and 'T'. var r14 = true ? x : E.A; - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'E'. var af: typeof f; var r15 = true ? af : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'typeof f' and 'T'. var r15 = true ? x : af; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'typeof f'. var ac: typeof c; var r16 = true ? ac : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'typeof c' and 'T'. var r16 = true ? x : ac; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'typeof c'. function f17(a: T) { var r17 = true ? x : a; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'T'. var r17 = true ? a : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'T'. } function f18(a: U) { ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. var r18 = true ? x : a; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r18 = true ? a : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. } var r19 = true ? new Object() : x; // BCT is Object diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.errors.txt index c2b429c08bb..7f23cb39c8c 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.errors.txt @@ -1,46 +1,20 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(3,13): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(4,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(5,13): error TS2367: No best common type exists between 'U' and 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(9,13): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(9,26): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(10,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(11,13): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(14,14): error TS2367: No best common type exists between 'V' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(15,14): error TS2367: No best common type exists between 'U' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(18,14): error TS2367: No best common type exists between 'V' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(19,14): error TS2367: No best common type exists between 'T' and 'V'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(18,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'r2' must be of type 'U | V', but here has type 'T | V'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(19,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'r2' must be of type 'U | V', but here has type 'T | V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(23,13): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(24,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(25,13): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(28,14): error TS2367: No best common type exists between 'T' and 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(29,14): error TS2367: No best common type exists between 'Date' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(60,14): error TS2367: No best common type exists between 'number' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(61,14): error TS2367: No best common type exists between 'T' and 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(65,14): error TS2367: No best common type exists between 'string' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(66,14): error TS2367: No best common type exists between 'T' and 'string'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(70,14): error TS2367: No best common type exists between 'boolean' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(71,14): error TS2367: No best common type exists between 'T' and 'boolean'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(118,15): error TS2367: No best common type exists between 'typeof E' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(119,15): error TS2367: No best common type exists between 'T' and 'typeof E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(121,15): error TS2367: No best common type exists between 'E' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(122,15): error TS2367: No best common type exists between 'T' and 'E'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(143,18): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(144,19): error TS2367: No best common type exists between 'T' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(145,19): error TS2367: No best common type exists between 'V' and 'T'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts (29 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts (7 errors) ==== // checking whether other types are subtypes of type parameters with constraints function f1(x: T, y: U) { ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. var r = true ? x : y; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? y : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. } // V > U > T @@ -50,27 +24,19 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. var r = true ? x : y; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? y : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. // ok var r2 = true ? z : y; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'U'. var r2 = true ? y : z; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'V'. // ok var r2 = true ? z : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'T'. + ~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'r2' must be of type 'U | V', but here has type 'T | V'. var r2 = true ? x : z; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'V'. + ~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'r2' must be of type 'U | V', but here has type 'T | V'. } // Date > U > T @@ -78,19 +44,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. var r = true ? x : y; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? y : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. // ok var r2 = true ? x : new Date(); - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'Date'. var r2 = true ? new Date() : x; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Date' and 'T'. // ok var r3 = true ? y : new Date(); @@ -122,29 +80,17 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf function f5(x: T) { var r1 = true ? 1 : x; // error - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'number' and 'T'. var r1 = true ? x : 1; // error - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'number'. } function f6(x: T) { var r2 = true ? '' : x; // error - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'string' and 'T'. var r2 = true ? x : ''; // error - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'string'. } function f7(x: T) { var r3 = true ? true : x; // error - ~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'boolean' and 'T'. var r3 = true ? x : true; // error - ~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'boolean'. } function f8(x: T) { @@ -192,18 +138,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf function f16(x: T) { var r13 = true ? E : x; // BUG 831833 - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'typeof E' and 'T'. var r13 = true ? x : E; // BUG 831833 - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'typeof E'. var r14 = true ? E.A : x; // BUG 831833 - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'E' and 'T'. var r14 = true ? x : E.A; // BUG 831833 - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'E'. } function f17(x: T) { @@ -228,11 +166,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. var r18 = true ? x : a; // ok - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'V'. var r18 = true ? a : x; // ok - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'T'. } } diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.errors.txt index f26389bb2a2..edb09275bed 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.errors.txt @@ -1,13 +1,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(3,12): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(5,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(6,13): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(9,14): error TS2367: No best common type exists between 'T' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(10,14): error TS2367: No best common type exists between 'V' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(13,14): error TS2367: No best common type exists between 'V' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(14,14): error TS2367: No best common type exists between 'U' and 'V'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts (7 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts (1 errors) ==== // checking whether other types are subtypes of type parameters with constraints function f(t: T, u: U, v: V) { @@ -15,25 +9,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. // ok var r = true ? t : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? u : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. // error var r2 = true ? t : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'V'. var r2 = true ? v : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'T'. // error var r3 = true ? v : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'U'. var r3 = true ? u : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'V'. } \ No newline at end of file diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt index 082d78d43d5..480090391e2 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt @@ -1,11 +1,3 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(6,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(7,13): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(10,14): error TS2367: No best common type exists between 'T' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(11,14): error TS2367: No best common type exists between 'V' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(14,14): error TS2367: No best common type exists between 'V' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(15,14): error TS2367: No best common type exists between 'U' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(26,14): error TS2367: No best common type exists between 'V' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(27,14): error TS2367: No best common type exists between 'Foo' and 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(45,7): error TS2416: Class 'D3' incorrectly extends base class 'B1': Types of property 'foo' are incompatible: Type 'V' is not assignable to type 'Foo': @@ -29,34 +21,22 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts (18 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts (10 errors) ==== // checking whether other types are subtypes of type parameters with constraints class Foo { foo: number; } function f(t: T, u: U, v: V) { // error var r = true ? t : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? u : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. // error var r2 = true ? t : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'V'. var r2 = true ? v : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'T'. // error var r3 = true ? v : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'U'. var r3 = true ? u : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'V'. // ok var r4 = true ? t : new Foo(); @@ -68,11 +48,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf // BUG, should be error var r6 = true ? v : new Foo(); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'Foo'. var r6 = true ? new Foo() : v; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'V'. } diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt index bf7cbbcae03..4f11fc6e1b9 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt @@ -1,30 +1,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(4,12): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(4,30): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(4,48): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(6,14): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(7,14): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(10,14): error TS2367: No best common type exists between 'T' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(11,14): error TS2367: No best common type exists between 'V' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(14,14): error TS2367: No best common type exists between 'V' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(15,14): error TS2367: No best common type exists between 'U' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(18,14): error TS2367: No best common type exists between 'T' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(19,14): error TS2367: No best common type exists between 'Foo' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(22,14): error TS2367: No best common type exists between 'U' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(23,14): error TS2367: No best common type exists between 'Foo' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(26,14): error TS2367: No best common type exists between 'V' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(27,14): error TS2367: No best common type exists between 'Foo' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(31,14): error TS2367: No best common type exists between 'T' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(32,14): error TS2367: No best common type exists between 'Foo' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(35,14): error TS2367: No best common type exists between 'U' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(36,14): error TS2367: No best common type exists between 'Foo' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(39,14): error TS2367: No best common type exists between 'V' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(40,14): error TS2367: No best common type exists between 'Foo' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(44,15): error TS2367: No best common type exists between 'T' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(45,15): error TS2367: No best common type exists between 'Foo' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(48,15): error TS2367: No best common type exists between 'U' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(49,15): error TS2367: No best common type exists between 'Foo' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(52,15): error TS2367: No best common type exists between 'V' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(53,15): error TS2367: No best common type exists between 'Foo' and 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(61,14): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(61,32): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(61,50): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. @@ -111,7 +87,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(153,50): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts (99 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts (75 errors) ==== // checking whether other types are subtypes of type parameters with constraints class Foo { foo: T; } @@ -124,101 +100,53 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. // error var r1 = true ? t : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r1 = true ? u : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. // error var r2 = true ? t : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'V'. var r2 = true ? v : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'T'. // error var r3 = true ? v : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'U'. var r3 = true ? u : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'V'. // ok? var r4 = true ? t : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'Foo'. var r4 = true ? new Foo() : t; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'T'. // ok? var r5 = true ? u : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'Foo'. var r5 = true ? new Foo() : u; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'U'. // ok? var r6 = true ? v : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'Foo'. var r6 = true ? new Foo() : v; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'V'. // ok? var r7 = true ? t : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'Foo'. var r7 = true ? new Foo() : t; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'T'. // ok? var r8 = true ? u : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'Foo'. var r8 = true ? new Foo() : u; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'U'. // ok? var r9 = true ? v : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'Foo'. var r9 = true ? new Foo() : v; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'V'. // ok? var r10 = true ? t : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'Foo'. var r10 = true ? new Foo() : t; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'T'. // ok? var r11 = true ? u : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'Foo'. var r11 = true ? new Foo() : u; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'U'. // ok? var r12 = true ? v : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'Foo'. var r12 = true ? new Foo() : v; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'V'. } module M1 { diff --git a/tests/baselines/reference/subtypingWithCallSignatures2.types b/tests/baselines/reference/subtypingWithCallSignatures2.types index 5006e00d52b..12344a46f3f 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures2.types +++ b/tests/baselines/reference/subtypingWithCallSignatures2.types @@ -368,8 +368,8 @@ var r2a = [r2arg1, r2arg2]; >r2arg2 : (x: number) => string[] var r2b = [r2arg2, r2arg1]; ->r2b : { (x: number): string[]; }[] ->[r2arg2, r2arg1] : { (x: number): string[]; }[] +>r2b : { (x: T): string[]; }[] +>[r2arg2, r2arg1] : { (x: T): string[]; }[] >r2arg2 : (x: number) => string[] >r2arg1 : (x: T) => string[] @@ -399,8 +399,8 @@ var r3a = [r3arg1, r3arg2]; >r3arg2 : (x: number) => void var r3b = [r3arg2, r3arg1]; ->r3b : { (x: number): void; }[] ->[r3arg2, r3arg1] : { (x: number): void; }[] +>r3b : { (x: T): T; }[] +>[r3arg2, r3arg1] : { (x: T): T; }[] >r3arg2 : (x: number) => void >r3arg1 : (x: T) => T @@ -795,8 +795,8 @@ var r12a = [r12arg1, r12arg2]; >r12arg2 : (x: Base[], y: Derived2[]) => Derived[] var r12b = [r12arg2, r12arg1]; ->r12b : { (x: Base[], y: Derived2[]): Derived[]; }[] ->[r12arg2, r12arg1] : { (x: Base[], y: Derived2[]): Derived[]; }[] +>r12b : { (x: Base[], y: T): Derived[]; }[] +>[r12arg2, r12arg1] : { (x: Base[], y: T): Derived[]; }[] >r12arg2 : (x: Base[], y: Derived2[]) => Derived[] >r12arg1 : (x: Base[], y: T) => Derived[] diff --git a/tests/baselines/reference/subtypingWithCallSignatures3.types b/tests/baselines/reference/subtypingWithCallSignatures3.types index 8c136113464..be5fb44c9c7 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures3.types +++ b/tests/baselines/reference/subtypingWithCallSignatures3.types @@ -340,14 +340,14 @@ module Errors { >r3arg : (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U var r3a = [r3arg2, r3arg]; ->r3a : {}[] ->[r3arg2, r3arg] : {}[] +>r3a : Array<{ (x: (arg: T) => U, y: (arg2: { foo: number; }) => U): (r: T) => U; } | { (x: (arg: Base) => Derived, y: (arg2: Base) => Derived): (r: Base) => Derived; }> +>[r3arg2, r3arg] : Array<{ (x: (arg: T) => U, y: (arg2: { foo: number; }) => U): (r: T) => U; } | { (x: (arg: Base) => Derived, y: (arg2: Base) => Derived): (r: Base) => Derived; }> >r3arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived >r3arg : (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U var r3b = [r3arg, r3arg2]; ->r3b : {}[] ->[r3arg, r3arg2] : {}[] +>r3b : Array<{ (x: (arg: T) => U, y: (arg2: { foo: number; }) => U): (r: T) => U; } | { (x: (arg: Base) => Derived, y: (arg2: Base) => Derived): (r: Base) => Derived; }> +>[r3arg, r3arg2] : Array<{ (x: (arg: T) => U, y: (arg2: { foo: number; }) => U): (r: T) => U; } | { (x: (arg: Base) => Derived, y: (arg2: Base) => Derived): (r: Base) => Derived; }> >r3arg : (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U >r3arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived @@ -535,8 +535,8 @@ module Errors { >r7arg3 : (x: { a: T; b: T; }) => number var r7e = [r7arg3, r7arg2]; ->r7e : { (x: { a: T; b: T; }): number; }[] ->[r7arg3, r7arg2] : { (x: { a: T; b: T; }): number; }[] +>r7e : { (x: { a: string; b: number; }): number; }[] +>[r7arg3, r7arg2] : { (x: { a: string; b: number; }): number; }[] >r7arg3 : (x: { a: T; b: T; }) => number >r7arg2 : (x: { a: string; b: number; }) => number diff --git a/tests/baselines/reference/subtypingWithCallSignatures4.types b/tests/baselines/reference/subtypingWithCallSignatures4.types index 07b3af3e540..f31a4fa928e 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures4.types +++ b/tests/baselines/reference/subtypingWithCallSignatures4.types @@ -318,8 +318,8 @@ var r3a = [r3arg, r3arg2]; >r3arg2 : (x: T) => void var r3b = [r3arg2, r3arg]; ->r3b : { (x: T): void; }[] ->[r3arg2, r3arg] : { (x: T): void; }[] +>r3b : { (x: T): T; }[] +>[r3arg2, r3arg] : { (x: T): T; }[] >r3arg2 : (x: T) => void >r3arg : (x: T) => T @@ -442,8 +442,8 @@ var r6a = [r6arg, r6arg2]; >r6arg2 : (x: (arg: T) => Derived) => T var r6b = [r6arg2, r6arg]; ->r6b : { (x: (arg: T) => Derived): T; }[] ->[r6arg2, r6arg] : { (x: (arg: T) => Derived): T; }[] +>r6b : { (x: (arg: T) => U): T; }[] +>[r6arg2, r6arg] : { (x: (arg: T) => U): T; }[] >r6arg2 : (x: (arg: T) => Derived) => T >r6arg : (x: (arg: T) => U) => T @@ -491,8 +491,8 @@ var r11a = [r11arg, r11arg2]; >r11arg2 : (x: { foo: T; }, y: { foo: T; bar: T; }) => Base var r11b = [r11arg2, r11arg]; ->r11b : { (x: { foo: T; }, y: { foo: T; bar: T; }): Base; }[] ->[r11arg2, r11arg] : { (x: { foo: T; }, y: { foo: T; bar: T; }): Base; }[] +>r11b : { (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] +>[r11arg2, r11arg] : { (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] >r11arg2 : (x: { foo: T; }, y: { foo: T; bar: T; }) => Base >r11arg : (x: { foo: T; }, y: { foo: U; bar: U; }) => Base @@ -534,8 +534,8 @@ var r15a = [r15arg, r15arg2]; >r15arg2 : (x: { a: T; b: T; }) => T[] var r15b = [r15arg2, r15arg]; ->r15b : { (x: { a: T; b: T; }): T[]; }[] ->[r15arg2, r15arg] : { (x: { a: T; b: T; }): T[]; }[] +>r15b : { (x: { a: U; b: V; }): U[]; }[] +>[r15arg2, r15arg] : { (x: { a: U; b: V; }): U[]; }[] >r15arg2 : (x: { a: T; b: T; }) => T[] >r15arg : (x: { a: U; b: V; }) => U[] diff --git a/tests/baselines/reference/subtypingWithConstructSignatures2.types b/tests/baselines/reference/subtypingWithConstructSignatures2.types index fdba6014751..3832697d04c 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures2.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures2.types @@ -360,8 +360,8 @@ var r2a = [r2arg1, r2arg2]; >r2arg2 : new (x: number) => string[] var r2b = [r2arg2, r2arg1]; ->r2b : { new (x: number): string[]; }[] ->[r2arg2, r2arg1] : { new (x: number): string[]; }[] +>r2b : { new (x: T): string[]; }[] +>[r2arg2, r2arg1] : { new (x: T): string[]; }[] >r2arg2 : new (x: number) => string[] >r2arg1 : new (x: T) => string[] @@ -389,8 +389,8 @@ var r3a = [r3arg1, r3arg2]; >r3arg2 : new (x: number) => void var r3b = [r3arg2, r3arg1]; ->r3b : { new (x: number): void; }[] ->[r3arg2, r3arg1] : { new (x: number): void; }[] +>r3b : { new (x: T): T; }[] +>[r3arg2, r3arg1] : { new (x: T): T; }[] >r3arg2 : new (x: number) => void >r3arg1 : new (x: T) => T @@ -630,14 +630,14 @@ var r9 = foo9(r9arg1); // any >r9arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U var r9a = [r9arg1, r9arg2]; ->r9a : {}[] ->[r9arg1, r9arg2] : {}[] +>r9a : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): new (r: T) => U; } | { new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> +>[r9arg1, r9arg2] : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): new (r: T) => U; } | { new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> >r9arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U >r9arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived var r9b = [r9arg2, r9arg1]; ->r9b : {}[] ->[r9arg2, r9arg1] : {}[] +>r9b : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): new (r: T) => U; } | { new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> +>[r9arg2, r9arg1] : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): new (r: T) => U; } | { new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> >r9arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived >r9arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U @@ -747,8 +747,8 @@ var r12a = [r12arg1, r12arg2]; >r12arg2 : new (x: Base[], y: Derived2[]) => Derived[] var r12b = [r12arg2, r12arg1]; ->r12b : { new (x: Base[], y: Derived2[]): Derived[]; }[] ->[r12arg2, r12arg1] : { new (x: Base[], y: Derived2[]): Derived[]; }[] +>r12b : { new (x: Base[], y: T): Derived[]; }[] +>[r12arg2, r12arg1] : { new (x: Base[], y: T): Derived[]; }[] >r12arg2 : new (x: Base[], y: Derived2[]) => Derived[] >r12arg1 : new (x: Base[], y: T) => Derived[] diff --git a/tests/baselines/reference/subtypingWithConstructSignatures3.types b/tests/baselines/reference/subtypingWithConstructSignatures3.types index cf4db8939fd..ff6b9adef0a 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures3.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures3.types @@ -318,14 +318,14 @@ module Errors { >r3arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U var r3a = [r3arg2, r3arg1]; ->r3a : {}[] ->[r3arg2, r3arg1] : {}[] +>r3a : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U): new (r: T) => U; } | { new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> +>[r3arg2, r3arg1] : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U): new (r: T) => U; } | { new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> >r3arg2 : new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived >r3arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U var r3b = [r3arg1, r3arg2]; ->r3b : {}[] ->[r3arg1, r3arg2] : {}[] +>r3b : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U): new (r: T) => U; } | { new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> +>[r3arg1, r3arg2] : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U): new (r: T) => U; } | { new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> >r3arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U >r3arg2 : new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived @@ -497,8 +497,8 @@ module Errors { >r7arg3 : new (x: { a: T; b: T; }) => number var r7e = [r7arg3, r7arg2]; ->r7e : { new (x: { a: T; b: T; }): number; }[] ->[r7arg3, r7arg2] : { new (x: { a: T; b: T; }): number; }[] +>r7e : { new (x: { a: string; b: number; }): number; }[] +>[r7arg3, r7arg2] : { new (x: { a: string; b: number; }): number; }[] >r7arg3 : new (x: { a: T; b: T; }) => number >r7arg2 : new (x: { a: string; b: number; }) => number diff --git a/tests/baselines/reference/subtypingWithConstructSignatures4.types b/tests/baselines/reference/subtypingWithConstructSignatures4.types index a9116880df3..473bbe9a205 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures4.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures4.types @@ -307,8 +307,8 @@ var r3a = [r3arg, r3arg2]; >r3arg2 : new (x: T) => void var r3b = [r3arg2, r3arg]; ->r3b : { new (x: T): void; }[] ->[r3arg2, r3arg] : { new (x: T): void; }[] +>r3b : { new (x: T): T; }[] +>[r3arg2, r3arg] : { new (x: T): T; }[] >r3arg2 : new (x: T) => void >r3arg : new (x: T) => T @@ -421,8 +421,8 @@ var r6a = [r6arg, r6arg2]; >r6arg2 : new (x: new (arg: T) => Derived) => T var r6b = [r6arg2, r6arg]; ->r6b : { new (x: new (arg: T) => Derived): T; }[] ->[r6arg2, r6arg] : { new (x: new (arg: T) => Derived): T; }[] +>r6b : { new (x: new (arg: T) => U): T; }[] +>[r6arg2, r6arg] : { new (x: new (arg: T) => U): T; }[] >r6arg2 : new (x: new (arg: T) => Derived) => T >r6arg : new (x: new (arg: T) => U) => T @@ -466,8 +466,8 @@ var r11a = [r11arg, r11arg2]; >r11arg2 : new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base var r11b = [r11arg2, r11arg]; ->r11b : { new (x: { foo: T; }, y: { foo: T; bar: T; }): Base; }[] ->[r11arg2, r11arg] : { new (x: { foo: T; }, y: { foo: T; bar: T; }): Base; }[] +>r11b : { new (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] +>[r11arg2, r11arg] : { new (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] >r11arg2 : new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base >r11arg : new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base @@ -505,8 +505,8 @@ var r15a = [r15arg, r15arg2]; >r15arg2 : new (x: { a: T; b: T; }) => T[] var r15b = [r15arg2, r15arg]; ->r15b : { new (x: { a: T; b: T; }): T[]; }[] ->[r15arg2, r15arg] : { new (x: { a: T; b: T; }): T[]; }[] +>r15b : { new (x: { a: U; b: V; }): U[]; }[] +>[r15arg2, r15arg] : { new (x: { a: U; b: V; }): U[]; }[] >r15arg2 : new (x: { a: T; b: T; }) => T[] >r15arg : new (x: { a: U; b: V; }) => U[] diff --git a/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt b/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt index 74d47f12565..b3eae74f568 100644 --- a/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt +++ b/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt @@ -4,10 +4,9 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW Property '1' is optional in type 'S2' but required in type 'T2'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts(26,11): error TS2429: Interface 'S3' incorrectly extends interface 'T3': Property ''1'' is optional in type 'S3' but required in type 'T3'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts(33,9): error TS2367: No best common type exists between '{ Foo: Base; }' and '{ Foo?: Derived; }'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts (4 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts (3 errors) ==== // Derived member is optional but base member is not, should be an error interface Base { foo: string; } @@ -49,6 +48,4 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW // object literal case var a: { Foo: Base; } var b: { Foo?: Derived; } - var r = true ? a : b; // error - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between '{ Foo: Base; }' and '{ Foo?: Derived; }'. \ No newline at end of file + var r = true ? a : b; // error \ No newline at end of file diff --git a/tests/baselines/reference/targetTypeTest3.errors.txt b/tests/baselines/reference/targetTypeTest3.errors.txt index e81cba71a47..d9dbec41150 100644 --- a/tests/baselines/reference/targetTypeTest3.errors.txt +++ b/tests/baselines/reference/targetTypeTest3.errors.txt @@ -1,5 +1,6 @@ -tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type '{}[]' is not assignable to type 'string[]': - Type '{}' is not assignable to type 'string'. +tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type 'Array' is not assignable to type 'string[]': + Type 'string | number' is not assignable to type 'string': + Type 'number' is not assignable to type 'string'. ==== tests/cases/compiler/targetTypeTest3.ts (1 errors) ==== @@ -8,8 +9,9 @@ tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type '{}[]' is not a var a : string[] = [1,2,"3"]; // should produce an error ~ -!!! error TS2322: Type '{}[]' is not assignable to type 'string[]': -!!! error TS2322: Type '{}' is not assignable to type 'string'. +!!! error TS2322: Type 'Array' is not assignable to type 'string[]': +!!! error TS2322: Type 'string | number' is not assignable to type 'string': +!!! error TS2322: Type 'number' is not assignable to type 'string'. function func1(stuff:any[]) { return stuff; } diff --git a/tests/baselines/reference/throwStatements.types b/tests/baselines/reference/throwStatements.types index efc2ff24124..7f106daced9 100644 --- a/tests/baselines/reference/throwStatements.types +++ b/tests/baselines/reference/throwStatements.types @@ -219,7 +219,7 @@ throw []; >[] : undefined[] throw ['a', ['b']]; ->['a', ['b']] : {}[] +>['a', ['b']] : Array >['b'] : string[] throw /[a-z]/; diff --git a/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt b/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt index e1681f5cc29..823bf93e535 100644 --- a/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt +++ b/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt @@ -1,7 +1,9 @@ -tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(5,19): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. - Type '{}' is not assignable to type 'number'. -tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. - Type '{}' is not assignable to type 'number'. +tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(5,19): error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. +tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. ==== tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts (2 errors) ==== @@ -11,12 +13,14 @@ tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS // these two should give the same error this.test([1, 2, "hi", 5, ]); ~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type '{}' is not assignable to type 'number'. +!!! error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number': +!!! error TS2345: Type 'string' is not assignable to type 'number'. this.test([1, 2, "hi", 5]); ~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type '{}' is not assignable to type 'number'. +!!! error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number': +!!! error TS2345: Type 'string' is not assignable to type 'number'. } } \ No newline at end of file diff --git a/tests/baselines/reference/tupleTypes.errors.txt b/tests/baselines/reference/tupleTypes.errors.txt index fcc65ff5c23..2ce9b044f48 100644 --- a/tests/baselines/reference/tupleTypes.errors.txt +++ b/tests/baselines/reference/tupleTypes.errors.txt @@ -1,16 +1,19 @@ tests/cases/compiler/tupleTypes.ts(1,9): error TS1122: A tuple type element list cannot be empty. -tests/cases/compiler/tupleTypes.ts(14,1): error TS2322: Type '{}[]' is not assignable to type '[number, string]': - Property '0' is missing in type '{}[]'. +tests/cases/compiler/tupleTypes.ts(12,5): error TS2403: Subsequent variable declarations must have the same type. Variable 't2' must be of type 'string | number', but here has type '{}'. +tests/cases/compiler/tupleTypes.ts(14,1): error TS2322: Type 'Array' is not assignable to type '[number, string]': + Property '0' is missing in type 'Array'. tests/cases/compiler/tupleTypes.ts(15,1): error TS2322: Type '[number]' is not assignable to type '[number, string]': Property '1' is missing in type '[number]'. tests/cases/compiler/tupleTypes.ts(17,1): error TS2322: Type '[string, number]' is not assignable to type '[number, string]': Types of property '0' are incompatible: Type 'string' is not assignable to type 'number'. -tests/cases/compiler/tupleTypes.ts(41,1): error TS2323: Type '{}[]' is not assignable to type '[number, string]'. +tests/cases/compiler/tupleTypes.ts(36,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'tt2' must be of type 'string | number', but here has type '{}'. +tests/cases/compiler/tupleTypes.ts(41,1): error TS2323: Type 'Array' is not assignable to type '[number, string]'. tests/cases/compiler/tupleTypes.ts(47,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]': Types of property 'pop' are incompatible: - Type '() => {}' is not assignable to type '() => number': - Type '{}' is not assignable to type 'number'. + Type '() => string | number' is not assignable to type '() => number': + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. tests/cases/compiler/tupleTypes.ts(49,1): error TS2322: Type '[number, {}]' is not assignable to type 'number[]': Types of property 'pop' are incompatible: Type '() => {}' is not assignable to type '() => number': @@ -23,7 +26,7 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n Type '{}' is not assignable to type 'string'. -==== tests/cases/compiler/tupleTypes.ts (9 errors) ==== +==== tests/cases/compiler/tupleTypes.ts (11 errors) ==== var v1: []; // Error ~~ !!! error TS1122: A tuple type element list cannot be empty. @@ -38,11 +41,13 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n var t1: string; var t2 = t[2]; // {} var t2: {}; + ~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 't2' must be of type 'string | number', but here has type '{}'. t = []; // Error ~ -!!! error TS2322: Type '{}[]' is not assignable to type '[number, string]': -!!! error TS2322: Property '0' is missing in type '{}[]'. +!!! error TS2322: Type 'Array' is not assignable to type '[number, string]': +!!! error TS2322: Property '0' is missing in type 'Array'. t = [1]; // Error ~ !!! error TS2322: Type '[number]' is not assignable to type '[number, string]': @@ -72,13 +77,15 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n var tt1: string; var tt2 = tt[2]; var tt2: {}; + ~~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'tt2' must be of type 'string | number', but here has type '{}'. tt = tuple2(1, undefined); tt = [1, undefined]; tt = [undefined, undefined]; tt = []; // Error ~~ -!!! error TS2323: Type '{}[]' is not assignable to type '[number, string]'. +!!! error TS2323: Type 'Array' is not assignable to type '[number, string]'. var a: number[]; var a1: [number, string]; @@ -88,8 +95,9 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n ~ !!! error TS2322: Type '[number, string]' is not assignable to type 'number[]': !!! error TS2322: Types of property 'pop' are incompatible: -!!! error TS2322: Type '() => {}' is not assignable to type '() => number': -!!! error TS2322: Type '{}' is not assignable to type 'number'. +!!! error TS2322: Type '() => string | number' is not assignable to type '() => number': +!!! error TS2322: Type 'string | number' is not assignable to type 'number': +!!! error TS2322: Type 'string' is not assignable to type 'number'. a = a2; a = a3; // Error ~ diff --git a/tests/baselines/reference/typeArgInference2.errors.txt b/tests/baselines/reference/typeArgInference2.errors.txt new file mode 100644 index 00000000000..3e148ca1da6 --- /dev/null +++ b/tests/baselines/reference/typeArgInference2.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/typeArgInference2.ts(12,10): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/compiler/typeArgInference2.ts (1 errors) ==== + interface Item { + name: string; + } + + declare function foo(x?: T, y?: T): T; + + var z1 = foo(null); // any + var z2 = foo(); // Item + var z3 = foo({ name: null }); // { name: any } + var z4 = foo({ name: "abc" }); // { name: string } + var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } + var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // Item + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgInference2.types b/tests/baselines/reference/typeArgInference2.types deleted file mode 100644 index 1b94a0638bd..00000000000 --- a/tests/baselines/reference/typeArgInference2.types +++ /dev/null @@ -1,61 +0,0 @@ -=== tests/cases/compiler/typeArgInference2.ts === -interface Item { ->Item : Item - - name: string; ->name : string -} - -declare function foo(x?: T, y?: T): T; ->foo : (x?: T, y?: T) => T ->T : T ->Item : Item ->x : T ->T : T ->y : T ->T : T ->T : T - -var z1 = foo(null); // any ->z1 : any ->foo(null) : any ->foo : (x?: T, y?: T) => T - -var z2 = foo(); // Item ->z2 : Item ->foo() : Item ->foo : (x?: T, y?: T) => T - -var z3 = foo({ name: null }); // { name: any } ->z3 : { name: any; } ->foo({ name: null }) : { name: any; } ->foo : (x?: T, y?: T) => T ->{ name: null } : { name: null; } ->name : null - -var z4 = foo({ name: "abc" }); // { name: string } ->z4 : { name: string; } ->foo({ name: "abc" }) : { name: string; } ->foo : (x?: T, y?: T) => T ->{ name: "abc" } : { name: string; } ->name : string - -var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } ->z5 : { name: string; a: number; } ->foo({ name: "abc", a: 5 }) : { name: string; a: number; } ->foo : (x?: T, y?: T) => T ->{ name: "abc", a: 5 } : { name: string; a: number; } ->name : string ->a : number - -var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // Item ->z6 : Item ->foo({ name: "abc", a: 5 }, { name: "def", b: 5 }) : Item ->foo : (x?: T, y?: T) => T ->{ name: "abc", a: 5 } : { name: string; a: number; } ->name : string ->a : number ->{ name: "def", b: 5 } : { name: string; b: number; } ->name : string ->b : number - diff --git a/tests/baselines/reference/typeArgInference2WithError.errors.txt b/tests/baselines/reference/typeArgInference2WithError.errors.txt index 26259abf37b..83fa81b5524 100644 --- a/tests/baselines/reference/typeArgInference2WithError.errors.txt +++ b/tests/baselines/reference/typeArgInference2WithError.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/typeArgInference2WithError.ts(7,14): error TS2345: Argument of type 'string' is not assignable to parameter of type 'Item'. +tests/cases/compiler/typeArgInference2WithError.ts(7,10): error TS2346: Supplied parameters do not match any signature of call target. ==== tests/cases/compiler/typeArgInference2WithError.ts (1 errors) ==== @@ -9,5 +9,5 @@ tests/cases/compiler/typeArgInference2WithError.ts(7,14): error TS2345: Argument declare function foo(x?: T, y?: T): T; var z7 = foo("abc", 5); // Error - ~~~~~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'Item'. \ No newline at end of file + ~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentInference.errors.txt b/tests/baselines/reference/typeArgumentInference.errors.txt new file mode 100644 index 00000000000..dbff8b83854 --- /dev/null +++ b/tests/baselines/reference/typeArgumentInference.errors.txt @@ -0,0 +1,109 @@ +tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts(68,11): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts(82,11): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts (2 errors) ==== + // Generic call with no parameters + function noParams() { } + noParams(); + noParams(); + noParams<{}>(); + + // Generic call with parameters but none use type parameter type + function noGenericParams(n: string) { } + noGenericParams(''); + noGenericParams(''); + noGenericParams<{}>(''); + + // Generic call with multiple type parameters and only one used in parameter type annotation + function someGenerics1(n: T, m: number) { } + someGenerics1(3, 4); + someGenerics1(3, 4); + + // Generic call with argument of function type whose parameter is of type parameter type + function someGenerics2a(n: (x: T) => void) { } + someGenerics2a((n: string) => n); + someGenerics2a((n: string) => n); + someGenerics2a((n) => n.substr(0)); + + function someGenerics2b(n: (x: T, y: U) => void) { } + someGenerics2b((n: string, x: number) => n); + someGenerics2b((n: string, t: number) => n); + someGenerics2b((n, t) => n.substr(t * t)); + + // Generic call with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter + function someGenerics3(producer: () => T) { } + someGenerics3(() => ''); + someGenerics3(() => undefined); + someGenerics3(() => 3); + + // 2 parameter generic call with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type + function someGenerics4(n: T, f: (x: U) => void) { } + someGenerics4(4, () => null); + someGenerics4('', () => 3); + someGenerics4(null, null); + + // 2 parameter generic call with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type + function someGenerics5(n: T, f: (x: U) => void) { } + someGenerics5(4, () => null); + someGenerics5('', () => 3); + someGenerics5(null, null); + + // Generic call with multiple arguments of function types that each have parameters of the same generic type + function someGenerics6(a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } + someGenerics6(n => n, n => n, n => n); + someGenerics6(n => n, n => n, n => n); + someGenerics6((n: number) => n, (n: number) => n, (n: number) => n); + + // Generic call with multiple arguments of function types that each have parameters of different generic type + function someGenerics7(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } + someGenerics7(n => n, n => n, n => n); + someGenerics7(n => n, n => n, n => n); + someGenerics7((n: number) => n, (n: string) => n, (n: number) => n); + + // Generic call with argument of generic function type + function someGenerics8(n: T): T { return n; } + var x = someGenerics8(someGenerics7); + x(null, null, null); + + // Generic call with multiple parameters of generic type passed arguments with no best common type + function someGenerics9(a: T, b: T, c: T): T { + return null; + } + var a9a = someGenerics9('', 0, []); + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var a9a: {}; + var a9b = someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null); + var a9b: { a?: number; b?: string; }; + + // Generic call with multiple parameters of generic type passed arguments with multiple best common types + interface A91 { + x: number; + y?: string; + } + interface A92 { + x: number; + z?: Date; + } + var a9e = someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var a9e: {}; + var a9f = someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }); + var a9f: A92; + + // Generic call with multiple parameters of generic type passed arguments with a single best common type + var a9d = someGenerics9({ x: 3 }, { x: 6 }, { x: 6 }); + var a9d: { x: number; }; + + // Generic call with multiple parameters of generic type where one argument is of type 'any' + var anyVar: any; + var a = someGenerics9(7, anyVar, 4); + var a: any; + + // Generic call with multiple parameters of generic type where one argument is [] and the other is not 'any' + var arr = someGenerics9([], null, undefined); + var arr: any[]; + + \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentInference.types b/tests/baselines/reference/typeArgumentInference.types deleted file mode 100644 index 40136bd10c3..00000000000 --- a/tests/baselines/reference/typeArgumentInference.types +++ /dev/null @@ -1,468 +0,0 @@ -=== tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts === -// Generic call with no parameters -function noParams() { } ->noParams : () => void ->T : T - -noParams(); ->noParams() : void ->noParams : () => void - -noParams(); ->noParams() : void ->noParams : () => void - -noParams<{}>(); ->noParams<{}>() : void ->noParams : () => void - -// Generic call with parameters but none use type parameter type -function noGenericParams(n: string) { } ->noGenericParams : (n: string) => void ->T : T ->n : string - -noGenericParams(''); ->noGenericParams('') : void ->noGenericParams : (n: string) => void - -noGenericParams(''); ->noGenericParams('') : void ->noGenericParams : (n: string) => void - -noGenericParams<{}>(''); ->noGenericParams<{}>('') : void ->noGenericParams : (n: string) => void - -// Generic call with multiple type parameters and only one used in parameter type annotation -function someGenerics1(n: T, m: number) { } ->someGenerics1 : (n: T, m: number) => void ->T : T ->U : U ->n : T ->T : T ->m : number - -someGenerics1(3, 4); ->someGenerics1(3, 4) : void ->someGenerics1 : (n: T, m: number) => void - -someGenerics1(3, 4); ->someGenerics1(3, 4) : void ->someGenerics1 : (n: T, m: number) => void - -// Generic call with argument of function type whose parameter is of type parameter type -function someGenerics2a(n: (x: T) => void) { } ->someGenerics2a : (n: (x: T) => void) => void ->T : T ->n : (x: T) => void ->x : T ->T : T - -someGenerics2a((n: string) => n); ->someGenerics2a((n: string) => n) : void ->someGenerics2a : (n: (x: T) => void) => void ->(n: string) => n : (n: string) => string ->n : string ->n : string - -someGenerics2a((n: string) => n); ->someGenerics2a((n: string) => n) : void ->someGenerics2a : (n: (x: T) => void) => void ->(n: string) => n : (n: string) => string ->n : string ->n : string - -someGenerics2a((n) => n.substr(0)); ->someGenerics2a((n) => n.substr(0)) : void ->someGenerics2a : (n: (x: T) => void) => void ->(n) => n.substr(0) : (n: string) => string ->n : string ->n.substr(0) : string ->n.substr : (from: number, length?: number) => string ->n : string ->substr : (from: number, length?: number) => string - -function someGenerics2b(n: (x: T, y: U) => void) { } ->someGenerics2b : (n: (x: T, y: U) => void) => void ->T : T ->U : U ->n : (x: T, y: U) => void ->x : T ->T : T ->y : U ->U : U - -someGenerics2b((n: string, x: number) => n); ->someGenerics2b((n: string, x: number) => n) : void ->someGenerics2b : (n: (x: T, y: U) => void) => void ->(n: string, x: number) => n : (n: string, x: number) => string ->n : string ->x : number ->n : string - -someGenerics2b((n: string, t: number) => n); ->someGenerics2b((n: string, t: number) => n) : void ->someGenerics2b : (n: (x: T, y: U) => void) => void ->(n: string, t: number) => n : (n: string, t: number) => string ->n : string ->t : number ->n : string - -someGenerics2b((n, t) => n.substr(t * t)); ->someGenerics2b((n, t) => n.substr(t * t)) : void ->someGenerics2b : (n: (x: T, y: U) => void) => void ->(n, t) => n.substr(t * t) : (n: string, t: number) => string ->n : string ->t : number ->n.substr(t * t) : string ->n.substr : (from: number, length?: number) => string ->n : string ->substr : (from: number, length?: number) => string ->t * t : number ->t : number ->t : number - -// Generic call with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter -function someGenerics3(producer: () => T) { } ->someGenerics3 : (producer: () => T) => void ->T : T ->producer : () => T ->T : T - -someGenerics3(() => ''); ->someGenerics3(() => '') : void ->someGenerics3 : (producer: () => T) => void ->() => '' : () => string - -someGenerics3(() => undefined); ->someGenerics3(() => undefined) : void ->someGenerics3 : (producer: () => T) => void ->Date : Date ->() => undefined : () => any ->undefined : undefined - -someGenerics3(() => 3); ->someGenerics3(() => 3) : void ->someGenerics3 : (producer: () => T) => void ->() => 3 : () => number - -// 2 parameter generic call with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type -function someGenerics4(n: T, f: (x: U) => void) { } ->someGenerics4 : (n: T, f: (x: U) => void) => void ->T : T ->U : U ->n : T ->T : T ->f : (x: U) => void ->x : U ->U : U - -someGenerics4(4, () => null); ->someGenerics4(4, () => null) : void ->someGenerics4 : (n: T, f: (x: U) => void) => void ->() => null : () => any - -someGenerics4('', () => 3); ->someGenerics4('', () => 3) : void ->someGenerics4 : (n: T, f: (x: U) => void) => void ->() => 3 : () => number - -someGenerics4(null, null); ->someGenerics4(null, null) : void ->someGenerics4 : (n: T, f: (x: U) => void) => void - -// 2 parameter generic call with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type -function someGenerics5(n: T, f: (x: U) => void) { } ->someGenerics5 : (n: T, f: (x: U) => void) => void ->U : U ->T : T ->n : T ->T : T ->f : (x: U) => void ->x : U ->U : U - -someGenerics5(4, () => null); ->someGenerics5(4, () => null) : void ->someGenerics5 : (n: T, f: (x: U) => void) => void ->() => null : () => any - -someGenerics5('', () => 3); ->someGenerics5('', () => 3) : void ->someGenerics5 : (n: T, f: (x: U) => void) => void ->() => 3 : () => number - -someGenerics5(null, null); ->someGenerics5(null, null) : void ->someGenerics5 : (n: T, f: (x: U) => void) => void - -// Generic call with multiple arguments of function types that each have parameters of the same generic type -function someGenerics6(a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } ->someGenerics6 : (a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) => void ->A : A ->a : (a: A) => A ->a : A ->A : A ->A : A ->b : (b: A) => A ->b : A ->A : A ->A : A ->c : (c: A) => A ->c : A ->A : A ->A : A - -someGenerics6(n => n, n => n, n => n); ->someGenerics6(n => n, n => n, n => n) : void ->someGenerics6 : (a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) => void ->n => n : (n: {}) => {} ->n : {} ->n : {} ->n => n : (n: {}) => {} ->n : {} ->n : {} ->n => n : (n: {}) => {} ->n : {} ->n : {} - -someGenerics6(n => n, n => n, n => n); ->someGenerics6(n => n, n => n, n => n) : void ->someGenerics6 : (a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) => void ->n => n : (n: number) => number ->n : number ->n : number ->n => n : (n: number) => number ->n : number ->n : number ->n => n : (n: number) => number ->n : number ->n : number - -someGenerics6((n: number) => n, (n: number) => n, (n: number) => n); ->someGenerics6((n: number) => n, (n: number) => n, (n: number) => n) : void ->someGenerics6 : (a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) => void ->(n: number) => n : (n: number) => number ->n : number ->n : number ->(n: number) => n : (n: number) => number ->n : number ->n : number ->(n: number) => n : (n: number) => number ->n : number ->n : number - -// Generic call with multiple arguments of function types that each have parameters of different generic type -function someGenerics7(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } ->someGenerics7 : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->A : A ->B : B ->C : C ->a : (a: A) => A ->a : A ->A : A ->A : A ->b : (b: B) => B ->b : B ->B : B ->B : B ->c : (c: C) => C ->c : C ->C : C ->C : C - -someGenerics7(n => n, n => n, n => n); ->someGenerics7(n => n, n => n, n => n) : void ->someGenerics7 : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->n => n : (n: {}) => {} ->n : {} ->n : {} ->n => n : (n: {}) => {} ->n : {} ->n : {} ->n => n : (n: {}) => {} ->n : {} ->n : {} - -someGenerics7(n => n, n => n, n => n); ->someGenerics7(n => n, n => n, n => n) : void ->someGenerics7 : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->n => n : (n: number) => number ->n : number ->n : number ->n => n : (n: string) => string ->n : string ->n : string ->n => n : (n: number) => number ->n : number ->n : number - -someGenerics7((n: number) => n, (n: string) => n, (n: number) => n); ->someGenerics7((n: number) => n, (n: string) => n, (n: number) => n) : void ->someGenerics7 : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->(n: number) => n : (n: number) => number ->n : number ->n : number ->(n: string) => n : (n: string) => string ->n : string ->n : string ->(n: number) => n : (n: number) => number ->n : number ->n : number - -// Generic call with argument of generic function type -function someGenerics8(n: T): T { return n; } ->someGenerics8 : (n: T) => T ->T : T ->n : T ->T : T ->T : T ->n : T - -var x = someGenerics8(someGenerics7); ->x : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->someGenerics8(someGenerics7) : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->someGenerics8 : (n: T) => T ->someGenerics7 : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void - -x(null, null, null); ->x(null, null, null) : void ->x : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void - -// Generic call with multiple parameters of generic type passed arguments with no best common type -function someGenerics9(a: T, b: T, c: T): T { ->someGenerics9 : (a: T, b: T, c: T) => T ->T : T ->a : T ->T : T ->b : T ->T : T ->c : T ->T : T ->T : T - - return null; -} -var a9a = someGenerics9('', 0, []); ->a9a : {} ->someGenerics9('', 0, []) : {} ->someGenerics9 : (a: T, b: T, c: T) => T ->[] : undefined[] - -var a9a: {}; ->a9a : {} - -var a9b = someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null); ->a9b : { a?: number; b?: string; } ->someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null) : { a?: number; b?: string; } ->someGenerics9 : (a: T, b: T, c: T) => T ->a : number ->b : string ->{ a: 0 } : { a: number; } ->a : number ->{ b: '' } : { b: string; } ->b : string - -var a9b: { a?: number; b?: string; }; ->a9b : { a?: number; b?: string; } ->a : number ->b : string - -// Generic call with multiple parameters of generic type passed arguments with multiple best common types -interface A91 { ->A91 : A91 - - x: number; ->x : number - - y?: string; ->y : string -} -interface A92 { ->A92 : A92 - - x: number; ->x : number - - z?: Date; ->z : Date ->Date : Date -} -var a9e = someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }); ->a9e : {} ->someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }) : {} ->someGenerics9 : (a: T, b: T, c: T) => T ->undefined : undefined ->{ x: 6, z: new Date() } : { x: number; z: Date; } ->x : number ->z : Date ->new Date() : Date ->Date : { (): string; new (): Date; new (value: number): Date; new (value: string): Date; new (year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date; prototype: Date; parse(s: string): number; UTC(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number; now(): number; } ->{ x: 6, y: '' } : { x: number; y: string; } ->x : number ->y : string - -var a9e: {}; ->a9e : {} - -var a9f = someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }); ->a9f : A92 ->someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }) : A92 ->someGenerics9 : (a: T, b: T, c: T) => T ->A92 : A92 ->undefined : undefined ->{ x: 6, z: new Date() } : { x: number; z: Date; } ->x : number ->z : Date ->new Date() : Date ->Date : { (): string; new (): Date; new (value: number): Date; new (value: string): Date; new (year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date; prototype: Date; parse(s: string): number; UTC(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number; now(): number; } ->{ x: 6, y: '' } : { x: number; y: string; } ->x : number ->y : string - -var a9f: A92; ->a9f : A92 ->A92 : A92 - -// Generic call with multiple parameters of generic type passed arguments with a single best common type -var a9d = someGenerics9({ x: 3 }, { x: 6 }, { x: 6 }); ->a9d : { x: number; } ->someGenerics9({ x: 3 }, { x: 6 }, { x: 6 }) : { x: number; } ->someGenerics9 : (a: T, b: T, c: T) => T ->{ x: 3 } : { x: number; } ->x : number ->{ x: 6 } : { x: number; } ->x : number ->{ x: 6 } : { x: number; } ->x : number - -var a9d: { x: number; }; ->a9d : { x: number; } ->x : number - -// Generic call with multiple parameters of generic type where one argument is of type 'any' -var anyVar: any; ->anyVar : any - -var a = someGenerics9(7, anyVar, 4); ->a : any ->someGenerics9(7, anyVar, 4) : any ->someGenerics9 : (a: T, b: T, c: T) => T ->anyVar : any - -var a: any; ->a : any - -// Generic call with multiple parameters of generic type where one argument is [] and the other is not 'any' -var arr = someGenerics9([], null, undefined); ->arr : any[] ->someGenerics9([], null, undefined) : any[] ->someGenerics9 : (a: T, b: T, c: T) => T ->[] : any[] ->undefined : undefined - -var arr: any[]; ->arr : any[] - - diff --git a/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt b/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt index a9de02d4226..4f11cb6135e 100644 --- a/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt @@ -3,12 +3,14 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstruct tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(61,39): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(71,39): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(81,45): error TS2345: Argument of type '(n: string) => string' is not assignable to parameter of type '(b: number) => number'. +tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(106,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(118,9): error TS2304: Cannot find name 'Window'. +tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(120,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(120,51): error TS2304: Cannot find name 'window'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(122,56): error TS2304: Cannot find name 'window'. -==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts (8 errors) ==== +==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts (10 errors) ==== // Generic call with no parameters interface NoParams { new (); @@ -125,6 +127,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstruct } var someGenerics9: someGenerics9; var a9a = new someGenerics9('', 0, []); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var a9a: {}; var a9b = new someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null); var a9b: { a?: number; b?: string; }; @@ -141,6 +145,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstruct !!! error TS2304: Cannot find name 'Window'. } var a9e = new someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' }); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. ~~~~~~ !!! error TS2304: Cannot find name 'window'. var a9e: {}; diff --git a/tests/baselines/reference/typeArgumentInferenceTransitiveConstraints.errors.txt b/tests/baselines/reference/typeArgumentInferenceTransitiveConstraints.errors.txt index e6e59308dd4..08cb5348c27 100644 --- a/tests/baselines/reference/typeArgumentInferenceTransitiveConstraints.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceTransitiveConstraints.errors.txt @@ -1,9 +1,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiveConstraints.ts(2,29): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiveConstraints.ts(2,42): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiveConstraints.ts(7,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'd' must be of type '{}[]', but here has type 'Date[]'. -==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiveConstraints.ts (3 errors) ==== +==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiveConstraints.ts (2 errors) ==== function fn(a: A, b: B, c: C) { ~~~~~~~~~~~ @@ -15,6 +14,4 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiv var d = fn(new Date(), new Date(), new Date()); var d: Date[]; // Should be OK (d should be Date[]) - ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'd' must be of type '{}[]', but here has type 'Date[]'. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.errors.txt b/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.errors.txt new file mode 100644 index 00000000000..c0ee4329c8d --- /dev/null +++ b/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/typeArgumentInferenceWithConstraintAsCommonRoot.ts(7,1): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/compiler/typeArgumentInferenceWithConstraintAsCommonRoot.ts (1 errors) ==== + interface Animal { x } + interface Giraffe extends Animal { y } + interface Elephant extends Animal { z } + function f(x: T, y: T): T { return undefined; } + var g: Giraffe; + var e: Elephant; + f(g, e); // valid because both Giraffe and Elephant satisfy the constraint. T is Animal + ~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.types b/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.types deleted file mode 100644 index 35328f72803..00000000000 --- a/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.types +++ /dev/null @@ -1,40 +0,0 @@ -=== tests/cases/compiler/typeArgumentInferenceWithConstraintAsCommonRoot.ts === -interface Animal { x } ->Animal : Animal ->x : any - -interface Giraffe extends Animal { y } ->Giraffe : Giraffe ->Animal : Animal ->y : any - -interface Elephant extends Animal { z } ->Elephant : Elephant ->Animal : Animal ->z : any - -function f(x: T, y: T): T { return undefined; } ->f : (x: T, y: T) => T ->T : T ->Animal : Animal ->x : T ->T : T ->y : T ->T : T ->T : T ->undefined : undefined - -var g: Giraffe; ->g : Giraffe ->Giraffe : Giraffe - -var e: Elephant; ->e : Elephant ->Elephant : Elephant - -f(g, e); // valid because both Giraffe and Elephant satisfy the constraint. T is Animal ->f(g, e) : Animal ->f : (x: T, y: T) => T ->g : Giraffe ->e : Elephant - diff --git a/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt b/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt index 8cf2a2d3503..c0dbf74f66e 100644 --- a/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt @@ -8,12 +8,14 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(49,15): error TS2344: Type 'string' does not satisfy the constraint 'number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(55,41): error TS2345: Argument of type '(n: string) => string' is not assignable to parameter of type '(b: number) => number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(66,31): error TS2345: Argument of type '(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void' is not assignable to parameter of type 'string'. +tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(73,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(85,9): error TS2304: Cannot find name 'Window'. +tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(87,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(87,47): error TS2304: Cannot find name 'window'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(89,52): error TS2304: Cannot find name 'window'. -==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts (13 errors) ==== +==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts (15 errors) ==== // Generic call with no parameters function noParams() { } noParams(); @@ -107,6 +109,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst return null; } var a9a = someGenerics9('', 0, []); + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var a9a: {}; var a9b = someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null); var a9b: { a?: number; b?: string; }; @@ -123,6 +127,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst !!! error TS2304: Cannot find name 'Window'. } var a9e = someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' }); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. ~~~~~~ !!! error TS2304: Cannot find name 'window'. var a9e: {}; diff --git a/tests/baselines/reference/typeInferenceConflictingCandidates.errors.txt b/tests/baselines/reference/typeInferenceConflictingCandidates.errors.txt new file mode 100644 index 00000000000..5f9f980e735 --- /dev/null +++ b/tests/baselines/reference/typeInferenceConflictingCandidates.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/typeInferenceConflictingCandidates.ts(3,1): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/compiler/typeInferenceConflictingCandidates.ts (1 errors) ==== + declare function g(a: T, b: T, c: (t: T) => T): T; + + g("", 3, a => a); + ~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/typeInferenceConflictingCandidates.types b/tests/baselines/reference/typeInferenceConflictingCandidates.types deleted file mode 100644 index 7a77daf4092..00000000000 --- a/tests/baselines/reference/typeInferenceConflictingCandidates.types +++ /dev/null @@ -1,21 +0,0 @@ -=== tests/cases/compiler/typeInferenceConflictingCandidates.ts === -declare function g(a: T, b: T, c: (t: T) => T): T; ->g : (a: T, b: T, c: (t: T) => T) => T ->T : T ->a : T ->T : T ->b : T ->T : T ->c : (t: T) => T ->t : T ->T : T ->T : T ->T : T - -g("", 3, a => a); ->g("", 3, a => a) : {} ->g : (a: T, b: T, c: (t: T) => T) => T ->a => a : (a: {}) => {} ->a : {} ->a : {} - diff --git a/tests/baselines/reference/typeParameterAsElementType.types b/tests/baselines/reference/typeParameterAsElementType.types index 0dbbbf5ac7a..828c7034a58 100644 --- a/tests/baselines/reference/typeParameterAsElementType.types +++ b/tests/baselines/reference/typeParameterAsElementType.types @@ -8,7 +8,7 @@ function fee() { >T : T var arr = [t, ""]; ->arr : {}[] ->[t, ""] : {}[] +>arr : Array +>[t, ""] : Array >t : T } diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index 115bc09195d..a23eff1f8ea 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -176,7 +176,7 @@ _.all([true, 1, null, 'yes'], _.identity); >_.all : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } >_ : Underscore.Static >all : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } ->[true, 1, null, 'yes'] : {}[] +>[true, 1, null, 'yes'] : Array >_.identity : (value: T) => T >_ : Underscore.Static >identity : (value: T) => T @@ -186,7 +186,7 @@ _.any([null, 0, 'yes', false]); >_.any : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } >_ : Underscore.Static >any : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } ->[null, 0, 'yes', false] : {}[] +>[null, 0, 'yes', false] : Array _.contains([1, 2, 3], 3); >_.contains([1, 2, 3], 3) : boolean @@ -364,11 +364,11 @@ _.rest([5, 4, 3, 2, 1]); >[5, 4, 3, 2, 1] : number[] _.compact([0, 1, false, 2, '', 3]); ->_.compact([0, 1, false, 2, '', 3]) : {}[] +>_.compact([0, 1, false, 2, '', 3]) : Array >_.compact : (list: T[]) => T[] >_ : Underscore.Static >compact : (list: T[]) => T[] ->[0, 1, false, 2, '', 3] : {}[] +>[0, 1, false, 2, '', 3] : Array _.flatten([1, 2, 3, 4]); >_.flatten([1, 2, 3, 4]) : {}[] @@ -393,7 +393,7 @@ _.flatten([1, [2], [3, [[4]]]]); >flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } >[1, [2], [3, [[4]]]] : any[] >[2] : number[] ->[3, [[4]]] : {}[] +>[3, [[4]]] : Array >[[4]] : number[][] >[4] : number[] @@ -404,7 +404,7 @@ _.flatten([1, [2], [3, [[4]]]], true); >flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } >[1, [2], [3, [[4]]]] : any[] >[2] : number[] ->[3, [[4]]] : {}[] +>[3, [[4]]] : Array >[[4]] : number[][] >[4] : number[] From 3a17b02393ae14cc6627d08bb649cdcfaec231a5 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 8 Oct 2014 14:25:13 -0700 Subject: [PATCH 08/23] Improved type argument inference with union types --- src/compiler/checker.ts | 35 ++++++++++++++++++++++++++++++++++- src/compiler/types.ts | 1 + 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 47ee21c3cbf..1d710c9315c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3720,6 +3720,7 @@ module ts { for (var i = 0; i < typeParameters.length; i++) inferences.push([]); return { typeParameters: typeParameters, + inferenceCount: 0, inferences: inferences, inferredTypes: new Array(typeParameters.length), }; @@ -3757,6 +3758,7 @@ module ts { var typeParameters = context.typeParameters; for (var i = 0; i < typeParameters.length; i++) { if (target === typeParameters[i]) { + context.inferenceCount++; var inferences = context.inferences[i]; if (!contains(inferences, source)) inferences.push(source); break; @@ -3771,6 +3773,35 @@ module ts { inferFromTypes(sourceTypes[i], targetTypes[i]); } } + else if (target.flags & TypeFlags.Union) { + // Target is a union type + var targetTypes = (target).types; + var startCount = context.inferenceCount; + var typeParameterCount = 0; + var typeParameter: TypeParameter; + // First infer to each type in union that isn't a type parameter + for (var i = 0; i < targetTypes.length; i++) { + var t = targetTypes[i]; + if (t.flags & TypeFlags.TypeParameter && contains(context.typeParameters, t)) { + typeParameter = t; + typeParameterCount++; + } + else { + inferFromTypes(source, t); + } + } + // If no inferences were produced above and union contains a single naked type parameter, infer to that type parameter + if (context.inferenceCount === startCount && typeParameterCount === 1) { + inferFromTypes(source, typeParameter); + } + } + else if (source.flags & TypeFlags.Union) { + // Source is a union type, infer from each consituent type + var sourceTypes = (source).types; + for (var i = 0; i < sourceTypes.length; i++) { + inferFromTypes(sourceTypes[i], target); + } + } else if (source.flags & TypeFlags.ObjectType && (target.flags & (TypeFlags.Reference | TypeFlags.Tuple) || (target.flags & TypeFlags.Anonymous) && target.symbol && target.symbol.flags & (SymbolFlags.Method | SymbolFlags.TypeLiteral))) { // If source is an object type, and target is a type reference, a tuple type, the type of a method, or a type literal, infer from members @@ -5169,7 +5200,9 @@ module ts { // Try to return the best common type if we have any return expressions. if (types.length > 0) { - var commonType = getCommonSupertype(types); + // When return statements are contextually typed we allow the return type to be a union type. Otherwise we require the + // return expressions to have a best common supertype. + var commonType = getContextualSignature(func) ? getUnionType(types) : getCommonSupertype(types); if (!commonType) { error(func, Diagnostics.No_best_common_type_exists_among_return_expressions); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f6691353c22..29f77e77f65 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -970,6 +970,7 @@ module ts { export interface InferenceContext { typeParameters: TypeParameter[]; + inferenceCount: number; inferences: Type[][]; inferredTypes: Type[]; } From 5c661baddc82803f8ee8158f5259b5032fe1c35b Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 8 Oct 2014 15:37:01 -0700 Subject: [PATCH 09/23] Accepting new baselines after merge with master The tuple type tests from master need to be updated to reflect the new best common type behavior from union types. This commit simply accepts the baselines as they are. --- ...nmentCompatBetweenTupleAndArray.errors.txt | 72 +++--- .../assignmentCompatBetweenTupleAndArray.js | 38 +-- .../reference/bestCommonTypeOfTuple.js | 68 +++--- .../reference/bestCommonTypeOfTuple.types | 192 +++++++-------- .../reference/bestCommonTypeOfTuple2.js | 112 ++++----- .../reference/bestCommonTypeOfTuple2.types | 180 +++++++------- ...wiseCompoundAssignmentOperators.errors.txt | 116 ++++----- .../bitwiseCompoundAssignmentOperators.js | 64 ++--- .../reference/castingTuple.errors.txt | 132 +++++----- tests/baselines/reference/castingTuple.js | 138 +++++------ .../contextualTypeWithTuple.errors.txt | 96 +++++--- .../reference/contextualTypeWithTuple.js | 32 +-- .../genericCallWithTupleType.errors.txt | 110 +++++---- .../reference/genericCallWithTupleType.js | 44 ++-- .../getEmitOutputExternalModule.baseline | 12 +- .../getEmitOutputExternalModule2.baseline | 24 +- tests/baselines/reference/indexerWithTuple.js | 36 +-- .../reference/indexerWithTuple.types | 128 +++++----- .../reference/selfReferencingFile.errors.txt | 20 +- .../reference/selfReferencingFile2.errors.txt | 20 +- .../reference/selfReferencingFile3.errors.txt | 20 +- .../reference/typeInferenceWithTupleType.js | 48 ++-- .../typeInferenceWithTupleType.types | 228 +++++++++--------- 23 files changed, 990 insertions(+), 940 deletions(-) diff --git a/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt b/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt index 7c0a3a5c8b9..2395f2bf364 100644 --- a/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt +++ b/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt @@ -1,36 +1,38 @@ -tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(17,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]': - Types of property 'pop' are incompatible: - Type '() => {}' is not assignable to type '() => number': - Type '{}' is not assignable to type 'number'. -tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(18,1): error TS2322: Type '{}[]' is not assignable to type '[{}]': - Property '0' is missing in type '{}[]'. - - -==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts (2 errors) ==== - var numStrTuple: [number, string]; - var numNumTuple: [number, number]; - var numEmptyObjTuple: [number, {}]; - var emptyObjTuple: [{}]; - - var numArray: number[]; - var emptyObjArray: {}[]; - - // no error - numArray = numNumTuple; - emptyObjArray = emptyObjTuple; - emptyObjArray = numStrTuple; - emptyObjArray = numNumTuple; - emptyObjArray = numEmptyObjTuple; - - // error - numArray = numStrTuple; - ~~~~~~~~ -!!! error TS2322: Type '[number, string]' is not assignable to type 'number[]': -!!! error TS2322: Types of property 'pop' are incompatible: -!!! error TS2322: Type '() => {}' is not assignable to type '() => number': -!!! error TS2322: Type '{}' is not assignable to type 'number'. - emptyObjTuple = emptyObjArray; - ~~~~~~~~~~~~~ -!!! error TS2322: Type '{}[]' is not assignable to type '[{}]': -!!! error TS2322: Property '0' is missing in type '{}[]'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(17,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]': + Types of property 'pop' are incompatible: + Type '() => string | number' is not assignable to type '() => number': + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(18,1): error TS2322: Type '{}[]' is not assignable to type '[{}]': + Property '0' is missing in type '{}[]'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts (2 errors) ==== + var numStrTuple: [number, string]; + var numNumTuple: [number, number]; + var numEmptyObjTuple: [number, {}]; + var emptyObjTuple: [{}]; + + var numArray: number[]; + var emptyObjArray: {}[]; + + // no error + numArray = numNumTuple; + emptyObjArray = emptyObjTuple; + emptyObjArray = numStrTuple; + emptyObjArray = numNumTuple; + emptyObjArray = numEmptyObjTuple; + + // error + numArray = numStrTuple; + ~~~~~~~~ +!!! error TS2322: Type '[number, string]' is not assignable to type 'number[]': +!!! error TS2322: Types of property 'pop' are incompatible: +!!! error TS2322: Type '() => string | number' is not assignable to type '() => number': +!!! error TS2322: Type 'string | number' is not assignable to type 'number': +!!! error TS2322: Type 'string' is not assignable to type 'number'. + emptyObjTuple = emptyObjArray; + ~~~~~~~~~~~~~ +!!! error TS2322: Type '{}[]' is not assignable to type '[{}]': +!!! error TS2322: Property '0' is missing in type '{}[]'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.js b/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.js index cbe6b1ff04e..fd3ac1d46f1 100644 --- a/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.js +++ b/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.js @@ -1,4 +1,4 @@ -//// [assignmentCompatBetweenTupleAndArray.ts] +//// [assignmentCompatBetweenTupleAndArray.ts] var numStrTuple: [number, string]; var numNumTuple: [number, number]; var numEmptyObjTuple: [number, {}]; @@ -17,21 +17,21 @@ emptyObjArray = numEmptyObjTuple; // error numArray = numStrTuple; emptyObjTuple = emptyObjArray; - - -//// [assignmentCompatBetweenTupleAndArray.js] -var numStrTuple; -var numNumTuple; -var numEmptyObjTuple; -var emptyObjTuple; -var numArray; -var emptyObjArray; -// no error -numArray = numNumTuple; -emptyObjArray = emptyObjTuple; -emptyObjArray = numStrTuple; -emptyObjArray = numNumTuple; -emptyObjArray = numEmptyObjTuple; -// error -numArray = numStrTuple; -emptyObjTuple = emptyObjArray; + + +//// [assignmentCompatBetweenTupleAndArray.js] +var numStrTuple; +var numNumTuple; +var numEmptyObjTuple; +var emptyObjTuple; +var numArray; +var emptyObjArray; +// no error +numArray = numNumTuple; +emptyObjArray = emptyObjTuple; +emptyObjArray = numStrTuple; +emptyObjArray = numNumTuple; +emptyObjArray = numEmptyObjTuple; +// error +numArray = numStrTuple; +emptyObjTuple = emptyObjArray; diff --git a/tests/baselines/reference/bestCommonTypeOfTuple.js b/tests/baselines/reference/bestCommonTypeOfTuple.js index a668b9978b0..752523317b5 100644 --- a/tests/baselines/reference/bestCommonTypeOfTuple.js +++ b/tests/baselines/reference/bestCommonTypeOfTuple.js @@ -1,4 +1,4 @@ -//// [bestCommonTypeOfTuple.ts] +//// [bestCommonTypeOfTuple.ts] function f1(x: number): string { return "foo"; } function f2(x: number): number { return 10; } @@ -23,36 +23,36 @@ t4 = [E1.one, E2.two, 20]; var e1 = t1[2]; // {} var e2 = t2[2]; // {} var e3 = t3[2]; // any -var e4 = t4[3]; // number - -//// [bestCommonTypeOfTuple.js] -function f1(x) { - return "foo"; -} -function f2(x) { - return 10; -} -function f3(x) { - return true; -} -var E1; -(function (E1) { - E1[E1["one"] = 0] = "one"; -})(E1 || (E1 = {})); -var E2; -(function (E2) { - E2[E2["two"] = 0] = "two"; -})(E2 || (E2 = {})); -var t1; -var t2; -var t3; -var t4; -// no error -t1 = [f1, f2]; -t2 = [0 /* one */, 0 /* two */]; -t3 = [5, undefined]; -t4 = [0 /* one */, 0 /* two */, 20]; -var e1 = t1[2]; // {} -var e2 = t2[2]; // {} -var e3 = t3[2]; // any -var e4 = t4[3]; // number +var e4 = t4[3]; // number + +//// [bestCommonTypeOfTuple.js] +function f1(x) { + return "foo"; +} +function f2(x) { + return 10; +} +function f3(x) { + return true; +} +var E1; +(function (E1) { + E1[E1["one"] = 0] = "one"; +})(E1 || (E1 = {})); +var E2; +(function (E2) { + E2[E2["two"] = 0] = "two"; +})(E2 || (E2 = {})); +var t1; +var t2; +var t3; +var t4; +// no error +t1 = [f1, f2]; +t2 = [0 /* one */, 0 /* two */]; +t3 = [5, undefined]; +t4 = [0 /* one */, 0 /* two */, 20]; +var e1 = t1[2]; // {} +var e2 = t2[2]; // {} +var e3 = t3[2]; // any +var e4 = t4[3]; // number diff --git a/tests/baselines/reference/bestCommonTypeOfTuple.types b/tests/baselines/reference/bestCommonTypeOfTuple.types index 936607769e7..87624c267aa 100644 --- a/tests/baselines/reference/bestCommonTypeOfTuple.types +++ b/tests/baselines/reference/bestCommonTypeOfTuple.types @@ -1,96 +1,96 @@ -=== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple.ts === -function f1(x: number): string { return "foo"; } ->f1 : (x: number) => string ->x : number - -function f2(x: number): number { return 10; } ->f2 : (x: number) => number ->x : number - -function f3(x: number): boolean { return true; } ->f3 : (x: number) => boolean ->x : number - -enum E1 { one } ->E1 : E1 ->one : E1 - -enum E2 { two } ->E2 : E2 ->two : E2 - - -var t1: [(x: number) => string, (x: number) => number]; ->t1 : [(x: number) => string, (x: number) => number] ->x : number ->x : number - -var t2: [E1, E2]; ->t2 : [E1, E2] ->E1 : E1 ->E2 : E2 - -var t3: [number, any]; ->t3 : [number, any] - -var t4: [E1, E2, number]; ->t4 : [E1, E2, number] ->E1 : E1 ->E2 : E2 - -// no error -t1 = [f1, f2]; ->t1 = [f1, f2] : [(x: number) => string, (x: number) => number] ->t1 : [(x: number) => string, (x: number) => number] ->[f1, f2] : [(x: number) => string, (x: number) => number] ->f1 : (x: number) => string ->f2 : (x: number) => number - -t2 = [E1.one, E2.two]; ->t2 = [E1.one, E2.two] : [E1, E2] ->t2 : [E1, E2] ->[E1.one, E2.two] : [E1, E2] ->E1.one : E1 ->E1 : typeof E1 ->one : E1 ->E2.two : E2 ->E2 : typeof E2 ->two : E2 - -t3 = [5, undefined]; ->t3 = [5, undefined] : [number, undefined] ->t3 : [number, any] ->[5, undefined] : [number, undefined] ->undefined : undefined - -t4 = [E1.one, E2.two, 20]; ->t4 = [E1.one, E2.two, 20] : [E1, E2, number] ->t4 : [E1, E2, number] ->[E1.one, E2.two, 20] : [E1, E2, number] ->E1.one : E1 ->E1 : typeof E1 ->one : E1 ->E2.two : E2 ->E2 : typeof E2 ->two : E2 - -var e1 = t1[2]; // {} ->e1 : {} ->t1[2] : {} ->t1 : [(x: number) => string, (x: number) => number] - -var e2 = t2[2]; // {} ->e2 : {} ->t2[2] : {} ->t2 : [E1, E2] - -var e3 = t3[2]; // any ->e3 : any ->t3[2] : any ->t3 : [number, any] - -var e4 = t4[3]; // number ->e4 : number ->t4[3] : number ->t4 : [E1, E2, number] - +=== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple.ts === +function f1(x: number): string { return "foo"; } +>f1 : (x: number) => string +>x : number + +function f2(x: number): number { return 10; } +>f2 : (x: number) => number +>x : number + +function f3(x: number): boolean { return true; } +>f3 : (x: number) => boolean +>x : number + +enum E1 { one } +>E1 : E1 +>one : E1 + +enum E2 { two } +>E2 : E2 +>two : E2 + + +var t1: [(x: number) => string, (x: number) => number]; +>t1 : [(x: number) => string, (x: number) => number] +>x : number +>x : number + +var t2: [E1, E2]; +>t2 : [E1, E2] +>E1 : E1 +>E2 : E2 + +var t3: [number, any]; +>t3 : [number, any] + +var t4: [E1, E2, number]; +>t4 : [E1, E2, number] +>E1 : E1 +>E2 : E2 + +// no error +t1 = [f1, f2]; +>t1 = [f1, f2] : [(x: number) => string, (x: number) => number] +>t1 : [(x: number) => string, (x: number) => number] +>[f1, f2] : [(x: number) => string, (x: number) => number] +>f1 : (x: number) => string +>f2 : (x: number) => number + +t2 = [E1.one, E2.two]; +>t2 = [E1.one, E2.two] : [E1, E2] +>t2 : [E1, E2] +>[E1.one, E2.two] : [E1, E2] +>E1.one : E1 +>E1 : typeof E1 +>one : E1 +>E2.two : E2 +>E2 : typeof E2 +>two : E2 + +t3 = [5, undefined]; +>t3 = [5, undefined] : [number, undefined] +>t3 : [number, any] +>[5, undefined] : [number, undefined] +>undefined : undefined + +t4 = [E1.one, E2.two, 20]; +>t4 = [E1.one, E2.two, 20] : [E1, E2, number] +>t4 : [E1, E2, number] +>[E1.one, E2.two, 20] : [E1, E2, number] +>E1.one : E1 +>E1 : typeof E1 +>one : E1 +>E2.two : E2 +>E2 : typeof E2 +>two : E2 + +var e1 = t1[2]; // {} +>e1 : { (x: number): string; } | { (x: number): number; } +>t1[2] : { (x: number): string; } | { (x: number): number; } +>t1 : [(x: number) => string, (x: number) => number] + +var e2 = t2[2]; // {} +>e2 : E1 | E2 +>t2[2] : E1 | E2 +>t2 : [E1, E2] + +var e3 = t3[2]; // any +>e3 : any +>t3[2] : any +>t3 : [number, any] + +var e4 = t4[3]; // number +>e4 : number +>t4[3] : number +>t4 : [E1, E2, number] + diff --git a/tests/baselines/reference/bestCommonTypeOfTuple2.js b/tests/baselines/reference/bestCommonTypeOfTuple2.js index 2f2db308fc9..f9183f41348 100644 --- a/tests/baselines/reference/bestCommonTypeOfTuple2.js +++ b/tests/baselines/reference/bestCommonTypeOfTuple2.js @@ -1,4 +1,4 @@ -//// [bestCommonTypeOfTuple2.ts] +//// [bestCommonTypeOfTuple2.ts] interface base { } interface base1 { i } class C implements base { c } @@ -20,58 +20,58 @@ var e21 = t2[4]; // {} var e31 = t3[4]; // C1 var e41 = t4[2]; // base1 var e51 = t5[2]; // {} - - -//// [bestCommonTypeOfTuple2.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C = (function () { - function C() { - } - return C; -})(); -var D = (function () { - function D() { - } - return D; -})(); -var E = (function () { - function E() { - } - return E; -})(); -var F = (function (_super) { - __extends(F, _super); - function F() { - _super.apply(this, arguments); - } - return F; -})(C); -var C1 = (function () { - function C1() { - this.i = "foo"; - } - return C1; -})(); -var D1 = (function (_super) { - __extends(D1, _super); - function D1() { - _super.apply(this, arguments); - this.i = "bar"; - } - return D1; -})(C1); -var t1; -var t2; -var t3; -var t4; -var t5; -var e11 = t1[4]; // base -var e21 = t2[4]; // {} -var e31 = t3[4]; // C1 -var e41 = t4[2]; // base1 -var e51 = t5[2]; // {} + + +//// [bestCommonTypeOfTuple2.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var C = (function () { + function C() { + } + return C; +})(); +var D = (function () { + function D() { + } + return D; +})(); +var E = (function () { + function E() { + } + return E; +})(); +var F = (function (_super) { + __extends(F, _super); + function F() { + _super.apply(this, arguments); + } + return F; +})(C); +var C1 = (function () { + function C1() { + this.i = "foo"; + } + return C1; +})(); +var D1 = (function (_super) { + __extends(D1, _super); + function D1() { + _super.apply(this, arguments); + this.i = "bar"; + } + return D1; +})(C1); +var t1; +var t2; +var t3; +var t4; +var t5; +var e11 = t1[4]; // base +var e21 = t2[4]; // {} +var e31 = t3[4]; // C1 +var e41 = t4[2]; // base1 +var e51 = t5[2]; // {} diff --git a/tests/baselines/reference/bestCommonTypeOfTuple2.types b/tests/baselines/reference/bestCommonTypeOfTuple2.types index ec52e6c685f..a87407e98fc 100644 --- a/tests/baselines/reference/bestCommonTypeOfTuple2.types +++ b/tests/baselines/reference/bestCommonTypeOfTuple2.types @@ -1,90 +1,90 @@ -=== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple2.ts === -interface base { } ->base : base - -interface base1 { i } ->base1 : base1 ->i : any - -class C implements base { c } ->C : C ->base : base ->c : any - -class D implements base { d } ->D : D ->base : base ->d : any - -class E implements base { e } ->E : E ->base : base ->e : any - -class F extends C { f } ->F : F ->C : C ->f : any - -class C1 implements base1 { i = "foo"; c } ->C1 : C1 ->base1 : base1 ->i : string ->c : any - -class D1 extends C1 { i = "bar"; d } ->D1 : D1 ->C1 : C1 ->i : string ->d : any - -var t1: [C, base]; ->t1 : [C, base] ->C : C ->base : base - -var t2: [C, D]; ->t2 : [C, D] ->C : C ->D : D - -var t3: [C1, D1]; ->t3 : [C1, D1] ->C1 : C1 ->D1 : D1 - -var t4: [base1, C1]; ->t4 : [base1, C1] ->base1 : base1 ->C1 : C1 - -var t5: [C1, F] ->t5 : [C1, F] ->C1 : C1 ->F : F - -var e11 = t1[4]; // base ->e11 : base ->t1[4] : base ->t1 : [C, base] - -var e21 = t2[4]; // {} ->e21 : {} ->t2[4] : {} ->t2 : [C, D] - -var e31 = t3[4]; // C1 ->e31 : C1 ->t3[4] : C1 ->t3 : [C1, D1] - -var e41 = t4[2]; // base1 ->e41 : base1 ->t4[2] : base1 ->t4 : [base1, C1] - -var e51 = t5[2]; // {} ->e51 : {} ->t5[2] : {} ->t5 : [C1, F] - +=== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple2.ts === +interface base { } +>base : base + +interface base1 { i } +>base1 : base1 +>i : any + +class C implements base { c } +>C : C +>base : base +>c : any + +class D implements base { d } +>D : D +>base : base +>d : any + +class E implements base { e } +>E : E +>base : base +>e : any + +class F extends C { f } +>F : F +>C : C +>f : any + +class C1 implements base1 { i = "foo"; c } +>C1 : C1 +>base1 : base1 +>i : string +>c : any + +class D1 extends C1 { i = "bar"; d } +>D1 : D1 +>C1 : C1 +>i : string +>d : any + +var t1: [C, base]; +>t1 : [C, base] +>C : C +>base : base + +var t2: [C, D]; +>t2 : [C, D] +>C : C +>D : D + +var t3: [C1, D1]; +>t3 : [C1, D1] +>C1 : C1 +>D1 : D1 + +var t4: [base1, C1]; +>t4 : [base1, C1] +>base1 : base1 +>C1 : C1 + +var t5: [C1, F] +>t5 : [C1, F] +>C1 : C1 +>F : F + +var e11 = t1[4]; // base +>e11 : base +>t1[4] : base +>t1 : [C, base] + +var e21 = t2[4]; // {} +>e21 : C | D +>t2[4] : C | D +>t2 : [C, D] + +var e31 = t3[4]; // C1 +>e31 : C1 +>t3[4] : C1 +>t3 : [C1, D1] + +var e41 = t4[2]; // base1 +>e41 : base1 +>t4[2] : base1 +>t4 : [base1, C1] + +var e51 = t5[2]; // {} +>e51 : F | C1 +>t5[2] : F | C1 +>t5 : [C1, F] + diff --git a/tests/baselines/reference/bitwiseCompoundAssignmentOperators.errors.txt b/tests/baselines/reference/bitwiseCompoundAssignmentOperators.errors.txt index 1cd51984682..ae7a8fdce0a 100644 --- a/tests/baselines/reference/bitwiseCompoundAssignmentOperators.errors.txt +++ b/tests/baselines/reference/bitwiseCompoundAssignmentOperators.errors.txt @@ -1,59 +1,59 @@ -tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(3,1): error TS2447: The '^=' operator is not allowed for boolean types. Consider using '!==' instead. -tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(7,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(9,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(14,1): error TS2447: The '&=' operator is not allowed for boolean types. Consider using '&&' instead. -tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(18,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(20,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(24,1): error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead. -tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(28,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - - -==== tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts (8 errors) ==== - var a = true; - var b = 1; - a ^= a; - ~~~~~~ -!!! error TS2447: The '^=' operator is not allowed for boolean types. Consider using '!==' instead. - a = true; - b ^= b; - b = 1; - a ^= b; - ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - a = true; - b ^= a; - ~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - b = 1; - - var c = false; - var d = 2; - c &= c; - ~~~~~~ -!!! error TS2447: The '&=' operator is not allowed for boolean types. Consider using '&&' instead. - c = false; - d &= d; - d = 2; - c &= d; - ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - c = false; - d &= c; - ~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - - var e = true; - var f = 0; - e |= e; - ~~~~~~ -!!! error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead. - e = true; - f |= f; - f = 0; - e |= f; - ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - e = true; - f |= f; - +tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(3,1): error TS2447: The '^=' operator is not allowed for boolean types. Consider using '!==' instead. +tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(7,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(9,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(14,1): error TS2447: The '&=' operator is not allowed for boolean types. Consider using '&&' instead. +tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(18,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(20,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(24,1): error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead. +tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(28,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + +==== tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts (8 errors) ==== + var a = true; + var b = 1; + a ^= a; + ~~~~~~ +!!! error TS2447: The '^=' operator is not allowed for boolean types. Consider using '!==' instead. + a = true; + b ^= b; + b = 1; + a ^= b; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + a = true; + b ^= a; + ~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + b = 1; + + var c = false; + var d = 2; + c &= c; + ~~~~~~ +!!! error TS2447: The '&=' operator is not allowed for boolean types. Consider using '&&' instead. + c = false; + d &= d; + d = 2; + c &= d; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + c = false; + d &= c; + ~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var e = true; + var f = 0; + e |= e; + ~~~~~~ +!!! error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead. + e = true; + f |= f; + f = 0; + e |= f; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + e = true; + f |= f; + \ No newline at end of file diff --git a/tests/baselines/reference/bitwiseCompoundAssignmentOperators.js b/tests/baselines/reference/bitwiseCompoundAssignmentOperators.js index e9bfeabb965..c148fc0142c 100644 --- a/tests/baselines/reference/bitwiseCompoundAssignmentOperators.js +++ b/tests/baselines/reference/bitwiseCompoundAssignmentOperators.js @@ -1,4 +1,4 @@ -//// [bitwiseCompoundAssignmentOperators.ts] +//// [bitwiseCompoundAssignmentOperators.ts] var a = true; var b = 1; a ^= a; @@ -30,34 +30,34 @@ e |= f; e = true; f |= f; - - -//// [bitwiseCompoundAssignmentOperators.js] -var a = true; -var b = 1; -a ^= a; -a = true; -b ^= b; -b = 1; -a ^= b; -a = true; -b ^= a; -b = 1; -var c = false; -var d = 2; -c &= c; -c = false; -d &= d; -d = 2; -c &= d; -c = false; -d &= c; -var e = true; -var f = 0; -e |= e; -e = true; -f |= f; -f = 0; -e |= f; -e = true; -f |= f; + + +//// [bitwiseCompoundAssignmentOperators.js] +var a = true; +var b = 1; +a ^= a; +a = true; +b ^= b; +b = 1; +a ^= b; +a = true; +b ^= a; +b = 1; +var c = false; +var d = 2; +c &= c; +c = false; +d &= d; +d = 2; +c &= d; +c = false; +d &= c; +var e = true; +var f = 0; +e |= e; +e = true; +f |= f; +f = 0; +e |= f; +e = true; +f |= f; diff --git a/tests/baselines/reference/castingTuple.errors.txt b/tests/baselines/reference/castingTuple.errors.txt index ee09362f01f..c3079699a80 100644 --- a/tests/baselines/reference/castingTuple.errors.txt +++ b/tests/baselines/reference/castingTuple.errors.txt @@ -1,61 +1,73 @@ -tests/cases/conformance/types/tuple/castingTuple.ts(24,10): error TS2353: Neither type '[number, string]' nor type '[number, number]' is assignable to the other: - Types of property '1' are incompatible: - Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/tuple/castingTuple.ts(25,10): error TS2353: 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 TS2353: Neither type '[number, string]' nor type 'number[]' is assignable to the other: - Types of property 'pop' are incompatible: - Type '() => {}' is not assignable to type '() => number': - Type '{}' is not assignable to type 'number'. -tests/cases/conformance/types/tuple/castingTuple.ts(27,1): error TS2304: Cannot find name 't4'. - - -==== tests/cases/conformance/types/tuple/castingTuple.ts (5 errors) ==== - interface I { } - class A { a = 10; } - class C implements I { c }; - class D implements I { d }; - class E extends A { e }; - class F extends A { f }; - enum E1 { one } - enum E2 { one } - - // no error - var numStrTuple: [number, string] = [5, "foo"]; - var emptyObjTuple = <[{}, {}]>numStrTuple; - var numStrBoolTuple = <[number, string, boolean]>numStrTuple; - var classCDTuple: [C, D] = [new C(), new D()]; - var interfaceIITuple = <[I, I]>classCDTuple; - var classCDATuple = <[C, D, A]>classCDTuple; - var eleFromCDA1 = classCDATuple[2]; // A - var eleFromCDA2 = classCDATuple[5]; // {} - var t10: [E1, E2] = [E1.one, E2.one]; - var t11 = <[number, number]>t10; - var array1 = <{}[]>emptyObjTuple; - - // error - var t3 = <[number, number]>numStrTuple; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2353: Neither type '[number, string]' nor type '[number, number]' is assignable to the other: -!!! error TS2353: Types of property '1' are incompatible: -!!! error TS2353: Type 'string' is not assignable to type 'number'. - var t9 = <[A, I]>classCDTuple; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2353: Neither type '[C, D]' nor type '[A, I]' is assignable to the other: -!!! error TS2353: Types of property '0' are incompatible: -!!! error TS2353: Type 'C' is not assignable to type 'A': -!!! error TS2353: Property 'a' is missing in type 'C'. - var array1 = numStrTuple; - ~~~~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'. - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2353: Neither type '[number, string]' nor type 'number[]' is assignable to the other: -!!! error TS2353: Types of property 'pop' are incompatible: -!!! error TS2353: Type '() => {}' is not assignable to type '() => number': -!!! error TS2353: Type '{}' is not assignable to type 'number'. - t4[2] = 10; - ~~ +tests/cases/conformance/types/tuple/castingTuple.ts(13,23): error TS2353: Neither type '[number, string]' nor type '[number, string, boolean]' is assignable to the other: + Property '2' is missing in type '[number, string]'. +tests/cases/conformance/types/tuple/castingTuple.ts(16,21): error TS2353: Neither type '[C, D]' nor type '[C, D, A]' is assignable to the other: + Property '2' is missing in type '[C, D]'. +tests/cases/conformance/types/tuple/castingTuple.ts(24,10): error TS2353: Neither type '[number, string]' nor type '[number, number]' is assignable to the other: + Types of property '1' are incompatible: + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/castingTuple.ts(25,10): error TS2353: 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 TS2353: Neither type '[number, string]' nor type 'number[]' is assignable to the other: + Types of property 'pop' are incompatible: + Type '() => string | number' is not assignable to type '() => number': + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/castingTuple.ts(27,1): error TS2304: Cannot find name 't4'. + + +==== tests/cases/conformance/types/tuple/castingTuple.ts (7 errors) ==== + interface I { } + class A { a = 10; } + class C implements I { c }; + class D implements I { d }; + class E extends A { e }; + class F extends A { f }; + enum E1 { one } + enum E2 { one } + + // no error + var numStrTuple: [number, string] = [5, "foo"]; + var emptyObjTuple = <[{}, {}]>numStrTuple; + var numStrBoolTuple = <[number, string, boolean]>numStrTuple; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2353: Neither type '[number, string]' nor type '[number, string, boolean]' is assignable to the other: +!!! error TS2353: Property '2' is missing in type '[number, string]'. + var classCDTuple: [C, D] = [new C(), new D()]; + var interfaceIITuple = <[I, I]>classCDTuple; + var classCDATuple = <[C, D, A]>classCDTuple; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2353: Neither type '[C, D]' nor type '[C, D, A]' is assignable to the other: +!!! error TS2353: Property '2' is missing in type '[C, D]'. + var eleFromCDA1 = classCDATuple[2]; // A + var eleFromCDA2 = classCDATuple[5]; // {} + var t10: [E1, E2] = [E1.one, E2.one]; + var t11 = <[number, number]>t10; + var array1 = <{}[]>emptyObjTuple; + + // error + var t3 = <[number, number]>numStrTuple; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2353: Neither type '[number, string]' nor type '[number, number]' is assignable to the other: +!!! error TS2353: Types of property '1' are incompatible: +!!! error TS2353: Type 'string' is not assignable to type 'number'. + var t9 = <[A, I]>classCDTuple; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2353: Neither type '[C, D]' nor type '[A, I]' is assignable to the other: +!!! error TS2353: Types of property '0' are incompatible: +!!! error TS2353: Type 'C' is not assignable to type 'A': +!!! error TS2353: Property 'a' is missing in type 'C'. + var array1 = numStrTuple; + ~~~~~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2353: Neither type '[number, string]' nor type 'number[]' is assignable to the other: +!!! error TS2353: Types of property 'pop' are incompatible: +!!! error TS2353: Type '() => string | number' is not assignable to type '() => number': +!!! error TS2353: Type 'string | number' is not assignable to type 'number': +!!! error TS2353: Type 'string' is not assignable to type 'number'. + t4[2] = 10; + ~~ !!! error TS2304: Cannot find name 't4'. \ No newline at end of file diff --git a/tests/baselines/reference/castingTuple.js b/tests/baselines/reference/castingTuple.js index c1835e9d117..0671062bb4e 100644 --- a/tests/baselines/reference/castingTuple.js +++ b/tests/baselines/reference/castingTuple.js @@ -1,4 +1,4 @@ -//// [castingTuple.ts] +//// [castingTuple.ts] interface I { } class A { a = 10; } class C implements I { c }; @@ -25,71 +25,71 @@ var array1 = <{}[]>emptyObjTuple; var t3 = <[number, number]>numStrTuple; var t9 = <[A, I]>classCDTuple; var array1 = numStrTuple; -t4[2] = 10; - -//// [castingTuple.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var A = (function () { - function A() { - this.a = 10; - } - return A; -})(); -var C = (function () { - function C() { - } - return C; -})(); -; -var D = (function () { - function D() { - } - return D; -})(); -; -var E = (function (_super) { - __extends(E, _super); - function E() { - _super.apply(this, arguments); - } - return E; -})(A); -; -var F = (function (_super) { - __extends(F, _super); - function F() { - _super.apply(this, arguments); - } - return F; -})(A); -; -var E1; -(function (E1) { - E1[E1["one"] = 0] = "one"; -})(E1 || (E1 = {})); -var E2; -(function (E2) { - E2[E2["one"] = 0] = "one"; -})(E2 || (E2 = {})); -// no error -var numStrTuple = [5, "foo"]; -var emptyObjTuple = numStrTuple; -var numStrBoolTuple = numStrTuple; -var classCDTuple = [new C(), new D()]; -var interfaceIITuple = classCDTuple; -var classCDATuple = classCDTuple; -var eleFromCDA1 = classCDATuple[2]; // A -var eleFromCDA2 = classCDATuple[5]; // {} -var t10 = [0 /* one */, 0 /* one */]; -var t11 = t10; -var array1 = emptyObjTuple; -// error -var t3 = numStrTuple; -var t9 = classCDTuple; -var array1 = numStrTuple; -t4[2] = 10; +t4[2] = 10; + +//// [castingTuple.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var A = (function () { + function A() { + this.a = 10; + } + return A; +})(); +var C = (function () { + function C() { + } + return C; +})(); +; +var D = (function () { + function D() { + } + return D; +})(); +; +var E = (function (_super) { + __extends(E, _super); + function E() { + _super.apply(this, arguments); + } + return E; +})(A); +; +var F = (function (_super) { + __extends(F, _super); + function F() { + _super.apply(this, arguments); + } + return F; +})(A); +; +var E1; +(function (E1) { + E1[E1["one"] = 0] = "one"; +})(E1 || (E1 = {})); +var E2; +(function (E2) { + E2[E2["one"] = 0] = "one"; +})(E2 || (E2 = {})); +// no error +var numStrTuple = [5, "foo"]; +var emptyObjTuple = numStrTuple; +var numStrBoolTuple = numStrTuple; +var classCDTuple = [new C(), new D()]; +var interfaceIITuple = classCDTuple; +var classCDATuple = classCDTuple; +var eleFromCDA1 = classCDATuple[2]; // A +var eleFromCDA2 = classCDATuple[5]; // {} +var t10 = [0 /* one */, 0 /* one */]; +var t11 = t10; +var array1 = emptyObjTuple; +// error +var t3 = numStrTuple; +var t9 = classCDTuple; +var array1 = numStrTuple; +t4[2] = 10; diff --git a/tests/baselines/reference/contextualTypeWithTuple.errors.txt b/tests/baselines/reference/contextualTypeWithTuple.errors.txt index e739c916c8a..bd1aa155661 100644 --- a/tests/baselines/reference/contextualTypeWithTuple.errors.txt +++ b/tests/baselines/reference/contextualTypeWithTuple.errors.txt @@ -1,40 +1,58 @@ -tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(11,1): error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]': - Types of property '0' are incompatible: - Type '{}' is not assignable to type '{ a: string; }': - Property 'a' is missing in type '{}'. -tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(12,1): error TS2322: Type '[number, string]' is not assignable to type '[number, string, boolean]': - Property '2' is missing in type '[number, string]'. -tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(13,5): error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]': - Types of property 'pop' are incompatible: - Type '() => {}' is not assignable to type '() => string': - Type '{}' is not assignable to type 'string'. - - -==== tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts (3 errors) ==== - // no error - var numStrTuple: [number, string] = [5, "hello"]; - var numStrTuple2: [number, string] = [5, "foo", true]; - var numStrBoolTuple: [number, string, boolean] = [5, "foo", true]; - var objNumTuple: [{ a: string }, number] = [{ a: "world" }, 5]; - var strTupleTuple: [string, [number, {}]] = ["bar", [5, { x: 1, y: 1 }]]; - numStrTuple = numStrTuple2; - numStrTuple = numStrBoolTuple; - - // error - objNumTuple = [ {}, 5]; - ~~~~~~~~~~~ -!!! error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]': -!!! error TS2322: Types of property '0' are incompatible: -!!! error TS2322: Type '{}' is not assignable to type '{ a: string; }': -!!! error TS2322: Property 'a' is missing in type '{}'. - numStrBoolTuple = numStrTuple; - ~~~~~~~~~~~~~~~ -!!! error TS2322: Type '[number, string]' is not assignable to type '[number, string, boolean]': -!!! error TS2322: Property '2' is missing in type '[number, string]'. - var strStrTuple: [string, string] = ["foo", "bar", 5]; - ~~~~~~~~~~~ -!!! error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]': -!!! error TS2322: Types of property 'pop' are incompatible: -!!! error TS2322: Type '() => {}' is not assignable to type '() => string': -!!! error TS2322: Type '{}' is not assignable to type 'string'. +tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(3,5): error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]': + Types of property 'pop' are incompatible: + Type '() => string | number | boolean' is not assignable to type '() => string | number': + Type 'string | number | boolean' is not assignable to type 'string | number': + Type 'boolean' is not assignable to type 'string | number': + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(8,1): error TS2323: Type '[number, string, boolean]' is not assignable to type '[number, string]'. +tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(11,1): error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]': + Types of property '0' are incompatible: + Type '{}' is not assignable to type '{ a: string; }': + Property 'a' is missing in type '{}'. +tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(12,1): error TS2322: Type '[number, string]' is not assignable to type '[number, string, boolean]': + Property '2' is missing in type '[number, string]'. +tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(13,5): error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]': + Types of property 'pop' are incompatible: + Type '() => string | number' is not assignable to type '() => string': + Type 'string | number' is not assignable to type 'string': + Type 'number' is not assignable to type 'string'. + + +==== tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts (5 errors) ==== + // no error + var numStrTuple: [number, string] = [5, "hello"]; + var numStrTuple2: [number, string] = [5, "foo", true]; + ~~~~~~~~~~~~ +!!! error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]': +!!! error TS2322: Types of property 'pop' are incompatible: +!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => string | number': +!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'string | number': +!!! error TS2322: Type 'boolean' is not assignable to type 'string | number': +!!! error TS2322: Type 'boolean' is not assignable to type 'number'. + var numStrBoolTuple: [number, string, boolean] = [5, "foo", true]; + var objNumTuple: [{ a: string }, number] = [{ a: "world" }, 5]; + var strTupleTuple: [string, [number, {}]] = ["bar", [5, { x: 1, y: 1 }]]; + numStrTuple = numStrTuple2; + numStrTuple = numStrBoolTuple; + ~~~~~~~~~~~ +!!! error TS2323: Type '[number, string, boolean]' is not assignable to type '[number, string]'. + + // error + objNumTuple = [ {}, 5]; + ~~~~~~~~~~~ +!!! error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]': +!!! error TS2322: Types of property '0' are incompatible: +!!! error TS2322: Type '{}' is not assignable to type '{ a: string; }': +!!! error TS2322: Property 'a' is missing in type '{}'. + numStrBoolTuple = numStrTuple; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '[number, string]' is not assignable to type '[number, string, boolean]': +!!! error TS2322: Property '2' is missing in type '[number, string]'. + var strStrTuple: [string, string] = ["foo", "bar", 5]; + ~~~~~~~~~~~ +!!! error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]': +!!! error TS2322: Types of property 'pop' are incompatible: +!!! error TS2322: Type '() => string | number' is not assignable to type '() => string': +!!! error TS2322: Type 'string | number' is not assignable to type 'string': +!!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypeWithTuple.js b/tests/baselines/reference/contextualTypeWithTuple.js index 0e53cea283b..61a2df5d8ce 100644 --- a/tests/baselines/reference/contextualTypeWithTuple.js +++ b/tests/baselines/reference/contextualTypeWithTuple.js @@ -1,4 +1,4 @@ -//// [contextualTypeWithTuple.ts] +//// [contextualTypeWithTuple.ts] // no error var numStrTuple: [number, string] = [5, "hello"]; var numStrTuple2: [number, string] = [5, "foo", true]; @@ -12,18 +12,18 @@ numStrTuple = numStrBoolTuple; objNumTuple = [ {}, 5]; numStrBoolTuple = numStrTuple; var strStrTuple: [string, string] = ["foo", "bar", 5]; - - -//// [contextualTypeWithTuple.js] -// no error -var numStrTuple = [5, "hello"]; -var numStrTuple2 = [5, "foo", true]; -var numStrBoolTuple = [5, "foo", true]; -var objNumTuple = [{ a: "world" }, 5]; -var strTupleTuple = ["bar", [5, { x: 1, y: 1 }]]; -numStrTuple = numStrTuple2; -numStrTuple = numStrBoolTuple; -// error -objNumTuple = [{}, 5]; -numStrBoolTuple = numStrTuple; -var strStrTuple = ["foo", "bar", 5]; + + +//// [contextualTypeWithTuple.js] +// no error +var numStrTuple = [5, "hello"]; +var numStrTuple2 = [5, "foo", true]; +var numStrBoolTuple = [5, "foo", true]; +var objNumTuple = [{ a: "world" }, 5]; +var strTupleTuple = ["bar", [5, { x: 1, y: 1 }]]; +numStrTuple = numStrTuple2; +numStrTuple = numStrBoolTuple; +// error +objNumTuple = [{}, 5]; +numStrBoolTuple = numStrTuple; +var strStrTuple = ["foo", "bar", 5]; diff --git a/tests/baselines/reference/genericCallWithTupleType.errors.txt b/tests/baselines/reference/genericCallWithTupleType.errors.txt index 7f84cee760c..abfe5087131 100644 --- a/tests/baselines/reference/genericCallWithTupleType.errors.txt +++ b/tests/baselines/reference/genericCallWithTupleType.errors.txt @@ -1,47 +1,65 @@ -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(22,1): error TS2322: Type '[number, string]' is not assignable to type '[string, number]': - Types of property '0' are incompatible: - Type 'number' is not assignable to type 'string'. -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(23,1): error TS2322: Type '[{}, {}]' is not assignable to type '[string, number]': - Types of property '0' are incompatible: - Type '{}' is not assignable to type 'string'. -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(24,1): error TS2322: Type '[{}]' is not assignable to type '[{}, {}]': - Property '1' is missing in type '[{}]'. - - -==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts (3 errors) ==== - interface I { - tuple1: [T, U]; - } - - var i1: I; - var i2: I<{}, {}>; - - // no error - i1.tuple1 = ["foo", 5]; - var e1 = i1.tuple1[0]; // string - var e2 = i1.tuple1[1]; // number - i1.tuple1 = ["foo", 5, false, true]; - var e3 = i1.tuple1[2]; // {} - i1.tuple1[3] = { a: "string" }; - var e4 = i1.tuple1[3]; // {} - i2.tuple1 = ["foo", 5]; - i2.tuple1 = ["foo", "bar"]; - i2.tuple1 = [5, "bar"]; - i2.tuple1 = [{}, {}]; - - // error - i1.tuple1 = [5, "foo"]; - ~~~~~~~~~ -!!! error TS2322: Type '[number, string]' is not assignable to type '[string, number]': -!!! error TS2322: Types of property '0' are incompatible: -!!! error TS2322: Type 'number' is not assignable to type 'string'. - i1.tuple1 = [{}, {}]; - ~~~~~~~~~ -!!! error TS2322: Type '[{}, {}]' is not assignable to type '[string, number]': -!!! error TS2322: Types of property '0' are incompatible: -!!! error TS2322: Type '{}' is not assignable to type 'string'. - i2.tuple1 = [{}]; - ~~~~~~~~~ -!!! error TS2322: Type '[{}]' is not assignable to type '[{}, {}]': -!!! error TS2322: Property '1' is missing in type '[{}]'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(12,1): error TS2322: Type '[string, number, boolean, boolean]' is not assignable to type '[string, number]': + Types of property 'pop' are incompatible: + Type '() => string | number | boolean' is not assignable to type '() => string | number': + Type 'string | number | boolean' is not assignable to type 'string | number': + Type 'boolean' is not assignable to type 'string | number': + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(14,1): error TS2322: Type '{ a: string; }' is not assignable to type 'string | number': + Type '{ a: string; }' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(22,1): error TS2322: Type '[number, string]' is not assignable to type '[string, number]': + Types of property '0' are incompatible: + Type 'number' is not assignable to type 'string'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(23,1): error TS2322: Type '[{}, {}]' is not assignable to type '[string, number]': + Types of property '0' are incompatible: + Type '{}' is not assignable to type 'string'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(24,1): error TS2322: Type '[{}]' is not assignable to type '[{}, {}]': + Property '1' is missing in type '[{}]'. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts (5 errors) ==== + interface I { + tuple1: [T, U]; + } + + var i1: I; + var i2: I<{}, {}>; + + // no error + i1.tuple1 = ["foo", 5]; + var e1 = i1.tuple1[0]; // string + var e2 = i1.tuple1[1]; // number + i1.tuple1 = ["foo", 5, false, true]; + ~~~~~~~~~ +!!! error TS2322: Type '[string, number, boolean, boolean]' is not assignable to type '[string, number]': +!!! error TS2322: Types of property 'pop' are incompatible: +!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => string | number': +!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'string | number': +!!! error TS2322: Type 'boolean' is not assignable to type 'string | number': +!!! error TS2322: Type 'boolean' is not assignable to type 'number'. + var e3 = i1.tuple1[2]; // {} + i1.tuple1[3] = { a: "string" }; + ~~~~~~~~~~~~ +!!! error TS2322: Type '{ a: string; }' is not assignable to type 'string | number': +!!! error TS2322: Type '{ a: string; }' is not assignable to type 'number'. + var e4 = i1.tuple1[3]; // {} + i2.tuple1 = ["foo", 5]; + i2.tuple1 = ["foo", "bar"]; + i2.tuple1 = [5, "bar"]; + i2.tuple1 = [{}, {}]; + + // error + i1.tuple1 = [5, "foo"]; + ~~~~~~~~~ +!!! error TS2322: Type '[number, string]' is not assignable to type '[string, number]': +!!! error TS2322: Types of property '0' are incompatible: +!!! error TS2322: Type 'number' is not assignable to type 'string'. + i1.tuple1 = [{}, {}]; + ~~~~~~~~~ +!!! error TS2322: Type '[{}, {}]' is not assignable to type '[string, number]': +!!! error TS2322: Types of property '0' are incompatible: +!!! error TS2322: Type '{}' is not assignable to type 'string'. + i2.tuple1 = [{}]; + ~~~~~~~~~ +!!! error TS2322: Type '[{}]' is not assignable to type '[{}, {}]': +!!! error TS2322: Property '1' is missing in type '[{}]'. \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithTupleType.js b/tests/baselines/reference/genericCallWithTupleType.js index 5ac66f66c3c..296a6dad63b 100644 --- a/tests/baselines/reference/genericCallWithTupleType.js +++ b/tests/baselines/reference/genericCallWithTupleType.js @@ -1,4 +1,4 @@ -//// [genericCallWithTupleType.ts] +//// [genericCallWithTupleType.ts] interface I { tuple1: [T, U]; } @@ -23,24 +23,24 @@ i2.tuple1 = [{}, {}]; i1.tuple1 = [5, "foo"]; i1.tuple1 = [{}, {}]; i2.tuple1 = [{}]; - - -//// [genericCallWithTupleType.js] -var i1; -var i2; -// no error -i1.tuple1 = ["foo", 5]; -var e1 = i1.tuple1[0]; // string -var e2 = i1.tuple1[1]; // number -i1.tuple1 = ["foo", 5, false, true]; -var e3 = i1.tuple1[2]; // {} -i1.tuple1[3] = { a: "string" }; -var e4 = i1.tuple1[3]; // {} -i2.tuple1 = ["foo", 5]; -i2.tuple1 = ["foo", "bar"]; -i2.tuple1 = [5, "bar"]; -i2.tuple1 = [{}, {}]; -// error -i1.tuple1 = [5, "foo"]; -i1.tuple1 = [{}, {}]; -i2.tuple1 = [{}]; + + +//// [genericCallWithTupleType.js] +var i1; +var i2; +// no error +i1.tuple1 = ["foo", 5]; +var e1 = i1.tuple1[0]; // string +var e2 = i1.tuple1[1]; // number +i1.tuple1 = ["foo", 5, false, true]; +var e3 = i1.tuple1[2]; // {} +i1.tuple1[3] = { a: "string" }; +var e4 = i1.tuple1[3]; // {} +i2.tuple1 = ["foo", 5]; +i2.tuple1 = ["foo", "bar"]; +i2.tuple1 = [5, "bar"]; +i2.tuple1 = [{}, {}]; +// error +i1.tuple1 = [5, "foo"]; +i1.tuple1 = [{}, {}]; +i2.tuple1 = [{}]; diff --git a/tests/baselines/reference/getEmitOutputExternalModule.baseline b/tests/baselines/reference/getEmitOutputExternalModule.baseline index b5e670c5fd7..33360cbed61 100644 --- a/tests/baselines/reference/getEmitOutputExternalModule.baseline +++ b/tests/baselines/reference/getEmitOutputExternalModule.baseline @@ -1,9 +1,9 @@ EmitOutputStatus : Succeeded Filename : declSingleFile.js -var x = 5; -var Bar = (function () { - function Bar() { - } - return Bar; -})(); +var x = 5; +var Bar = (function () { + function Bar() { + } + return Bar; +})(); diff --git a/tests/baselines/reference/getEmitOutputExternalModule2.baseline b/tests/baselines/reference/getEmitOutputExternalModule2.baseline index 5c03a092257..ede5474d8cc 100644 --- a/tests/baselines/reference/getEmitOutputExternalModule2.baseline +++ b/tests/baselines/reference/getEmitOutputExternalModule2.baseline @@ -1,15 +1,15 @@ EmitOutputStatus : JSGeneratedWithSemanticErrors Filename : declSingleFile.js -var x = 5; -var Bar = (function () { - function Bar() { - } - return Bar; -})(); -var x = "world"; -var Bar2 = (function () { - function Bar2() { - } - return Bar2; -})(); +var x = 5; +var Bar = (function () { + function Bar() { + } + return Bar; +})(); +var x = "world"; +var Bar2 = (function () { + function Bar2() { + } + return Bar2; +})(); diff --git a/tests/baselines/reference/indexerWithTuple.js b/tests/baselines/reference/indexerWithTuple.js index bc3bee9dd17..fc82716ba05 100644 --- a/tests/baselines/reference/indexerWithTuple.js +++ b/tests/baselines/reference/indexerWithTuple.js @@ -1,4 +1,4 @@ -//// [indexerWithTuple.ts] +//// [indexerWithTuple.ts] var strNumTuple: [string, number] = ["foo", 10]; var numTupleTuple: [number, [string, number]] = [10, ["bar", 20]]; @@ -13,20 +13,20 @@ var ele14 = strNumTuple[idx1]; // {} var ele15 = strNumTuple["0"]; // string var ele16 = strNumTuple["1"]; // number var strNumTuple1 = numTupleTuple[1]; //[string, number]; -var ele17 = numTupleTuple[2]; // {} - -//// [indexerWithTuple.js] -var strNumTuple = ["foo", 10]; -var numTupleTuple = [10, ["bar", 20]]; -// no error -var idx0 = 0; -var idx1 = 1; -var ele10 = strNumTuple[0]; // string -var ele11 = strNumTuple[1]; // number -var ele12 = strNumTuple[2]; // {} -var ele13 = strNumTuple[idx0]; // {} -var ele14 = strNumTuple[idx1]; // {} -var ele15 = strNumTuple["0"]; // string -var ele16 = strNumTuple["1"]; // number -var strNumTuple1 = numTupleTuple[1]; //[string, number]; -var ele17 = numTupleTuple[2]; // {} +var ele17 = numTupleTuple[2]; // {} + +//// [indexerWithTuple.js] +var strNumTuple = ["foo", 10]; +var numTupleTuple = [10, ["bar", 20]]; +// no error +var idx0 = 0; +var idx1 = 1; +var ele10 = strNumTuple[0]; // string +var ele11 = strNumTuple[1]; // number +var ele12 = strNumTuple[2]; // {} +var ele13 = strNumTuple[idx0]; // {} +var ele14 = strNumTuple[idx1]; // {} +var ele15 = strNumTuple["0"]; // string +var ele16 = strNumTuple["1"]; // number +var strNumTuple1 = numTupleTuple[1]; //[string, number]; +var ele17 = numTupleTuple[2]; // {} diff --git a/tests/baselines/reference/indexerWithTuple.types b/tests/baselines/reference/indexerWithTuple.types index 7c22cac407f..28053a33081 100644 --- a/tests/baselines/reference/indexerWithTuple.types +++ b/tests/baselines/reference/indexerWithTuple.types @@ -1,64 +1,64 @@ -=== tests/cases/conformance/types/tuple/indexerWithTuple.ts === -var strNumTuple: [string, number] = ["foo", 10]; ->strNumTuple : [string, number] ->["foo", 10] : [string, number] - -var numTupleTuple: [number, [string, number]] = [10, ["bar", 20]]; ->numTupleTuple : [number, [string, number]] ->[10, ["bar", 20]] : [number, [string, number]] ->["bar", 20] : [string, number] - -// no error -var idx0 = 0; ->idx0 : number - -var idx1 = 1; ->idx1 : number - -var ele10 = strNumTuple[0]; // string ->ele10 : string ->strNumTuple[0] : string ->strNumTuple : [string, number] - -var ele11 = strNumTuple[1]; // number ->ele11 : number ->strNumTuple[1] : number ->strNumTuple : [string, number] - -var ele12 = strNumTuple[2]; // {} ->ele12 : {} ->strNumTuple[2] : {} ->strNumTuple : [string, number] - -var ele13 = strNumTuple[idx0]; // {} ->ele13 : {} ->strNumTuple[idx0] : {} ->strNumTuple : [string, number] ->idx0 : number - -var ele14 = strNumTuple[idx1]; // {} ->ele14 : {} ->strNumTuple[idx1] : {} ->strNumTuple : [string, number] ->idx1 : number - -var ele15 = strNumTuple["0"]; // string ->ele15 : string ->strNumTuple["0"] : string ->strNumTuple : [string, number] - -var ele16 = strNumTuple["1"]; // number ->ele16 : number ->strNumTuple["1"] : number ->strNumTuple : [string, number] - -var strNumTuple1 = numTupleTuple[1]; //[string, number]; ->strNumTuple1 : [string, number] ->numTupleTuple[1] : [string, number] ->numTupleTuple : [number, [string, number]] - -var ele17 = numTupleTuple[2]; // {} ->ele17 : {} ->numTupleTuple[2] : {} ->numTupleTuple : [number, [string, number]] - +=== tests/cases/conformance/types/tuple/indexerWithTuple.ts === +var strNumTuple: [string, number] = ["foo", 10]; +>strNumTuple : [string, number] +>["foo", 10] : [string, number] + +var numTupleTuple: [number, [string, number]] = [10, ["bar", 20]]; +>numTupleTuple : [number, [string, number]] +>[10, ["bar", 20]] : [number, [string, number]] +>["bar", 20] : [string, number] + +// no error +var idx0 = 0; +>idx0 : number + +var idx1 = 1; +>idx1 : number + +var ele10 = strNumTuple[0]; // string +>ele10 : string +>strNumTuple[0] : string +>strNumTuple : [string, number] + +var ele11 = strNumTuple[1]; // number +>ele11 : number +>strNumTuple[1] : number +>strNumTuple : [string, number] + +var ele12 = strNumTuple[2]; // {} +>ele12 : string | number +>strNumTuple[2] : string | number +>strNumTuple : [string, number] + +var ele13 = strNumTuple[idx0]; // {} +>ele13 : string | number +>strNumTuple[idx0] : string | number +>strNumTuple : [string, number] +>idx0 : number + +var ele14 = strNumTuple[idx1]; // {} +>ele14 : string | number +>strNumTuple[idx1] : string | number +>strNumTuple : [string, number] +>idx1 : number + +var ele15 = strNumTuple["0"]; // string +>ele15 : string +>strNumTuple["0"] : string +>strNumTuple : [string, number] + +var ele16 = strNumTuple["1"]; // number +>ele16 : number +>strNumTuple["1"] : number +>strNumTuple : [string, number] + +var strNumTuple1 = numTupleTuple[1]; //[string, number]; +>strNumTuple1 : [string, number] +>numTupleTuple[1] : [string, number] +>numTupleTuple : [number, [string, number]] + +var ele17 = numTupleTuple[2]; // {} +>ele17 : number | [string, number] +>numTupleTuple[2] : number | [string, number] +>numTupleTuple : [number, [string, number]] + diff --git a/tests/baselines/reference/selfReferencingFile.errors.txt b/tests/baselines/reference/selfReferencingFile.errors.txt index 727be1ea0b2..8bf68fde774 100644 --- a/tests/baselines/reference/selfReferencingFile.errors.txt +++ b/tests/baselines/reference/selfReferencingFile.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/selfReferencingFile.ts(1,1): error TS1006: A file cannot have a reference to itself. - - -==== tests/cases/compiler/selfReferencingFile.ts (1 errors) ==== - /// - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1006: A file cannot have a reference to itself. - - class selfReferencingFile { - +tests/cases/compiler/selfReferencingFile.ts(1,1): error TS1006: A file cannot have a reference to itself. + + +==== tests/cases/compiler/selfReferencingFile.ts (1 errors) ==== + /// + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1006: A file cannot have a reference to itself. + + class selfReferencingFile { + } \ No newline at end of file diff --git a/tests/baselines/reference/selfReferencingFile2.errors.txt b/tests/baselines/reference/selfReferencingFile2.errors.txt index 5bd2d75723a..c993616784a 100644 --- a/tests/baselines/reference/selfReferencingFile2.errors.txt +++ b/tests/baselines/reference/selfReferencingFile2.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/selfReferencingFile2.ts(1,1): error TS6053: File 'tests/cases/selfReferencingFile2.ts' not found. - - -==== tests/cases/compiler/selfReferencingFile2.ts (1 errors) ==== - /// - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS6053: File 'selfReferencingFile2.ts' not found. - - class selfReferencingFile2 { - +tests/cases/compiler/selfReferencingFile2.ts(1,1): error TS6053: File 'tests/cases/selfReferencingFile2.ts' not found. + + +==== tests/cases/compiler/selfReferencingFile2.ts (1 errors) ==== + /// + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS6053: File 'selfReferencingFile2.ts' not found. + + class selfReferencingFile2 { + } \ No newline at end of file diff --git a/tests/baselines/reference/selfReferencingFile3.errors.txt b/tests/baselines/reference/selfReferencingFile3.errors.txt index e6e8deb5d47..05cf04ddc4b 100644 --- a/tests/baselines/reference/selfReferencingFile3.errors.txt +++ b/tests/baselines/reference/selfReferencingFile3.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/selfReferencingFile3.ts(1,1): error TS1006: A file cannot have a reference to itself. - - -==== tests/cases/compiler/selfReferencingFile3.ts (1 errors) ==== - /// - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1006: A file cannot have a reference to itself. - - class selfReferencingFile3 { - +tests/cases/compiler/selfReferencingFile3.ts(1,1): error TS1006: A file cannot have a reference to itself. + + +==== tests/cases/compiler/selfReferencingFile3.ts (1 errors) ==== + /// + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1006: A file cannot have a reference to itself. + + class selfReferencingFile3 { + } \ No newline at end of file diff --git a/tests/baselines/reference/typeInferenceWithTupleType.js b/tests/baselines/reference/typeInferenceWithTupleType.js index a9d75ad9990..10a18274c73 100644 --- a/tests/baselines/reference/typeInferenceWithTupleType.js +++ b/tests/baselines/reference/typeInferenceWithTupleType.js @@ -1,4 +1,4 @@ -//// [typeInferenceWithTupleType.ts] +//// [typeInferenceWithTupleType.ts] function combine(x: T, y: U): [T, U] { return [x, y]; } @@ -23,26 +23,26 @@ var zipResult = zip(["foo", "bar"], [5, 6]); var zipResultEle = zipResult[0]; // [string, number] var zipResultEleEle = zipResult[0][0]; // string - - -//// [typeInferenceWithTupleType.js] -function combine(x, y) { - return [x, y]; -} -var combineResult = combine("string", 10); -var combineEle1 = combineResult[0]; // string -var combineEle2 = combineResult[1]; // number -function zip(array1, array2) { - if (array1.length != array2.length) { - return [[undefined, undefined]]; - } - var length = array1.length; - var zipResult; - for (var i = 0; i < length; ++i) { - zipResult.push([array1[i], array2[i]]); - } - return zipResult; -} -var zipResult = zip(["foo", "bar"], [5, 6]); -var zipResultEle = zipResult[0]; // [string, number] -var zipResultEleEle = zipResult[0][0]; // string + + +//// [typeInferenceWithTupleType.js] +function combine(x, y) { + return [x, y]; +} +var combineResult = combine("string", 10); +var combineEle1 = combineResult[0]; // string +var combineEle2 = combineResult[1]; // number +function zip(array1, array2) { + if (array1.length != array2.length) { + return [[undefined, undefined]]; + } + var length = array1.length; + var zipResult; + for (var i = 0; i < length; ++i) { + zipResult.push([array1[i], array2[i]]); + } + return zipResult; +} +var zipResult = zip(["foo", "bar"], [5, 6]); +var zipResultEle = zipResult[0]; // [string, number] +var zipResultEleEle = zipResult[0][0]; // string diff --git a/tests/baselines/reference/typeInferenceWithTupleType.types b/tests/baselines/reference/typeInferenceWithTupleType.types index fbf1cd51920..3648c0aba50 100644 --- a/tests/baselines/reference/typeInferenceWithTupleType.types +++ b/tests/baselines/reference/typeInferenceWithTupleType.types @@ -1,114 +1,114 @@ -=== tests/cases/conformance/types/tuple/typeInferenceWithTupleType.ts === -function combine(x: T, y: U): [T, U] { ->combine : (x: T, y: U) => [T, U] ->T : T ->U : U ->x : T ->T : T ->y : U ->U : U ->T : T ->U : U - - return [x, y]; ->[x, y] : [T, U] ->x : T ->y : U -} - -var combineResult = combine("string", 10); ->combineResult : [string, number] ->combine("string", 10) : [string, number] ->combine : (x: T, y: U) => [T, U] - -var combineEle1 = combineResult[0]; // string ->combineEle1 : string ->combineResult[0] : string ->combineResult : [string, number] - -var combineEle2 = combineResult[1]; // number ->combineEle2 : number ->combineResult[1] : number ->combineResult : [string, number] - -function zip(array1: T[], array2: U[]): [[T, U]] { ->zip : (array1: T[], array2: U[]) => [[T, U]] ->T : T ->U : U ->array1 : T[] ->T : T ->array2 : U[] ->U : U ->T : T ->U : U - - if (array1.length != array2.length) { ->array1.length != array2.length : boolean ->array1.length : number ->array1 : T[] ->length : number ->array2.length : number ->array2 : U[] ->length : number - - return [[undefined, undefined]]; ->[[undefined, undefined]] : [[undefined, undefined]] ->[undefined, undefined] : [undefined, undefined] ->undefined : undefined ->undefined : undefined - } - var length = array1.length; ->length : number ->array1.length : number ->array1 : T[] ->length : number - - var zipResult: [[T, U]]; ->zipResult : [[T, U]] ->T : T ->U : U - - for (var i = 0; i < length; ++i) { ->i : number ->i < length : boolean ->i : number ->length : number ->++i : number ->i : number - - zipResult.push([array1[i], array2[i]]); ->zipResult.push([array1[i], array2[i]]) : number ->zipResult.push : (...items: [T, U][]) => number ->zipResult : [[T, U]] ->push : (...items: [T, U][]) => number ->[array1[i], array2[i]] : [T, U] ->array1[i] : T ->array1 : T[] ->i : number ->array2[i] : U ->array2 : U[] ->i : number - } - return zipResult; ->zipResult : [[T, U]] -} - -var zipResult = zip(["foo", "bar"], [5, 6]); ->zipResult : [[string, number]] ->zip(["foo", "bar"], [5, 6]) : [[string, number]] ->zip : (array1: T[], array2: U[]) => [[T, U]] ->["foo", "bar"] : string[] ->[5, 6] : number[] - -var zipResultEle = zipResult[0]; // [string, number] ->zipResultEle : [string, number] ->zipResult[0] : [string, number] ->zipResult : [[string, number]] - -var zipResultEleEle = zipResult[0][0]; // string ->zipResultEleEle : string ->zipResult[0][0] : string ->zipResult[0] : [string, number] ->zipResult : [[string, number]] - - +=== tests/cases/conformance/types/tuple/typeInferenceWithTupleType.ts === +function combine(x: T, y: U): [T, U] { +>combine : (x: T, y: U) => [T, U] +>T : T +>U : U +>x : T +>T : T +>y : U +>U : U +>T : T +>U : U + + return [x, y]; +>[x, y] : [T, U] +>x : T +>y : U +} + +var combineResult = combine("string", 10); +>combineResult : [string, number] +>combine("string", 10) : [string, number] +>combine : (x: T, y: U) => [T, U] + +var combineEle1 = combineResult[0]; // string +>combineEle1 : string +>combineResult[0] : string +>combineResult : [string, number] + +var combineEle2 = combineResult[1]; // number +>combineEle2 : number +>combineResult[1] : number +>combineResult : [string, number] + +function zip(array1: T[], array2: U[]): [[T, U]] { +>zip : (array1: T[], array2: U[]) => [[T, U]] +>T : T +>U : U +>array1 : T[] +>T : T +>array2 : U[] +>U : U +>T : T +>U : U + + if (array1.length != array2.length) { +>array1.length != array2.length : boolean +>array1.length : number +>array1 : T[] +>length : number +>array2.length : number +>array2 : U[] +>length : number + + return [[undefined, undefined]]; +>[[undefined, undefined]] : [[undefined, undefined]] +>[undefined, undefined] : [undefined, undefined] +>undefined : undefined +>undefined : undefined + } + var length = array1.length; +>length : number +>array1.length : number +>array1 : T[] +>length : number + + var zipResult: [[T, U]]; +>zipResult : [[T, U]] +>T : T +>U : U + + for (var i = 0; i < length; ++i) { +>i : number +>i < length : boolean +>i : number +>length : number +>++i : number +>i : number + + zipResult.push([array1[i], array2[i]]); +>zipResult.push([array1[i], array2[i]]) : number +>zipResult.push : (...items: [T, U][]) => number +>zipResult : [[T, U]] +>push : (...items: [T, U][]) => number +>[array1[i], array2[i]] : [T, U] +>array1[i] : T +>array1 : T[] +>i : number +>array2[i] : U +>array2 : U[] +>i : number + } + return zipResult; +>zipResult : [[T, U]] +} + +var zipResult = zip(["foo", "bar"], [5, 6]); +>zipResult : [[string, number]] +>zip(["foo", "bar"], [5, 6]) : [[string, number]] +>zip : (array1: T[], array2: U[]) => [[T, U]] +>["foo", "bar"] : string[] +>[5, 6] : number[] + +var zipResultEle = zipResult[0]; // [string, number] +>zipResultEle : [string, number] +>zipResult[0] : [string, number] +>zipResult : [[string, number]] + +var zipResultEleEle = zipResult[0][0]; // string +>zipResultEleEle : string +>zipResult[0][0] : string +>zipResult[0] : [string, number] +>zipResult : [[string, number]] + + From 779db6e76a8b117e2b12a8b6b0df72fb73411b12 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 8 Oct 2014 23:21:56 -0700 Subject: [PATCH 10/23] Support find all refs on union properties --- src/compiler/checker.ts | 20 ++- src/compiler/types.ts | 2 +- src/services/services.ts | 134 +++++++++--------- ...ontextuallyTypedObjectLiteralProperties.ts | 18 +-- ...ncesForContextuallyTypedUnionProperties.ts | 40 ++++++ .../fourslash/referencesForUnionProperties.ts | 35 +++++ 6 files changed, 169 insertions(+), 80 deletions(-) create mode 100644 tests/cases/fourslash/referencesForContextuallyTypedUnionProperties.ts create mode 100644 tests/cases/fourslash/referencesForUnionProperties.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 523cd139248..7138cd9588a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -88,7 +88,7 @@ module ts { symbolToString: symbolToString, symbolToDisplayParts: symbolToDisplayParts, getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType, - getRootSymbol: getRootSymbol, + getRootSymbols: getRootSymbols, getContextualType: getContextualType, getFullyQualifiedName: getFullyQualifiedName, getResolvedSignature: getResolvedSignature, @@ -7863,8 +7863,22 @@ module ts { } } - function getRootSymbol(symbol: Symbol) { - return ((symbol.flags & SymbolFlags.Transient) && getSymbolLinks(symbol).target) || symbol; + function getRootSymbols(symbol: Symbol): Symbol[] { + if (symbol.flags & SymbolFlags.UnionProperty) { + var symbols: Symbol[] = []; + var name = symbol.name; + forEach(getSymbolLinks(symbol).unionType.types, t => { + symbols.push(getPropertyOfType(t, name)); + }); + return symbols; + } + else if (symbol.flags & SymbolFlags.Transient) { + var target = getSymbolLinks(symbol).target; + if (target) { + return [target]; + } + } + return [symbol]; } // Emitter support diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 0d943915e44..0aa25e2efeb 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -653,7 +653,7 @@ module ts { symbolToDisplayParts(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): SymbolDisplayPart[]; getFullyQualifiedName(symbol: Symbol): string; getAugmentedPropertiesOfApparentType(type: Type): Symbol[]; - getRootSymbol(symbol: Symbol): Symbol; + getRootSymbols(symbol: Symbol): Symbol[]; getContextualType(node: Node): Type; getResolvedSignature(node: CallExpression, candidatesOutArray?: Signature[]): Signature; diff --git a/src/services/services.ts b/src/services/services.ts index 3fc2ae7f05a..68c402b51ce 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2284,16 +2284,8 @@ module ts { } } - function getConcreteSymbol(symbol: Symbol): Symbol { - if (symbol.flags & SymbolFlags.UnionProperty) { - var types = typeInfoResolver.getUnionTypesOfUnionProperty(symbol); - symbol = typeInfoResolver.getPropertyOfType(types[0], symbol.name); - } - return typeInfoResolver.getRootSymbol(symbol); - } - function getSymbolKind(symbol: Symbol): string { - var flags = getConcreteSymbol(symbol).getFlags(); + var flags = typeInfoResolver.getRootSymbols(symbol)[0].getFlags(); if (flags & SymbolFlags.Module) return ScriptElementKind.moduleElement; if (flags & SymbolFlags.Class) return ScriptElementKind.classElement; @@ -2352,7 +2344,7 @@ module ts { } function getSymbolModifiers(symbol: Symbol): string { - symbol = getConcreteSymbol(symbol); + symbol = typeInfoResolver.getRootSymbols(symbol)[0]; return symbol && symbol.declarations && symbol.declarations.length > 0 ? getNodeModifiers(symbol.declarations[0]) : ScriptElementKindModifier.none; @@ -3016,18 +3008,28 @@ module ts { return [getReferenceEntryFromNode(node)]; } + var declarations = symbol.getDeclarations(); + + // Handel union properties + if (symbol.flags & SymbolFlags.UnionProperty) { + declarations = []; + forEach(typeInfoResolver.getUnionTypesOfUnionProperty(symbol), t => { + declarations.push.apply(declarations, t.getProperty(symbol.name).declarations); + }); + } + // the symbol was an internal symbol and does not have a declaration e.g.undefined symbol - if (!symbol.getDeclarations()) { + if (!declarations || !declarations.length) { return undefined; } var result: ReferenceEntry[]; // Compute the meaning from the location and the symbol it references - var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), symbol.getDeclarations()); + var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations); // Get the text to search for, we need to normalize it as external module names will have quote - var symbolName = getNormalizedSymbolName(symbol); + var symbolName = getNormalizedSymbolName(symbol.name, declarations); // Get syntactic diagnostics var scope = getSymbolScope(symbol); @@ -3049,15 +3051,15 @@ module ts { return result; - function getNormalizedSymbolName(symbol: Symbol): string { + function getNormalizedSymbolName(symbolName: string, declarations: Declaration[]): string { // Special case for function expressions, whose names are solely local to their bodies. - var functionExpression = getDeclarationOfKind(symbol, SyntaxKind.FunctionExpression); + var functionExpression = forEach(declarations, d => d.kind === SyntaxKind.FunctionExpression ? d : undefined); if (functionExpression && functionExpression.name) { var name = functionExpression.name.text; } else { - var name = symbol.name; + var name = symbolName; } var length = name.length; @@ -3084,22 +3086,24 @@ module ts { var scope: Node = undefined; var declarations = symbol.getDeclarations(); - for (var i = 0, n = declarations.length; i < n; i++) { - var container = getContainerNode(declarations[i]); + if (declarations) { + for (var i = 0, n = declarations.length; i < n; i++) { + var container = getContainerNode(declarations[i]); - if (scope && scope !== container) { - // Different declarations have different containers, bail out - return undefined; + if (scope && scope !== container) { + // Different declarations have different containers, bail out + return undefined; + } + + if (container.kind === SyntaxKind.SourceFile && !isExternalModule(container)) { + // This is a global variable and not an external module, any declaration defined + // within this scope is visible outside the file + return undefined; + } + + // The search scope is the container node + scope = container; } - - if (container.kind === SyntaxKind.SourceFile && !isExternalModule(container)) { - // This is a global variable and not an external module, any declaration defined - // within this scope is visible outside the file - return undefined; - } - - // The search scope is the container node - scope = container; } return scope; @@ -3216,14 +3220,7 @@ module ts { } var referenceSymbol = typeInfoResolver.getSymbolInfo(referenceLocation); - - // Could not find a symbol e.g. node is string or number keyword, - // or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol - if (!referenceSymbol || !(referenceSymbol.getDeclarations())) { - return; - } - - if (isRelatableToSearchSet(searchSymbols, referenceSymbol, referenceLocation)) { + if (referenceSymbol && isRelatableToSearchSet(searchSymbols, referenceSymbol, referenceLocation)) { result.push(getReferenceEntryFromNode(referenceLocation)); } }); @@ -3359,24 +3356,26 @@ module ts { // The search set contains at least the current symbol var result = [symbol]; - // If the symbol is an instantiation from a another symbol (e.g. widened symbol) , add the root the list - var rootSymbol = typeInfoResolver.getRootSymbol(symbol); - if (rootSymbol && rootSymbol !== symbol) { - result.push(rootSymbol); - } - // If the location is in a context sensitive location (i.e. in an object literal) try // to get a contextual type for it, and add the property symbol from the contextual // type to the search set if (isNameOfPropertyAssignment(location)) { var symbolFromContextualType = getPropertySymbolFromContextualType(location); - if (symbolFromContextualType) result.push(typeInfoResolver.getRootSymbol(symbolFromContextualType)); + if (symbolFromContextualType) result.push.apply(result, typeInfoResolver.getRootSymbols(symbolFromContextualType)); } - // Add symbol of properties/methods of the same name in base classes and implemented interfaces definitions - if (symbol.parent && symbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { - getPropertySymbolsFromBaseTypes(symbol.parent, symbol.getName(), result); - } + // If this is a union property, add all the symbols from all its source symbols in all unioned types. + // If the symbol is an instantiation from a another symbol (e.g. widened symbol) , add the root the list + forEach(typeInfoResolver.getRootSymbols(symbol), rootSymbol => { + if (rootSymbol !== symbol) { + result.push(rootSymbol); + } + + // Add symbol of properties/methods of the same name in base classes and implemented interfaces definitions + if (rootSymbol.parent && rootSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { + getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result); + } + }); return result; } @@ -3411,33 +3410,34 @@ module ts { } function isRelatableToSearchSet(searchSymbols: Symbol[], referenceSymbol: Symbol, referenceLocation: Node): boolean { - // Unwrap symbols to get to the root (e.g. transient symbols as a result of widening) - var referenceSymbolTarget = typeInfoResolver.getRootSymbol(referenceSymbol); - - // if it is in the list, then we are done - if (searchSymbols.indexOf(referenceSymbolTarget) >= 0) { - return true; - } - // If the reference location is in an object literal, try to get the contextual type for the // object literal, lookup the property symbol in the contextual type, and use this symbol to // compare to our searchSymbol if (isNameOfPropertyAssignment(referenceLocation)) { var symbolFromContextualType = getPropertySymbolFromContextualType(referenceLocation); - if (symbolFromContextualType && searchSymbols.indexOf(typeInfoResolver.getRootSymbol(symbolFromContextualType)) >= 0) { - return true; + if (symbolFromContextualType) { + return forEach(typeInfoResolver.getRootSymbols(symbolFromContextualType), s => searchSymbols.indexOf(s) >= 0); } } - // Finally, try all properties with the same name in any type the containing type extend or implemented, and - // see if any is in the list - if (referenceSymbol.parent && referenceSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { - var result: Symbol[] = []; - getPropertySymbolsFromBaseTypes(referenceSymbol.parent, referenceSymbol.getName(), result); - return forEach(result, s => searchSymbols.indexOf(s) >= 0); - } + // Unwrap symbols to get to the root (e.g. transient symbols as a result of widening) + // Or a union property, use its underlying unioned symbols + return forEach(typeInfoResolver.getRootSymbols(referenceSymbol), rootSymbol => { + // if it is in the list, then we are done + if (searchSymbols.indexOf(rootSymbol) >= 0) { + return true; + } - return false; + // Finally, try all properties with the same name in any type the containing type extended or implemented, and + // see if any is in the list + if (rootSymbol.parent && rootSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { + var result: Symbol[] = []; + getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result); + return forEach(result, s => searchSymbols.indexOf(s) >= 0); + } + + return false; + }); } function getPropertySymbolFromContextualType(node: Node): Symbol { diff --git a/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts b/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts index f21f6cc3936..15dd5720019 100644 --- a/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts +++ b/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts @@ -1,5 +1,5 @@ -/// - +/// + ////interface IFoo { /*1*/xy: number; } //// ////// Assignment @@ -23,10 +23,10 @@ ////var w: IFoo = { /*4*/xy: undefined }; //// ////// Untped -- should not be included -////var u = { xy: 0 }; - - -test.markers().forEach((m) => { - goTo.position(m.position, m.fileName); - verify.referencesCountIs(9); -}); +////var u = { xy: 0 }; + + +test.markers().forEach((m) => { + goTo.position(m.position, m.fileName); + verify.referencesCountIs(9); +}); diff --git a/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties.ts b/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties.ts new file mode 100644 index 00000000000..f9c479de769 --- /dev/null +++ b/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties.ts @@ -0,0 +1,40 @@ +/// + +////interface A { +//// a: number; +//// common: string; +////} +//// +////interface B { +//// b: number; +//// common: number; +////} +//// +////// Assignment +////var v1: A | B = { a: 0, /*1*/common: "" }; +////var v2: A | B = { b: 0, /*2*/common: 3 }; +//// +////// Function call +////function consumer(f: A | B) { } +////consumer({ a: 0, b: 0, /*3*/common: 1 }); +//// +////// Type cast +////var c = { /*4*/common: 0, b: 0 }; +//// +////// Array literal +////var ar: Array = [{ a: 0, /*5*/common: "" }, { b: 0, /*6*/common: 0 }]; +//// +////// Nested object literal +////var ob: { aorb: A|B } = { aorb: { b: 0, /*7*/common: 0 } }; +//// +////// Widened type +////var w: A|B = { a:0, /*8*/common: undefined }; +//// +////// Untped -- should not be included +////var u1 = { a: 0, b: 0, common: "" }; +////var u2 = { b: 0, common: 0 }; + +test.markers().forEach((m) => { + goTo.position(m.position, m.fileName); + verify.referencesCountIs(10); // 8 contextually typed common, and 2 in definition (A.common, B.common) +}); diff --git a/tests/cases/fourslash/referencesForUnionProperties.ts b/tests/cases/fourslash/referencesForUnionProperties.ts new file mode 100644 index 00000000000..f4ef85e8e4e --- /dev/null +++ b/tests/cases/fourslash/referencesForUnionProperties.ts @@ -0,0 +1,35 @@ +/// + +////interface One { +//// common: { /*1*/a: number; }; +////} +//// +////interface Base { +//// /*2*/a: string; +//// b: string; +////} +//// +////interface HasAOrB extends Base { +//// /*3*/a: string; +//// b: string; +////} +//// +////interface Two { +//// common: HasAOrB; +////} +//// +////var x : One | Two; +//// +////x.common./*4*/a; + +goTo.marker("1"); +verify.referencesCountIs(2); // One.common.a, x.common.a + +goTo.marker("2"); +verify.referencesCountIs(3); // Base.a, HasAOrB.a, x.common.a + +goTo.marker("3"); +verify.referencesCountIs(3); // Base.a, HasAOrB.a, x.common.a + +goTo.marker("4"); +verify.referencesCountIs(4); // One.common.a, Base.a, HasAOrB.a, x.common.a \ No newline at end of file From 2eb51ab874ac576e7b10d3ec7c09b074e793620d Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 8 Oct 2014 23:28:17 -0700 Subject: [PATCH 11/23] Use getRootSymbols for all union property needs --- src/compiler/checker.ts | 5 ----- src/compiler/types.ts | 2 -- src/services/services.ts | 8 ++++---- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7138cd9588a..808f7e3b849 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -93,7 +93,6 @@ module ts { getFullyQualifiedName: getFullyQualifiedName, getResolvedSignature: getResolvedSignature, getEnumMemberValue: getEnumMemberValue, - getUnionTypesOfUnionProperty: getUnionTypesOfUnionProperty }; var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined"); @@ -1751,10 +1750,6 @@ module ts { return links.type; } - function getUnionTypesOfUnionProperty(symbol: Symbol): Type[] { - return (symbol.flags & SymbolFlags.UnionProperty) ? getSymbolLinks(symbol).unionType.types : undefined; - } - function getTypeOfSymbol(symbol: Symbol): Type { if (symbol.flags & (SymbolFlags.Variable | SymbolFlags.Property)) { return getTypeOfVariableOrParameterOrProperty(symbol); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 0aa25e2efeb..e314466cf8c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -657,8 +657,6 @@ module ts { getContextualType(node: Node): Type; getResolvedSignature(node: CallExpression, candidatesOutArray?: Signature[]): Signature; - getUnionTypesOfUnionProperty(symbol: Symbol): Type[]; - // Returns the constant value of this enum member, or 'undefined' if the enum member has a // computed value. getEnumMemberValue(node: EnumMember): number; diff --git a/src/services/services.ts b/src/services/services.ts index 68c402b51ce..8ae8ef36f36 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2619,8 +2619,8 @@ module ts { var result: DefinitionInfo[] = []; if (symbol.flags & SymbolFlags.UnionProperty) { - forEach(typeInfoResolver.getUnionTypesOfUnionProperty(symbol), t => { - getDefinitionFromSymbol(typeInfoResolver.getPropertyOfType(t, symbol.name), node, result); + forEach(typeInfoResolver.getRootSymbols(symbol), s => { + getDefinitionFromSymbol(s, node, result); }); } else { @@ -3013,8 +3013,8 @@ module ts { // Handel union properties if (symbol.flags & SymbolFlags.UnionProperty) { declarations = []; - forEach(typeInfoResolver.getUnionTypesOfUnionProperty(symbol), t => { - declarations.push.apply(declarations, t.getProperty(symbol.name).declarations); + forEach(typeInfoResolver.getRootSymbols(symbol), s => { + declarations.push.apply(declarations, s.declarations); }); } From 927f04f64fccfe01835173bf64ebc72389e1a50c Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 9 Oct 2014 11:16:04 -0700 Subject: [PATCH 12/23] Fix contextually typed object literal proeprties that are not properties of the union type but are properties on of one of its constituant types --- src/services/services.ts | 44 ++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index f7e38019997..4d192059815 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3562,8 +3562,9 @@ module ts { // to get a contextual type for it, and add the property symbol from the contextual // type to the search set if (isNameOfPropertyAssignment(location)) { - var symbolFromContextualType = getPropertySymbolFromContextualType(location); - if (symbolFromContextualType) result.push.apply(result, typeInfoResolver.getRootSymbols(symbolFromContextualType)); + forEach(getPropertySymbolsFromContextualType(location), contextualSymbol => { + result.push.apply(result, typeInfoResolver.getRootSymbols(contextualSymbol)); + }); } // If this is a union property, add all the symbols from all its source symbols in all unioned types. @@ -3613,14 +3614,17 @@ module ts { } function isRelatableToSearchSet(searchSymbols: Symbol[], referenceSymbol: Symbol, referenceLocation: Node): boolean { + if (searchSymbols.indexOf(referenceSymbol) >= 0) { + return true; + } + // If the reference location is in an object literal, try to get the contextual type for the // object literal, lookup the property symbol in the contextual type, and use this symbol to // compare to our searchSymbol if (isNameOfPropertyAssignment(referenceLocation)) { - var symbolFromContextualType = getPropertySymbolFromContextualType(referenceLocation); - if (symbolFromContextualType) { - return forEach(typeInfoResolver.getRootSymbols(symbolFromContextualType), s => searchSymbols.indexOf(s) >= 0); - } + return forEach(getPropertySymbolsFromContextualType(referenceLocation), contextualSymbol => { + return forEach(typeInfoResolver.getRootSymbols(contextualSymbol), s => searchSymbols.indexOf(s) >= 0); + }); } // Unwrap symbols to get to the root (e.g. transient symbols as a result of widening) @@ -3643,12 +3647,36 @@ module ts { }); } - function getPropertySymbolFromContextualType(node: Node): Symbol { + function getPropertySymbolsFromContextualType(node: Node): Symbol[] { if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeInfoResolver.getContextualType(objectLiteral); + var name = (node).text; if (contextualType) { - return typeInfoResolver.getPropertyOfType(contextualType, (node).text); + if (contextualType.flags & TypeFlags.Union) { + // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) + // if not, search the constituent types for the property + var unionProperty = contextualType.getProperty(name) + if (unionProperty) { + return [unionProperty]; + } + else { + var result: Symbol[] = []; + forEach((contextualType).types, t => { + var symbol = t.getProperty(name); + if (symbol) { + result.push(symbol); + } + }); + return result; + } + } + else { + var symbol = contextualType.getProperty(name); + if (symbol) { + return [symbol]; + } + } } } return undefined; From 9f43ac02deb84e73b9deca092157c53feafe408a Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 10 Oct 2014 10:59:30 -0700 Subject: [PATCH 13/23] respond to code review remarks --- src/services/services.ts | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 4d192059815..b6bea438c5a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2522,7 +2522,7 @@ module ts { } /// Goto definition - function getDefinitionAtPosition(filename: string, position: number): DefinitionInfo[]{ + function getDefinitionAtPosition(filename: string, position: number): DefinitionInfo[] { function getDefinitionInfo(node: Node, symbolKind: string, symbolName: string, containerName: string): DefinitionInfo { return { fileName: node.getSourceFile().filename, @@ -2554,7 +2554,7 @@ module ts { result.push(getDefinitionInfo(declarations[declarations.length - 1], symbolKind, symbolName, containerName)); return true; } - + return false; } @@ -2643,14 +2643,11 @@ module ts { var result: DefinitionInfo[] = []; - if (symbol.flags & SymbolFlags.UnionProperty) { - forEach(typeInfoResolver.getRootSymbols(symbol), s => { - getDefinitionFromSymbol(s, node, result); - }); - } - else { - getDefinitionFromSymbol(symbol, node, result); - } + // The symbol could be a unionProperty, we need to ensure we are collecting all + // declarations, so use getRootSymbol first. + forEach(typeInfoResolver.getRootSymbols(symbol), s => { + getDefinitionFromSymbol(s, node, result); + }); return result; } @@ -3167,15 +3164,13 @@ module ts { var declarations = symbol.getDeclarations(); - // Handel union properties - if (symbol.flags & SymbolFlags.UnionProperty) { - declarations = []; - forEach(typeInfoResolver.getRootSymbols(symbol), s => { - declarations.push.apply(declarations, s.declarations); - }); - } + // Handle union properties + declarations = []; + forEach(typeInfoResolver.getRootSymbols(symbol), s => { + declarations.push.apply(declarations, s.declarations); + }); - // the symbol was an internal symbol and does not have a declaration e.g.undefined symbol + // The symbol was an internal symbol and does not have a declaration e.g.undefined symbol if (!declarations || !declarations.length) { return undefined; } From bacb9d0b227c7fe4909ead8e6a881ab2ca84efe7 Mon Sep 17 00:00:00 2001 From: Dan Quirk Date: Fri, 10 Oct 2014 14:41:14 -0700 Subject: [PATCH 14/23] Test updates from union changes --- .../reference/arrayBestCommonTypes.js | 312 ++++++++---- .../reference/arrayBestCommonTypes.types | 481 +++++++++++++++--- .../arrayLiteralContextualType.errors.txt | 40 -- .../reference/arrayLiteralContextualType.js | 8 +- .../arrayLiteralContextualType.types | 86 ++++ ...ayLiteralWithMultipleBestCommonTypes.types | 4 +- tests/baselines/reference/arrayLiterals.js | 16 - tests/baselines/reference/arrayLiterals.types | 38 +- .../arrayLiteralsWithRecursiveGenerics.types | 4 +- ...stCommonTypeOfConditionalExpressions.types | 4 +- ...onTypeOfConditionalExpressions2.errors.txt | 17 +- .../conditionalExpression1.errors.txt | 11 +- ...onalOperatorWithoutIdenticalBCT.errors.txt | 72 ++- .../conditionalOperatorWithoutIdenticalBCT.js | 10 +- .../reference/contextualTyping21.errors.txt | 14 +- .../reference/contextualTyping30.errors.txt | 10 +- .../reference/contextualTyping33.errors.txt | 10 +- ...ontextualTypingOfArrayLiterals1.errors.txt | 14 +- ...lTypingOfConditionalExpression2.errors.txt | 17 +- ...lTypingWithFixedTypeParameters1.errors.txt | 9 +- ...ontextualTypingWithFixedTypeParameters1.js | 8 +- .../contextuallyTypingOrOperator.types | 18 +- .../contextuallyTypingOrOperator2.types | 6 +- ...defaultBestCommonTypesHaveDecls.errors.txt | 24 +- .../defaultBestCommonTypesHaveDecls.js | 23 +- tests/baselines/reference/enumBasics.types | 8 +- ...erInSignatureWithRestParameters.errors.txt | 8 + ...rameterInSignatureWithRestParameters.types | 13 - ...orStatementsMultipleInvalidDecl.errors.txt | 4 +- .../reference/generatedContextualTyping.types | 242 ++++----- ...nericArgumentCallSigAssignmentCompat.types | 2 +- .../genericCallWithArrayLiteralArgs.types | 6 +- ...cCallWithFunctionTypedArguments.errors.txt | 58 +++ .../genericCallWithFunctionTypedArguments.js | 20 +- ...enericCallWithFunctionTypedArguments.types | 173 ------- ...CallWithFunctionTypedArguments2.errors.txt | 50 ++ .../genericCallWithFunctionTypedArguments2.js | 8 +- ...nericCallWithFunctionTypedArguments2.types | 161 ------ ...lWithGenericSignatureArguments2.errors.txt | 125 +++-- ...nericCallWithGenericSignatureArguments2.js | 188 ++++--- ...lWithGenericSignatureArguments3.errors.txt | 42 ++ ...nericCallWithGenericSignatureArguments3.js | 8 +- ...icCallWithGenericSignatureArguments3.types | 202 -------- ...enericCallWithObjectLiteralArgs.errors.txt | 14 + .../genericCallWithObjectLiteralArgs.js | 4 +- .../genericCallWithObjectLiteralArgs.types | 49 -- ...CallWithObjectLiteralArguments1.errors.txt | 5 +- .../genericCallWithObjectTypeArgs.errors.txt | 27 + .../genericCallWithObjectTypeArgs.types | 68 --- .../genericCallWithObjectTypeArgs2.types | 16 +- ...thObjectTypeArgsAndConstraints3.errors.txt | 5 +- ...loadedConstructorTypedArguments.errors.txt | 54 ++ ...WithOverloadedConstructorTypedArguments.js | 4 +- ...hOverloadedConstructorTypedArguments.types | 173 ------- ...ithFunctionTypedMemberArguments.errors.txt | 81 +++ ...icClassWithFunctionTypedMemberArguments.js | 16 +- ...lassWithFunctionTypedMemberArguments.types | 297 ----------- .../reference/genericRestArgs.errors.txt | 8 +- .../genericTypeArgumentInference1.types | 6 +- .../genericsManyTypeParameters.types | 4 +- .../heterogeneousArrayAndOverloads.errors.txt | 10 +- .../heterogeneousArrayLiterals.types | 100 ++-- ...lidMultipleVariableDeclarations.errors.txt | 4 +- .../logicalOrOperatorWithEveryType.types | 160 +++--- .../logicalOrOperatorWithTypeParameters.types | 16 +- ...citTypeParameterAndArgumentType.errors.txt | 10 +- .../nonContextuallyTypedLogicalOr.errors.txt | 22 - .../nonContextuallyTypedLogicalOr.js | 4 - .../nonContextuallyTypedLogicalOr.types | 37 ++ ...rConstrainsPropertyDeclarations.errors.txt | 10 +- ...ConstrainsPropertyDeclarations2.errors.txt | 12 +- .../reference/parser15.4.4.14-9-2.errors.txt | 5 +- .../reference/promisePermutations.errors.txt | 42 +- .../reference/promisePermutations.js | 28 +- .../reference/promisePermutations2.errors.txt | 31 +- .../reference/promisePermutations2.js | 24 +- .../reference/promisePermutations3.errors.txt | 39 +- .../reference/promisePermutations3.js | 28 +- ...rConstrainsPropertyDeclarations.errors.txt | 10 +- .../subtypesOfTypeParameter.errors.txt | 110 +--- ...OfTypeParameterWithConstraints2.errors.txt | 98 +--- ...subtypesOfTypeParameterWithConstraints2.js | 48 +- ...OfTypeParameterWithConstraints3.errors.txt | 24 +- ...subtypesOfTypeParameterWithConstraints3.js | 8 +- ...OfTypeParameterWithConstraints4.errors.txt | 34 +- ...subtypesOfTypeParameterWithConstraints4.js | 16 +- ...rameterWithRecursiveConstraints.errors.txt | 98 +--- ...OfTypeParameterWithRecursiveConstraints.js | 48 +- .../subtypingWithCallSignatures2.types | 12 +- .../subtypingWithCallSignatures3.types | 12 +- .../subtypingWithCallSignatures4.types | 16 +- .../subtypingWithConstructSignatures2.types | 20 +- .../subtypingWithConstructSignatures3.types | 12 +- .../subtypingWithConstructSignatures4.types | 16 +- ...ngWithObjectMembersOptionality2.errors.txt | 7 +- .../subtypingWithObjectMembersOptionality2.js | 4 +- .../reference/targetTypeTest3.errors.txt | 10 +- .../baselines/reference/throwStatements.types | 2 +- ...ommaInHeterogenousArrayLiteral1.errors.txt | 20 +- .../baselines/reference/tupleTypes.errors.txt | 30 +- .../reference/typeArgInference2.errors.txt | 18 + .../baselines/reference/typeArgInference2.js | 4 +- .../reference/typeArgInference2.types | 61 --- .../typeArgInference2WithError.errors.txt | 6 +- .../typeArgumentInference.errors.txt | 109 ++++ .../reference/typeArgumentInference.types | 468 ----------------- ...entInferenceConstructSignatures.errors.txt | 8 +- ...tInferenceTransitiveConstraints.errors.txt | 5 +- ...renceWithConstraintAsCommonRoot.errors.txt | 13 + ...tInferenceWithConstraintAsCommonRoot.types | 40 -- ...rgumentInferenceWithConstraints.errors.txt | 8 +- ...eInferenceConflictingCandidates.errors.txt | 9 + .../typeInferenceConflictingCandidates.types | 21 - .../typeParameterAsElementType.types | 4 +- .../baselines/reference/underscoreTest1.types | 12 +- tests/cases/compiler/arrayBestCommonTypes.ts | 138 +++-- .../compiler/arrayLiteralContextualType.ts | 4 +- ...ontextualTypingWithFixedTypeParameters1.ts | 4 +- .../defaultBestCommonTypesHaveDecls.ts | 14 +- .../compiler/nonContextuallyTypedLogicalOr.ts | 2 - tests/cases/compiler/promisePermutations.ts | 16 +- tests/cases/compiler/promisePermutations2.ts | 14 +- tests/cases/compiler/promisePermutations3.ts | 16 +- tests/cases/compiler/tupleTypes.ts | 8 +- tests/cases/compiler/typeArgInference2.ts | 24 +- .../arrayLiterals/arrayLiterals.ts | 8 - .../conditionalOperatorWithoutIdenticalBCT.ts | 39 +- ...subtypesOfTypeParameterWithConstraints2.ts | 24 +- ...subtypesOfTypeParameterWithConstraints3.ts | 4 +- ...subtypesOfTypeParameterWithConstraints4.ts | 8 +- ...OfTypeParameterWithRecursiveConstraints.ts | 24 +- .../subtypingWithObjectMembersOptionality2.ts | 2 +- .../genericCallWithFunctionTypedArguments.ts | 10 +- .../genericCallWithFunctionTypedArguments2.ts | 4 +- ...nericCallWithGenericSignatureArguments2.ts | 87 +++- ...nericCallWithGenericSignatureArguments3.ts | 4 +- .../genericCallWithObjectLiteralArgs.ts | 2 +- ...WithOverloadedConstructorTypedArguments.ts | 2 +- ...icClassWithFunctionTypedMemberArguments.ts | 8 +- 139 files changed, 2558 insertions(+), 3336 deletions(-) delete mode 100644 tests/baselines/reference/arrayLiteralContextualType.errors.txt create mode 100644 tests/baselines/reference/arrayLiteralContextualType.types create mode 100644 tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.errors.txt delete mode 100644 tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.types create mode 100644 tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt delete mode 100644 tests/baselines/reference/genericCallWithFunctionTypedArguments.types create mode 100644 tests/baselines/reference/genericCallWithFunctionTypedArguments2.errors.txt delete mode 100644 tests/baselines/reference/genericCallWithFunctionTypedArguments2.types create mode 100644 tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt delete mode 100644 tests/baselines/reference/genericCallWithGenericSignatureArguments3.types create mode 100644 tests/baselines/reference/genericCallWithObjectLiteralArgs.errors.txt delete mode 100644 tests/baselines/reference/genericCallWithObjectLiteralArgs.types create mode 100644 tests/baselines/reference/genericCallWithObjectTypeArgs.errors.txt delete mode 100644 tests/baselines/reference/genericCallWithObjectTypeArgs.types create mode 100644 tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.errors.txt delete mode 100644 tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.types create mode 100644 tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.errors.txt delete mode 100644 tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.types delete mode 100644 tests/baselines/reference/nonContextuallyTypedLogicalOr.errors.txt create mode 100644 tests/baselines/reference/nonContextuallyTypedLogicalOr.types create mode 100644 tests/baselines/reference/typeArgInference2.errors.txt delete mode 100644 tests/baselines/reference/typeArgInference2.types create mode 100644 tests/baselines/reference/typeArgumentInference.errors.txt delete mode 100644 tests/baselines/reference/typeArgumentInference.types create mode 100644 tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.errors.txt delete mode 100644 tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.types create mode 100644 tests/baselines/reference/typeInferenceConflictingCandidates.errors.txt delete mode 100644 tests/baselines/reference/typeInferenceConflictingCandidates.types diff --git a/tests/baselines/reference/arrayBestCommonTypes.js b/tests/baselines/reference/arrayBestCommonTypes.js index 675d84119c0..f8e158e5b02 100644 --- a/tests/baselines/reference/arrayBestCommonTypes.js +++ b/tests/baselines/reference/arrayBestCommonTypes.js @@ -1,55 +1,109 @@ //// [arrayBestCommonTypes.ts] -interface iface { } -class base implements iface { } -class base2 implements iface { } -class derived extends base { } +module EmptyTypes { + interface iface { } + class base implements iface { } + class base2 implements iface { } + class derived extends base { } -class f { - public voidIfAny(x: boolean, y?: boolean): number; - public voidIfAny(x: string, y?: boolean): number; - public voidIfAny(x: number, y?: boolean): number; - public voidIfAny(x: any, y =false): any { return null; } - - public x() { - (this.voidIfAny([4, 2][0])); - (this.voidIfAny([4, 2, undefined][0])); - (this.voidIfAny([undefined, 2, 4][0])); - (this.voidIfAny([null, 2, 4][0])); - (this.voidIfAny([2, 4, null][0])); - (this.voidIfAny([undefined, 4, null][0])); + class f { + public voidIfAny(x: boolean, y?: boolean): number; + public voidIfAny(x: string, y?: boolean): number; + public voidIfAny(x: number, y?: boolean): number; + public voidIfAny(x: any, y = false): any { return null; } - (this.voidIfAny(['', "q"][0])); - (this.voidIfAny(['', "q", undefined][0])); - (this.voidIfAny([undefined, "q", ''][0])); - (this.voidIfAny([null, "q", ''][0])); - (this.voidIfAny(["q", '', null][0])); - (this.voidIfAny([undefined, '', null][0])); + public x() { + (this.voidIfAny([4, 2][0])); + (this.voidIfAny([4, 2, undefined][0])); + (this.voidIfAny([undefined, 2, 4][0])); + (this.voidIfAny([null, 2, 4][0])); + (this.voidIfAny([2, 4, null][0])); + (this.voidIfAny([undefined, 4, null][0])); - (this.voidIfAny([[3,4],[null]][0][0])); - - - var t1: { x: number; y: base; }[] = [ { x: 7, y: new derived() }, { x: 5, y: new base() } ]; - var t2: { x: boolean; y: base; }[] = [ { x: true, y: new derived() }, { x: false, y: new base() } ]; - var t3: { x: string; y: base; }[] = [ { x: undefined, y: new base() }, { x: '', y: new derived() } ]; + (this.voidIfAny(['', "q"][0])); + (this.voidIfAny(['', "q", undefined][0])); + (this.voidIfAny([undefined, "q", ''][0])); + (this.voidIfAny([null, "q", ''][0])); + (this.voidIfAny(["q", '', null][0])); + (this.voidIfAny([undefined, '', null][0])); - var anyObj: any = null; - // Order matters here so test all the variants - var a1 = [ {x: 0, y: 'a'}, {x: 'a', y: 'a'}, {x: anyObj, y: 'a'} ]; - var a2 = [ {x: anyObj, y: 'a'}, {x: 0, y: 'a'}, {x: 'a', y: 'a'} ]; - var a3 = [ {x: 0, y: 'a'}, {x: anyObj, y: 'a'}, {x: 'a', y: 'a'} ]; - - var ifaceObj: iface = null; - var baseObj = new base(); - var base2Obj = new base2(); + (this.voidIfAny([[3, 4], [null]][0][0])); - var b1 = [ baseObj, base2Obj, ifaceObj ]; - var b2 = [ base2Obj, baseObj, ifaceObj ]; - var b3 = [ baseObj, ifaceObj, base2Obj ]; - var b4 = [ ifaceObj, baseObj, base2Obj ]; + + var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; + var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }]; + var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; + + var anyObj: any = null; + // Order matters here so test all the variants + var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; + var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; + var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; + + var ifaceObj: iface = null; + var baseObj = new base(); + var base2Obj = new base2(); + + var b1 = [baseObj, base2Obj, ifaceObj]; + var b2 = [base2Obj, baseObj, ifaceObj]; + var b3 = [baseObj, ifaceObj, base2Obj]; + var b4 = [ifaceObj, baseObj, base2Obj]; + } } } +module NonEmptyTypes { + interface iface { x: string; } + class base implements iface { x: string; y: string; } + class base2 implements iface { x: string; z: string; } + class derived extends base { a: string; } + + + class f { + public voidIfAny(x: boolean, y?: boolean): number; + public voidIfAny(x: string, y?: boolean): number; + public voidIfAny(x: number, y?: boolean): number; + public voidIfAny(x: any, y = false): any { return null; } + + public x() { + (this.voidIfAny([4, 2][0])); + (this.voidIfAny([4, 2, undefined][0])); + (this.voidIfAny([undefined, 2, 4][0])); + (this.voidIfAny([null, 2, 4][0])); + (this.voidIfAny([2, 4, null][0])); + (this.voidIfAny([undefined, 4, null][0])); + + (this.voidIfAny(['', "q"][0])); + (this.voidIfAny(['', "q", undefined][0])); + (this.voidIfAny([undefined, "q", ''][0])); + (this.voidIfAny([null, "q", ''][0])); + (this.voidIfAny(["q", '', null][0])); + (this.voidIfAny([undefined, '', null][0])); + + (this.voidIfAny([[3, 4], [null]][0][0])); + + + var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; + var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }]; + var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; + + var anyObj: any = null; + // Order matters here so test all the variants + var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; + var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; + var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; + + var ifaceObj: iface = null; + var baseObj = new base(); + var base2Obj = new base2(); + + var b1 = [baseObj, base2Obj, ifaceObj]; + var b2 = [base2Obj, baseObj, ifaceObj]; + var b3 = [baseObj, ifaceObj, base2Obj]; + var b4 = [ifaceObj, baseObj, base2Obj]; + } + } +} @@ -60,59 +114,121 @@ var __extends = this.__extends || function (d, b) { __.prototype = b.prototype; d.prototype = new __(); }; -var base = (function () { - function base() { - } - return base; -})(); -var base2 = (function () { - function base2() { - } - return base2; -})(); -var derived = (function (_super) { - __extends(derived, _super); - function derived() { - _super.apply(this, arguments); - } - return derived; -})(base); -var f = (function () { - function f() { - } - f.prototype.voidIfAny = function (x, y) { - if (y === void 0) { y = false; } - return null; - }; - f.prototype.x = function () { - (this.voidIfAny([4, 2][0])); - (this.voidIfAny([4, 2, undefined][0])); - (this.voidIfAny([undefined, 2, 4][0])); - (this.voidIfAny([null, 2, 4][0])); - (this.voidIfAny([2, 4, null][0])); - (this.voidIfAny([undefined, 4, null][0])); - (this.voidIfAny(['', "q"][0])); - (this.voidIfAny(['', "q", undefined][0])); - (this.voidIfAny([undefined, "q", ''][0])); - (this.voidIfAny([null, "q", ''][0])); - (this.voidIfAny(["q", '', null][0])); - (this.voidIfAny([undefined, '', null][0])); - (this.voidIfAny([[3, 4], [null]][0][0])); - var t1 = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; - var t2 = [{ x: true, y: new derived() }, { x: false, y: new base() }]; - var t3 = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; - var anyObj = null; - // Order matters here so test all the variants - var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; - var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; - var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; - var ifaceObj = null; - var baseObj = new base(); - var base2Obj = new base2(); - var b1 = [baseObj, base2Obj, ifaceObj]; - var b2 = [base2Obj, baseObj, ifaceObj]; - var b3 = [baseObj, ifaceObj, base2Obj]; - var b4 = [ifaceObj, baseObj, base2Obj]; - }; - return f; -})(); +var EmptyTypes; +(function (EmptyTypes) { + var base = (function () { + function base() { + } + return base; + })(); + var base2 = (function () { + function base2() { + } + return base2; + })(); + var derived = (function (_super) { + __extends(derived, _super); + function derived() { + _super.apply(this, arguments); + } + return derived; + })(base); + var f = (function () { + function f() { + } + f.prototype.voidIfAny = function (x, y) { + if (y === void 0) { y = false; } + return null; + }; + f.prototype.x = function () { + (this.voidIfAny([4, 2][0])); + (this.voidIfAny([4, 2, undefined][0])); + (this.voidIfAny([undefined, 2, 4][0])); + (this.voidIfAny([null, 2, 4][0])); + (this.voidIfAny([2, 4, null][0])); + (this.voidIfAny([undefined, 4, null][0])); + (this.voidIfAny(['', "q"][0])); + (this.voidIfAny(['', "q", undefined][0])); + (this.voidIfAny([undefined, "q", ''][0])); + (this.voidIfAny([null, "q", ''][0])); + (this.voidIfAny(["q", '', null][0])); + (this.voidIfAny([undefined, '', null][0])); + (this.voidIfAny([[3, 4], [null]][0][0])); + var t1 = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; + var t2 = [{ x: true, y: new derived() }, { x: false, y: new base() }]; + var t3 = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; + var anyObj = null; + // Order matters here so test all the variants + var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; + var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; + var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; + var ifaceObj = null; + var baseObj = new base(); + var base2Obj = new base2(); + var b1 = [baseObj, base2Obj, ifaceObj]; + var b2 = [base2Obj, baseObj, ifaceObj]; + var b3 = [baseObj, ifaceObj, base2Obj]; + var b4 = [ifaceObj, baseObj, base2Obj]; + }; + return f; + })(); +})(EmptyTypes || (EmptyTypes = {})); +var NonEmptyTypes; +(function (NonEmptyTypes) { + var base = (function () { + function base() { + } + return base; + })(); + var base2 = (function () { + function base2() { + } + return base2; + })(); + var derived = (function (_super) { + __extends(derived, _super); + function derived() { + _super.apply(this, arguments); + } + return derived; + })(base); + var f = (function () { + function f() { + } + f.prototype.voidIfAny = function (x, y) { + if (y === void 0) { y = false; } + return null; + }; + f.prototype.x = function () { + (this.voidIfAny([4, 2][0])); + (this.voidIfAny([4, 2, undefined][0])); + (this.voidIfAny([undefined, 2, 4][0])); + (this.voidIfAny([null, 2, 4][0])); + (this.voidIfAny([2, 4, null][0])); + (this.voidIfAny([undefined, 4, null][0])); + (this.voidIfAny(['', "q"][0])); + (this.voidIfAny(['', "q", undefined][0])); + (this.voidIfAny([undefined, "q", ''][0])); + (this.voidIfAny([null, "q", ''][0])); + (this.voidIfAny(["q", '', null][0])); + (this.voidIfAny([undefined, '', null][0])); + (this.voidIfAny([[3, 4], [null]][0][0])); + var t1 = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; + var t2 = [{ x: true, y: new derived() }, { x: false, y: new base() }]; + var t3 = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; + var anyObj = null; + // Order matters here so test all the variants + var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; + var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; + var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; + var ifaceObj = null; + var baseObj = new base(); + var base2Obj = new base2(); + var b1 = [baseObj, base2Obj, ifaceObj]; + var b2 = [base2Obj, baseObj, ifaceObj]; + var b3 = [baseObj, ifaceObj, base2Obj]; + var b4 = [ifaceObj, baseObj, base2Obj]; + }; + return f; + })(); +})(NonEmptyTypes || (NonEmptyTypes = {})); diff --git a/tests/baselines/reference/arrayBestCommonTypes.types b/tests/baselines/reference/arrayBestCommonTypes.types index a0f407358c3..a2a6921ca4e 100644 --- a/tests/baselines/reference/arrayBestCommonTypes.types +++ b/tests/baselines/reference/arrayBestCommonTypes.types @@ -1,47 +1,50 @@ === tests/cases/compiler/arrayBestCommonTypes.ts === -interface iface { } +module EmptyTypes { +>EmptyTypes : typeof EmptyTypes + + interface iface { } >iface : iface -class base implements iface { } + class base implements iface { } >base : base >iface : iface -class base2 implements iface { } + class base2 implements iface { } >base2 : base2 >iface : iface -class derived extends base { } + class derived extends base { } >derived : derived >base : base -class f { + class f { >f : f - public voidIfAny(x: boolean, y?: boolean): number; + public voidIfAny(x: boolean, y?: boolean): number; >voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } >x : boolean >y : boolean - public voidIfAny(x: string, y?: boolean): number; + public voidIfAny(x: string, y?: boolean): number; >voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } >x : string >y : boolean - public voidIfAny(x: number, y?: boolean): number; + public voidIfAny(x: number, y?: boolean): number; >voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } >x : number >y : boolean - public voidIfAny(x: any, y =false): any { return null; } + public voidIfAny(x: any, y = false): any { return null; } >voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } >x : any >y : boolean - - public x() { + + public x() { >x : () => void - (this.voidIfAny([4, 2][0])); + (this.voidIfAny([4, 2][0])); >(this.voidIfAny([4, 2][0])) : number >(this.voidIfAny([4, 2][0])) : number >this.voidIfAny([4, 2][0]) : number @@ -51,7 +54,7 @@ class f { >[4, 2][0] : number >[4, 2] : number[] - (this.voidIfAny([4, 2, undefined][0])); + (this.voidIfAny([4, 2, undefined][0])); >(this.voidIfAny([4, 2, undefined][0])) : number >(this.voidIfAny([4, 2, undefined][0])) : number >this.voidIfAny([4, 2, undefined][0]) : number @@ -62,7 +65,7 @@ class f { >[4, 2, undefined] : number[] >undefined : undefined - (this.voidIfAny([undefined, 2, 4][0])); + (this.voidIfAny([undefined, 2, 4][0])); >(this.voidIfAny([undefined, 2, 4][0])) : number >(this.voidIfAny([undefined, 2, 4][0])) : number >this.voidIfAny([undefined, 2, 4][0]) : number @@ -73,7 +76,7 @@ class f { >[undefined, 2, 4] : number[] >undefined : undefined - (this.voidIfAny([null, 2, 4][0])); + (this.voidIfAny([null, 2, 4][0])); >(this.voidIfAny([null, 2, 4][0])) : number >(this.voidIfAny([null, 2, 4][0])) : number >this.voidIfAny([null, 2, 4][0]) : number @@ -83,7 +86,7 @@ class f { >[null, 2, 4][0] : number >[null, 2, 4] : number[] - (this.voidIfAny([2, 4, null][0])); + (this.voidIfAny([2, 4, null][0])); >(this.voidIfAny([2, 4, null][0])) : number >(this.voidIfAny([2, 4, null][0])) : number >this.voidIfAny([2, 4, null][0]) : number @@ -93,7 +96,7 @@ class f { >[2, 4, null][0] : number >[2, 4, null] : number[] - (this.voidIfAny([undefined, 4, null][0])); + (this.voidIfAny([undefined, 4, null][0])); >(this.voidIfAny([undefined, 4, null][0])) : number >(this.voidIfAny([undefined, 4, null][0])) : number >this.voidIfAny([undefined, 4, null][0]) : number @@ -104,7 +107,7 @@ class f { >[undefined, 4, null] : number[] >undefined : undefined - (this.voidIfAny(['', "q"][0])); + (this.voidIfAny(['', "q"][0])); >(this.voidIfAny(['', "q"][0])) : number >(this.voidIfAny(['', "q"][0])) : number >this.voidIfAny(['', "q"][0]) : number @@ -114,7 +117,7 @@ class f { >['', "q"][0] : string >['', "q"] : string[] - (this.voidIfAny(['', "q", undefined][0])); + (this.voidIfAny(['', "q", undefined][0])); >(this.voidIfAny(['', "q", undefined][0])) : number >(this.voidIfAny(['', "q", undefined][0])) : number >this.voidIfAny(['', "q", undefined][0]) : number @@ -125,7 +128,7 @@ class f { >['', "q", undefined] : string[] >undefined : undefined - (this.voidIfAny([undefined, "q", ''][0])); + (this.voidIfAny([undefined, "q", ''][0])); >(this.voidIfAny([undefined, "q", ''][0])) : number >(this.voidIfAny([undefined, "q", ''][0])) : number >this.voidIfAny([undefined, "q", ''][0]) : number @@ -136,7 +139,7 @@ class f { >[undefined, "q", ''] : string[] >undefined : undefined - (this.voidIfAny([null, "q", ''][0])); + (this.voidIfAny([null, "q", ''][0])); >(this.voidIfAny([null, "q", ''][0])) : number >(this.voidIfAny([null, "q", ''][0])) : number >this.voidIfAny([null, "q", ''][0]) : number @@ -146,7 +149,7 @@ class f { >[null, "q", ''][0] : string >[null, "q", ''] : string[] - (this.voidIfAny(["q", '', null][0])); + (this.voidIfAny(["q", '', null][0])); >(this.voidIfAny(["q", '', null][0])) : number >(this.voidIfAny(["q", '', null][0])) : number >this.voidIfAny(["q", '', null][0]) : number @@ -156,7 +159,7 @@ class f { >["q", '', null][0] : string >["q", '', null] : string[] - (this.voidIfAny([undefined, '', null][0])); + (this.voidIfAny([undefined, '', null][0])); >(this.voidIfAny([undefined, '', null][0])) : number >(this.voidIfAny([undefined, '', null][0])) : number >this.voidIfAny([undefined, '', null][0]) : number @@ -167,26 +170,26 @@ class f { >[undefined, '', null] : string[] >undefined : undefined - (this.voidIfAny([[3,4],[null]][0][0])); ->(this.voidIfAny([[3,4],[null]][0][0])) : number ->(this.voidIfAny([[3,4],[null]][0][0])) : number ->this.voidIfAny([[3,4],[null]][0][0]) : number + (this.voidIfAny([[3, 4], [null]][0][0])); +>(this.voidIfAny([[3, 4], [null]][0][0])) : number +>(this.voidIfAny([[3, 4], [null]][0][0])) : number +>this.voidIfAny([[3, 4], [null]][0][0]) : number >this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } >this : f >voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } ->[[3,4],[null]][0][0] : number ->[[3,4],[null]][0] : number[] ->[[3,4],[null]] : number[][] ->[3,4] : number[] +>[[3, 4], [null]][0][0] : number +>[[3, 4], [null]][0] : number[] +>[[3, 4], [null]] : number[][] +>[3, 4] : number[] >[null] : null[] - - - var t1: { x: number; y: base; }[] = [ { x: 7, y: new derived() }, { x: 5, y: new base() } ]; + + + var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; >t1 : { x: number; y: base; }[] >x : number >y : base >base : base ->[ { x: 7, y: new derived() }, { x: 5, y: new base() } ] : { x: number; y: base; }[] +>[{ x: 7, y: new derived() }, { x: 5, y: new base() }] : { x: number; y: base; }[] >{ x: 7, y: new derived() } : { x: number; y: derived; } >x : number >y : derived @@ -198,12 +201,12 @@ class f { >new base() : base >base : typeof base - var t2: { x: boolean; y: base; }[] = [ { x: true, y: new derived() }, { x: false, y: new base() } ]; + var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }]; >t2 : { x: boolean; y: base; }[] >x : boolean >y : base >base : base ->[ { x: true, y: new derived() }, { x: false, y: new base() } ] : { x: boolean; y: base; }[] +>[{ x: true, y: new derived() }, { x: false, y: new base() }] : { x: boolean; y: base; }[] >{ x: true, y: new derived() } : { x: boolean; y: derived; } >x : boolean >y : derived @@ -215,12 +218,12 @@ class f { >new base() : base >base : typeof base - var t3: { x: string; y: base; }[] = [ { x: undefined, y: new base() }, { x: '', y: new derived() } ]; + var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; >t3 : { x: string; y: base; }[] >x : string >y : base >base : base ->[ { x: undefined, y: new base() }, { x: '', y: new derived() } ] : { x: string; y: base; }[] +>[{ x: undefined, y: new base() }, { x: '', y: new derived() }] : { x: string; y: base; }[] >{ x: undefined, y: new base() } : { x: undefined; y: base; } >x : undefined >undefined : undefined @@ -233,95 +236,429 @@ class f { >new derived() : derived >derived : typeof derived - var anyObj: any = null; + var anyObj: any = null; >anyObj : any - // Order matters here so test all the variants - var a1 = [ {x: 0, y: 'a'}, {x: 'a', y: 'a'}, {x: anyObj, y: 'a'} ]; + // Order matters here so test all the variants + var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; >a1 : { x: any; y: string; }[] ->[ {x: 0, y: 'a'}, {x: 'a', y: 'a'}, {x: anyObj, y: 'a'} ] : { x: any; y: string; }[] ->{x: 0, y: 'a'} : { x: number; y: string; } +>[{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }] : { x: any; y: string; }[] +>{ x: 0, y: 'a' } : { x: number; y: string; } >x : number >y : string ->{x: 'a', y: 'a'} : { x: string; y: string; } +>{ x: 'a', y: 'a' } : { x: string; y: string; } >x : string >y : string ->{x: anyObj, y: 'a'} : { x: any; y: string; } +>{ x: anyObj, y: 'a' } : { x: any; y: string; } >x : any >anyObj : any >y : string - var a2 = [ {x: anyObj, y: 'a'}, {x: 0, y: 'a'}, {x: 'a', y: 'a'} ]; + var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; >a2 : { x: any; y: string; }[] ->[ {x: anyObj, y: 'a'}, {x: 0, y: 'a'}, {x: 'a', y: 'a'} ] : { x: any; y: string; }[] ->{x: anyObj, y: 'a'} : { x: any; y: string; } +>[{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }] : { x: any; y: string; }[] +>{ x: anyObj, y: 'a' } : { x: any; y: string; } >x : any >anyObj : any >y : string ->{x: 0, y: 'a'} : { x: number; y: string; } +>{ x: 0, y: 'a' } : { x: number; y: string; } >x : number >y : string ->{x: 'a', y: 'a'} : { x: string; y: string; } +>{ x: 'a', y: 'a' } : { x: string; y: string; } >x : string >y : string - var a3 = [ {x: 0, y: 'a'}, {x: anyObj, y: 'a'}, {x: 'a', y: 'a'} ]; + var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; >a3 : { x: any; y: string; }[] ->[ {x: 0, y: 'a'}, {x: anyObj, y: 'a'}, {x: 'a', y: 'a'} ] : { x: any; y: string; }[] ->{x: 0, y: 'a'} : { x: number; y: string; } +>[{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }] : { x: any; y: string; }[] +>{ x: 0, y: 'a' } : { x: number; y: string; } >x : number >y : string ->{x: anyObj, y: 'a'} : { x: any; y: string; } +>{ x: anyObj, y: 'a' } : { x: any; y: string; } >x : any >anyObj : any >y : string ->{x: 'a', y: 'a'} : { x: string; y: string; } +>{ x: 'a', y: 'a' } : { x: string; y: string; } >x : string >y : string - - var ifaceObj: iface = null; + + var ifaceObj: iface = null; >ifaceObj : iface >iface : iface - var baseObj = new base(); + var baseObj = new base(); >baseObj : base >new base() : base >base : typeof base - var base2Obj = new base2(); + var base2Obj = new base2(); >base2Obj : base2 >new base2() : base2 >base2 : typeof base2 - var b1 = [ baseObj, base2Obj, ifaceObj ]; ->b1 : base[] ->[ baseObj, base2Obj, ifaceObj ] : base[] + var b1 = [baseObj, base2Obj, ifaceObj]; +>b1 : iface[] +>[baseObj, base2Obj, ifaceObj] : iface[] >baseObj : base >base2Obj : base2 >ifaceObj : iface - var b2 = [ base2Obj, baseObj, ifaceObj ]; ->b2 : base2[] ->[ base2Obj, baseObj, ifaceObj ] : base2[] + var b2 = [base2Obj, baseObj, ifaceObj]; +>b2 : iface[] +>[base2Obj, baseObj, ifaceObj] : iface[] >base2Obj : base2 >baseObj : base >ifaceObj : iface - var b3 = [ baseObj, ifaceObj, base2Obj ]; ->b3 : base[] ->[ baseObj, ifaceObj, base2Obj ] : base[] + var b3 = [baseObj, ifaceObj, base2Obj]; +>b3 : iface[] +>[baseObj, ifaceObj, base2Obj] : iface[] >baseObj : base >ifaceObj : iface >base2Obj : base2 - var b4 = [ ifaceObj, baseObj, base2Obj ]; + var b4 = [ifaceObj, baseObj, base2Obj]; >b4 : iface[] ->[ ifaceObj, baseObj, base2Obj ] : iface[] +>[ifaceObj, baseObj, base2Obj] : iface[] >ifaceObj : iface >baseObj : base >base2Obj : base2 + } + } +} + +module NonEmptyTypes { +>NonEmptyTypes : typeof NonEmptyTypes + + interface iface { x: string; } +>iface : iface +>x : string + + class base implements iface { x: string; y: string; } +>base : base +>iface : iface +>x : string +>y : string + + class base2 implements iface { x: string; z: string; } +>base2 : base2 +>iface : iface +>x : string +>z : string + + class derived extends base { a: string; } +>derived : derived +>base : base +>a : string + + + class f { +>f : f + + public voidIfAny(x: boolean, y?: boolean): number; +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>x : boolean +>y : boolean + + public voidIfAny(x: string, y?: boolean): number; +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>x : string +>y : boolean + + public voidIfAny(x: number, y?: boolean): number; +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>x : number +>y : boolean + + public voidIfAny(x: any, y = false): any { return null; } +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>x : any +>y : boolean + + public x() { +>x : () => void + + (this.voidIfAny([4, 2][0])); +>(this.voidIfAny([4, 2][0])) : number +>(this.voidIfAny([4, 2][0])) : number +>this.voidIfAny([4, 2][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[4, 2][0] : number +>[4, 2] : number[] + + (this.voidIfAny([4, 2, undefined][0])); +>(this.voidIfAny([4, 2, undefined][0])) : number +>(this.voidIfAny([4, 2, undefined][0])) : number +>this.voidIfAny([4, 2, undefined][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[4, 2, undefined][0] : number +>[4, 2, undefined] : number[] +>undefined : undefined + + (this.voidIfAny([undefined, 2, 4][0])); +>(this.voidIfAny([undefined, 2, 4][0])) : number +>(this.voidIfAny([undefined, 2, 4][0])) : number +>this.voidIfAny([undefined, 2, 4][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[undefined, 2, 4][0] : number +>[undefined, 2, 4] : number[] +>undefined : undefined + + (this.voidIfAny([null, 2, 4][0])); +>(this.voidIfAny([null, 2, 4][0])) : number +>(this.voidIfAny([null, 2, 4][0])) : number +>this.voidIfAny([null, 2, 4][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[null, 2, 4][0] : number +>[null, 2, 4] : number[] + + (this.voidIfAny([2, 4, null][0])); +>(this.voidIfAny([2, 4, null][0])) : number +>(this.voidIfAny([2, 4, null][0])) : number +>this.voidIfAny([2, 4, null][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[2, 4, null][0] : number +>[2, 4, null] : number[] + + (this.voidIfAny([undefined, 4, null][0])); +>(this.voidIfAny([undefined, 4, null][0])) : number +>(this.voidIfAny([undefined, 4, null][0])) : number +>this.voidIfAny([undefined, 4, null][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[undefined, 4, null][0] : number +>[undefined, 4, null] : number[] +>undefined : undefined + + (this.voidIfAny(['', "q"][0])); +>(this.voidIfAny(['', "q"][0])) : number +>(this.voidIfAny(['', "q"][0])) : number +>this.voidIfAny(['', "q"][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>['', "q"][0] : string +>['', "q"] : string[] + + (this.voidIfAny(['', "q", undefined][0])); +>(this.voidIfAny(['', "q", undefined][0])) : number +>(this.voidIfAny(['', "q", undefined][0])) : number +>this.voidIfAny(['', "q", undefined][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>['', "q", undefined][0] : string +>['', "q", undefined] : string[] +>undefined : undefined + + (this.voidIfAny([undefined, "q", ''][0])); +>(this.voidIfAny([undefined, "q", ''][0])) : number +>(this.voidIfAny([undefined, "q", ''][0])) : number +>this.voidIfAny([undefined, "q", ''][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[undefined, "q", ''][0] : string +>[undefined, "q", ''] : string[] +>undefined : undefined + + (this.voidIfAny([null, "q", ''][0])); +>(this.voidIfAny([null, "q", ''][0])) : number +>(this.voidIfAny([null, "q", ''][0])) : number +>this.voidIfAny([null, "q", ''][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[null, "q", ''][0] : string +>[null, "q", ''] : string[] + + (this.voidIfAny(["q", '', null][0])); +>(this.voidIfAny(["q", '', null][0])) : number +>(this.voidIfAny(["q", '', null][0])) : number +>this.voidIfAny(["q", '', null][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>["q", '', null][0] : string +>["q", '', null] : string[] + + (this.voidIfAny([undefined, '', null][0])); +>(this.voidIfAny([undefined, '', null][0])) : number +>(this.voidIfAny([undefined, '', null][0])) : number +>this.voidIfAny([undefined, '', null][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[undefined, '', null][0] : string +>[undefined, '', null] : string[] +>undefined : undefined + + (this.voidIfAny([[3, 4], [null]][0][0])); +>(this.voidIfAny([[3, 4], [null]][0][0])) : number +>(this.voidIfAny([[3, 4], [null]][0][0])) : number +>this.voidIfAny([[3, 4], [null]][0][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[[3, 4], [null]][0][0] : number +>[[3, 4], [null]][0] : number[] +>[[3, 4], [null]] : number[][] +>[3, 4] : number[] +>[null] : null[] + + + var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; +>t1 : { x: number; y: base; }[] +>x : number +>y : base +>base : base +>[{ x: 7, y: new derived() }, { x: 5, y: new base() }] : { x: number; y: base; }[] +>{ x: 7, y: new derived() } : { x: number; y: derived; } +>x : number +>y : derived +>new derived() : derived +>derived : typeof derived +>{ x: 5, y: new base() } : { x: number; y: base; } +>x : number +>y : base +>new base() : base +>base : typeof base + + var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }]; +>t2 : { x: boolean; y: base; }[] +>x : boolean +>y : base +>base : base +>[{ x: true, y: new derived() }, { x: false, y: new base() }] : { x: boolean; y: base; }[] +>{ x: true, y: new derived() } : { x: boolean; y: derived; } +>x : boolean +>y : derived +>new derived() : derived +>derived : typeof derived +>{ x: false, y: new base() } : { x: boolean; y: base; } +>x : boolean +>y : base +>new base() : base +>base : typeof base + + var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; +>t3 : { x: string; y: base; }[] +>x : string +>y : base +>base : base +>[{ x: undefined, y: new base() }, { x: '', y: new derived() }] : { x: string; y: base; }[] +>{ x: undefined, y: new base() } : { x: undefined; y: base; } +>x : undefined +>undefined : undefined +>y : base +>new base() : base +>base : typeof base +>{ x: '', y: new derived() } : { x: string; y: derived; } +>x : string +>y : derived +>new derived() : derived +>derived : typeof derived + + var anyObj: any = null; +>anyObj : any + + // Order matters here so test all the variants + var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; +>a1 : { x: any; y: string; }[] +>[{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }] : { x: any; y: string; }[] +>{ x: 0, y: 'a' } : { x: number; y: string; } +>x : number +>y : string +>{ x: 'a', y: 'a' } : { x: string; y: string; } +>x : string +>y : string +>{ x: anyObj, y: 'a' } : { x: any; y: string; } +>x : any +>anyObj : any +>y : string + + var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; +>a2 : { x: any; y: string; }[] +>[{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }] : { x: any; y: string; }[] +>{ x: anyObj, y: 'a' } : { x: any; y: string; } +>x : any +>anyObj : any +>y : string +>{ x: 0, y: 'a' } : { x: number; y: string; } +>x : number +>y : string +>{ x: 'a', y: 'a' } : { x: string; y: string; } +>x : string +>y : string + + var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; +>a3 : { x: any; y: string; }[] +>[{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }] : { x: any; y: string; }[] +>{ x: 0, y: 'a' } : { x: number; y: string; } +>x : number +>y : string +>{ x: anyObj, y: 'a' } : { x: any; y: string; } +>x : any +>anyObj : any +>y : string +>{ x: 'a', y: 'a' } : { x: string; y: string; } +>x : string +>y : string + + var ifaceObj: iface = null; +>ifaceObj : iface +>iface : iface + + var baseObj = new base(); +>baseObj : base +>new base() : base +>base : typeof base + + var base2Obj = new base2(); +>base2Obj : base2 +>new base2() : base2 +>base2 : typeof base2 + + var b1 = [baseObj, base2Obj, ifaceObj]; +>b1 : iface[] +>[baseObj, base2Obj, ifaceObj] : iface[] +>baseObj : base +>base2Obj : base2 +>ifaceObj : iface + + var b2 = [base2Obj, baseObj, ifaceObj]; +>b2 : iface[] +>[base2Obj, baseObj, ifaceObj] : iface[] +>base2Obj : base2 +>baseObj : base +>ifaceObj : iface + + var b3 = [baseObj, ifaceObj, base2Obj]; +>b3 : iface[] +>[baseObj, ifaceObj, base2Obj] : iface[] +>baseObj : base +>ifaceObj : iface +>base2Obj : base2 + + var b4 = [ifaceObj, baseObj, base2Obj]; +>b4 : iface[] +>[ifaceObj, baseObj, base2Obj] : iface[] +>ifaceObj : iface +>baseObj : base +>base2Obj : base2 + } } } - diff --git a/tests/baselines/reference/arrayLiteralContextualType.errors.txt b/tests/baselines/reference/arrayLiteralContextualType.errors.txt deleted file mode 100644 index 5f661647d9f..00000000000 --- a/tests/baselines/reference/arrayLiteralContextualType.errors.txt +++ /dev/null @@ -1,40 +0,0 @@ -tests/cases/compiler/arrayLiteralContextualType.ts(28,5): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'IAnimal[]'. - Type '{}' is not assignable to type 'IAnimal'. -tests/cases/compiler/arrayLiteralContextualType.ts(29,5): error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ [x: number]: IAnimal; }'. - - -==== tests/cases/compiler/arrayLiteralContextualType.ts (2 errors) ==== - interface IAnimal { - name: string; - } - - class Giraffe { - name = "Giraffe"; - neckLength = "3m"; - } - - class Elephant { - name = "Elephant"; - trunkDiameter = "20cm"; - } - - function foo(animals: IAnimal[]) { } - function bar(animals: { [n: number]: IAnimal }) { } - - foo([ - new Giraffe(), - new Elephant() - ]); // Legal because of the contextual type IAnimal provided by the parameter - bar([ - new Giraffe(), - new Elephant() - ]); // Legal because of the contextual type IAnimal provided by the parameter - - var arr = [new Giraffe(), new Elephant()]; - foo(arr); // Error because of no contextual type - ~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'IAnimal[]'. -!!! error TS2345: Type '{}' is not assignable to type 'IAnimal'. - bar(arr); // Error because of no contextual type - ~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ [x: number]: IAnimal; }'. \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiteralContextualType.js b/tests/baselines/reference/arrayLiteralContextualType.js index a551a754204..65e4c135cba 100644 --- a/tests/baselines/reference/arrayLiteralContextualType.js +++ b/tests/baselines/reference/arrayLiteralContextualType.js @@ -26,8 +26,8 @@ bar([ ]); // Legal because of the contextual type IAnimal provided by the parameter var arr = [new Giraffe(), new Elephant()]; -foo(arr); // Error because of no contextual type -bar(arr); // Error because of no contextual type +foo(arr); // ok because arr is Array not {}[] +bar(arr); // ok because arr is Array not {}[] //// [arrayLiteralContextualType.js] var Giraffe = (function () { @@ -57,5 +57,5 @@ bar([ new Elephant() ]); // Legal because of the contextual type IAnimal provided by the parameter var arr = [new Giraffe(), new Elephant()]; -foo(arr); // Error because of no contextual type -bar(arr); // Error because of no contextual type +foo(arr); // ok because arr is Array not {}[] +bar(arr); // ok because arr is Array not {}[] diff --git a/tests/baselines/reference/arrayLiteralContextualType.types b/tests/baselines/reference/arrayLiteralContextualType.types new file mode 100644 index 00000000000..015a428c114 --- /dev/null +++ b/tests/baselines/reference/arrayLiteralContextualType.types @@ -0,0 +1,86 @@ +=== tests/cases/compiler/arrayLiteralContextualType.ts === +interface IAnimal { +>IAnimal : IAnimal + + name: string; +>name : string +} + +class Giraffe { +>Giraffe : Giraffe + + name = "Giraffe"; +>name : string + + neckLength = "3m"; +>neckLength : string +} + +class Elephant { +>Elephant : Elephant + + name = "Elephant"; +>name : string + + trunkDiameter = "20cm"; +>trunkDiameter : string +} + +function foo(animals: IAnimal[]) { } +>foo : (animals: IAnimal[]) => void +>animals : IAnimal[] +>IAnimal : IAnimal + +function bar(animals: { [n: number]: IAnimal }) { } +>bar : (animals: { [x: number]: IAnimal; }) => void +>animals : { [x: number]: IAnimal; } +>n : number +>IAnimal : IAnimal + +foo([ +>foo([ new Giraffe(), new Elephant()]) : void +>foo : (animals: IAnimal[]) => void +>[ new Giraffe(), new Elephant()] : IAnimal[] + + new Giraffe(), +>new Giraffe() : Giraffe +>Giraffe : typeof Giraffe + + new Elephant() +>new Elephant() : Elephant +>Elephant : typeof Elephant + +]); // Legal because of the contextual type IAnimal provided by the parameter +bar([ +>bar([ new Giraffe(), new Elephant()]) : void +>bar : (animals: { [x: number]: IAnimal; }) => void +>[ new Giraffe(), new Elephant()] : IAnimal[] + + new Giraffe(), +>new Giraffe() : Giraffe +>Giraffe : typeof Giraffe + + new Elephant() +>new Elephant() : Elephant +>Elephant : typeof Elephant + +]); // Legal because of the contextual type IAnimal provided by the parameter + +var arr = [new Giraffe(), new Elephant()]; +>arr : Array +>[new Giraffe(), new Elephant()] : Array +>new Giraffe() : Giraffe +>Giraffe : typeof Giraffe +>new Elephant() : Elephant +>Elephant : typeof Elephant + +foo(arr); // ok because arr is Array not {}[] +>foo(arr) : void +>foo : (animals: IAnimal[]) => void +>arr : Array + +bar(arr); // ok because arr is Array not {}[] +>bar(arr) : void +>bar : (animals: { [x: number]: IAnimal; }) => void +>arr : Array + diff --git a/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types b/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types index 7729b280160..49b65a86aa6 100644 --- a/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types +++ b/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types @@ -23,8 +23,8 @@ var as = [a, b]; // { x: number; y?: number };[] >b : { x: number; z?: number; } var bs = [b, a]; // { x: number; z?: number };[] ->bs : { x: number; z?: number; }[] ->[b, a] : { x: number; z?: number; }[] +>bs : { x: number; y?: number; }[] +>[b, a] : { x: number; y?: number; }[] >b : { x: number; z?: number; } >a : { x: number; y?: number; } diff --git a/tests/baselines/reference/arrayLiterals.js b/tests/baselines/reference/arrayLiterals.js index 800d2a12550..16e5ec7eee4 100644 --- a/tests/baselines/reference/arrayLiterals.js +++ b/tests/baselines/reference/arrayLiterals.js @@ -2,28 +2,21 @@ // Empty array literal with no contextual type has type Undefined[] var arr1= [[], [1], ['']]; -var arr1: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK var arr2 = [[null], [1], ['']]; -var arr2: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK // Array literal with elements of only EveryType E has type E[] var stringArrArr = [[''], [""]]; -var stringArrArr: string[][]; var stringArr = ['', ""]; -var stringArr: string[]; var numberArr = [0, 0.0, 0x00, 1e1]; -var numberArr: number[]; var boolArr = [false, true, false, true]; -var boolArr: boolean[]; class C { private p; } var classArr = [new C(), new C()]; -var classArr: C[]; // Should be OK var classTypeArray = [C, C, C]; var classTypeArray: Array; // Should OK, not be a parse error @@ -31,7 +24,6 @@ var classTypeArray: Array; // Should OK, not be a parse error // Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[] var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; -var context2: Array<{}>; // Should be OK // Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[] class Base { private p; } @@ -53,31 +45,23 @@ var __extends = this.__extends || function (d, b) { d.prototype = new __(); }; var arr1 = [[], [1], ['']]; -var arr1; // Bug 825172: Error ({}[] does not match {}[]), but should be OK var arr2 = [[null], [1], ['']]; -var arr2; // Bug 825172: Error ({}[] does not match {}[]), but should be OK // Array literal with elements of only EveryType E has type E[] var stringArrArr = [[''], [""]]; -var stringArrArr; var stringArr = ['', ""]; -var stringArr; var numberArr = [0, 0.0, 0x00, 1e1]; -var numberArr; var boolArr = [false, true, false, true]; -var boolArr; var C = (function () { function C() { } return C; })(); var classArr = [new C(), new C()]; -var classArr; // Should be OK var classTypeArray = [C, C, C]; var classTypeArray; // Should OK, not be a parse error // Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[] var context1 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; -var context2; // Should be OK // Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[] var Base = (function () { function Base() { diff --git a/tests/baselines/reference/arrayLiterals.types b/tests/baselines/reference/arrayLiterals.types index 29dd1b19970..d66e9d741a9 100644 --- a/tests/baselines/reference/arrayLiterals.types +++ b/tests/baselines/reference/arrayLiterals.types @@ -2,25 +2,19 @@ // Empty array literal with no contextual type has type Undefined[] var arr1= [[], [1], ['']]; ->arr1 : {}[] ->[[], [1], ['']] : {}[] +>arr1 : Array +>[[], [1], ['']] : Array >[] : undefined[] >[1] : number[] >[''] : string[] -var arr1: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK ->arr1 : {}[] - var arr2 = [[null], [1], ['']]; ->arr2 : {}[] ->[[null], [1], ['']] : {}[] +>arr2 : Array +>[[null], [1], ['']] : Array >[null] : null[] >[1] : number[] >[''] : string[] -var arr2: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK ->arr2 : {}[] - // Array literal with elements of only EveryType E has type E[] var stringArrArr = [[''], [""]]; @@ -29,30 +23,18 @@ var stringArrArr = [[''], [""]]; >[''] : string[] >[""] : string[] -var stringArrArr: string[][]; ->stringArrArr : string[][] - var stringArr = ['', ""]; >stringArr : string[] >['', ""] : string[] -var stringArr: string[]; ->stringArr : string[] - var numberArr = [0, 0.0, 0x00, 1e1]; >numberArr : number[] >[0, 0.0, 0x00, 1e1] : number[] -var numberArr: number[]; ->numberArr : number[] - var boolArr = [false, true, false, true]; >boolArr : boolean[] >[false, true, false, true] : boolean[] -var boolArr: boolean[]; ->boolArr : boolean[] - class C { private p; } >C : C >p : any @@ -65,10 +47,6 @@ var classArr = [new C(), new C()]; >new C() : C >C : typeof C -var classArr: C[]; // Should be OK ->classArr : C[] ->C : C - var classTypeArray = [C, C, C]; >classTypeArray : typeof C[] >[C, C, C] : typeof C[] @@ -98,8 +76,8 @@ var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: ' >c : number var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; ->context2 : {}[] ->[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : {}[] +>context2 : Array<{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }> +>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : Array<{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }> >{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; } >a : string >b : number @@ -109,10 +87,6 @@ var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; >b : number >c : number -var context2: Array<{}>; // Should be OK ->context2 : {}[] ->Array : T[] - // Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[] class Base { private p; } >Base : Base diff --git a/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types b/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types index becff7617b7..e99ca18673e 100644 --- a/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types +++ b/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types @@ -61,8 +61,8 @@ var xs = [list, myList]; // {}[] >myList : MyList var ys = [list, list2]; // {}[] ->ys : {}[] ->[list, list2] : {}[] +>ys : Array | List> +>[list, list2] : Array | List> >list : List >list2 : List diff --git a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types index 3deeae69bbe..18fe6efb8ce 100644 --- a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types +++ b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types @@ -54,8 +54,8 @@ var r4 = true ? a : b; // typeof a >b : { x: number; z?: number; } var r5 = true ? b : a; // typeof b ->r5 : { x: number; z?: number; } ->true ? b : a : { x: number; z?: number; } +>r5 : { x: number; y?: number; } +>true ? b : a : { x: number; y?: number; } >b : { x: number; z?: number; } >a : { x: number; y?: number; } diff --git a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.errors.txt b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.errors.txt index 532a40becd9..83f4678c8f3 100644 --- a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.errors.txt +++ b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.errors.txt @@ -1,14 +1,9 @@ -tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(11,10): error TS2367: No best common type exists between 'number' and 'string'. -tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(12,10): error TS2367: No best common type exists between 'Derived' and 'Derived2'. -tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(15,12): error TS2367: No best common type exists between 'T' and 'U'. tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(18,15): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(19,12): error TS2367: No best common type exists between 'T' and 'U'. tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(22,15): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(22,28): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(23,12): error TS2367: No best common type exists between 'T' and 'U'. -==== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts (8 errors) ==== +==== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts (3 errors) ==== // conditional expressions return the best common type of the branches plus contextual type (using the first candidate if multiple BCTs exist) // these are errors @@ -20,24 +15,16 @@ tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfC var derived2: Derived2; var r2 = true ? 1 : ''; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'number' and 'string'. var r9 = true ? derived : derived2; - ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Derived' and 'Derived2'. function foo(t: T, u: U) { return true ? t : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. } function foo2(t: T, u: U) { // Error for referencing own type parameter ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. return true ? t : u; // Ok because BCT(T, U) = U - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. } function foo3(t: T, u: U) { @@ -46,6 +33,4 @@ tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfC ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. return true ? t : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. } \ No newline at end of file diff --git a/tests/baselines/reference/conditionalExpression1.errors.txt b/tests/baselines/reference/conditionalExpression1.errors.txt index 542b660ba42..30703c7169e 100644 --- a/tests/baselines/reference/conditionalExpression1.errors.txt +++ b/tests/baselines/reference/conditionalExpression1.errors.txt @@ -1,10 +1,9 @@ -tests/cases/compiler/conditionalExpression1.ts(1,5): error TS2323: Type '{}' is not assignable to type 'boolean'. -tests/cases/compiler/conditionalExpression1.ts(1,19): error TS2367: No best common type exists between 'number' and 'string'. +tests/cases/compiler/conditionalExpression1.ts(1,5): error TS2322: Type 'string | number' is not assignable to type 'boolean': + Type 'string' is not assignable to type 'boolean'. -==== tests/cases/compiler/conditionalExpression1.ts (2 errors) ==== +==== tests/cases/compiler/conditionalExpression1.ts (1 errors) ==== var x: boolean = (true ? 1 : ""); // should be an error ~ -!!! error TS2323: Type '{}' is not assignable to type 'boolean'. - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'number' and 'string'. \ No newline at end of file +!!! error TS2322: Type 'string | number' is not assignable to type 'boolean': +!!! error TS2322: Type 'string' is not assignable to type 'boolean'. \ No newline at end of file diff --git a/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt b/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt index 7db921cbe1a..fb2c02d1c28 100644 --- a/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt +++ b/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt @@ -1,20 +1,21 @@ -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(12,1): error TS2367: No best common type exists between 'A' and 'B'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(13,15): error TS2367: No best common type exists between 'A' and 'B'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,5): error TS2322: Type '{}' is not assignable to type 'A': - Property 'propertyA' is missing in type '{}'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,18): error TS2366: No best common type exists between 'A', 'A', and 'B'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(17,5): error TS2322: Type '{}' is not assignable to type 'B': - Property 'propertyB' is missing in type '{}'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(17,18): error TS2366: No best common type exists between 'B', 'A', and 'B'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,5): error TS2323: Type '{}' is not assignable to type '(t: X) => number'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,33): error TS2366: No best common type exists between '(t: X) => number', '(m: X) => number', and '(n: X) => string'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,5): error TS2323: Type '{}' is not assignable to type '(t: X) => string'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,33): error TS2366: No best common type exists between '(t: X) => string', '(m: X) => number', and '(n: X) => string'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(21,5): error TS2323: Type '{}' is not assignable to type '(t: X) => boolean'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(21,34): error TS2366: No best common type exists between '(t: X) => boolean', '(m: X) => number', and '(n: X) => string'. +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(15,5): error TS2322: Type 'A | B' is not assignable to type 'A': + Type 'B' is not assignable to type 'A': + Property 'propertyA' is missing in type 'B'. +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,5): error TS2322: Type 'A | B' is not assignable to type 'B': + Type 'A' is not assignable to type 'B': + Property 'propertyB' is missing in type 'A'. +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(18,5): error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => number': + Type '(n: X) => string' is not assignable to type '(t: X) => number': + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,5): error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => string': + Type '(m: X) => number' is not assignable to type '(t: X) => string': + Type 'number' is not assignable to type 'string'. +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,5): error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => boolean': + Type '(m: X) => number' is not assignable to type '(t: X) => boolean': + Type 'number' is not assignable to type 'boolean'. -==== tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts (12 errors) ==== +==== tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts (5 errors) ==== //Cond ? Expr1 : Expr2, Expr1 and Expr2 have no identical best common type class X { propertyX: any; propertyX1: number; propertyX2: string }; class A extends X { propertyA: number }; @@ -24,41 +25,34 @@ tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithou var a: A; var b: B; - //Expect to have compiler errors - //Be not contextually typed + // No errors anymore, uses union types true ? a : b; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'A' and 'B'. var result1 = true ? a : b; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'A' and 'B'. - //Be contextually typed and and bct is not identical + //Be contextually typed and and bct is not identical, results in errors that union type is not assignable to target var result2: A = true ? a : b; ~~~~~~~ -!!! error TS2322: Type '{}' is not assignable to type 'A': -!!! error TS2322: Property 'propertyA' is missing in type '{}'. - ~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between 'A', 'A', and 'B'. +!!! error TS2322: Type 'A | B' is not assignable to type 'A': +!!! error TS2322: Type 'B' is not assignable to type 'A': +!!! error TS2322: Property 'propertyA' is missing in type 'B'. var result3: B = true ? a : b; ~~~~~~~ -!!! error TS2322: Type '{}' is not assignable to type 'B': -!!! error TS2322: Property 'propertyB' is missing in type '{}'. - ~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between 'B', 'A', and 'B'. +!!! error TS2322: Type 'A | B' is not assignable to type 'B': +!!! error TS2322: Type 'A' is not assignable to type 'B': +!!! error TS2322: Property 'propertyB' is missing in type 'A'. var result4: (t: X) => number = true ? (m) => m.propertyX1 : (n) => n.propertyX2; ~~~~~~~ -!!! error TS2323: Type '{}' is not assignable to type '(t: X) => number'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between '(t: X) => number', '(m: X) => number', and '(n: X) => string'. +!!! error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => number': +!!! error TS2322: Type '(n: X) => string' is not assignable to type '(t: X) => number': +!!! error TS2322: Type 'string' is not assignable to type 'number'. var result5: (t: X) => string = true ? (m) => m.propertyX1 : (n) => n.propertyX2; ~~~~~~~ -!!! error TS2323: Type '{}' is not assignable to type '(t: X) => string'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between '(t: X) => string', '(m: X) => number', and '(n: X) => string'. +!!! error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => string': +!!! error TS2322: Type '(m: X) => number' is not assignable to type '(t: X) => string': +!!! error TS2322: Type 'number' is not assignable to type 'string'. var result6: (t: X) => boolean = true ? (m) => m.propertyX1 : (n) => n.propertyX2; ~~~~~~~ -!!! error TS2323: Type '{}' is not assignable to type '(t: X) => boolean'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between '(t: X) => boolean', '(m: X) => number', and '(n: X) => string'. \ No newline at end of file +!!! error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => boolean': +!!! error TS2322: Type '(m: X) => number' is not assignable to type '(t: X) => boolean': +!!! error TS2322: Type 'number' is not assignable to type 'boolean'. \ No newline at end of file diff --git a/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.js b/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.js index 90125d4ebf6..b6376dd781f 100644 --- a/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.js +++ b/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.js @@ -8,12 +8,11 @@ var x: X; var a: A; var b: B; -//Expect to have compiler errors -//Be not contextually typed +// No errors anymore, uses union types true ? a : b; var result1 = true ? a : b; -//Be contextually typed and and bct is not identical +//Be contextually typed and and bct is not identical, results in errors that union type is not assignable to target var result2: A = true ? a : b; var result3: B = true ? a : b; @@ -54,11 +53,10 @@ var B = (function (_super) { var x; var a; var b; -//Expect to have compiler errors -//Be not contextually typed +// No errors anymore, uses union types true ? a : b; var result1 = true ? a : b; -//Be contextually typed and and bct is not identical +//Be contextually typed and and bct is not identical, results in errors that union type is not assignable to target var result2 = true ? a : b; var result3 = true ? a : b; var result4 = true ? function (m) { return m.propertyX1; } : function (n) { return n.propertyX2; }; diff --git a/tests/baselines/reference/contextualTyping21.errors.txt b/tests/baselines/reference/contextualTyping21.errors.txt index 999cfcbd769..620b0635d12 100644 --- a/tests/baselines/reference/contextualTyping21.errors.txt +++ b/tests/baselines/reference/contextualTyping21.errors.txt @@ -1,11 +1,13 @@ -tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type '{}[]' is not assignable to type '{ id: number; }[]': - Type '{}' is not assignable to type '{ id: number; }': - Property 'id' is missing in type '{}'. +tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type 'Array' is not assignable to type '{ id: number; }[]': + Type 'number | { id: number; }' is not assignable to type '{ id: number; }': + Type 'number' is not assignable to type '{ id: number; }': + Property 'id' is missing in type 'Number'. ==== tests/cases/compiler/contextualTyping21.ts (1 errors) ==== var foo:{id:number;}[] = [{id:1}]; foo = [{id:1}, 1]; ~~~ -!!! error TS2322: Type '{}[]' is not assignable to type '{ id: number; }[]': -!!! error TS2322: Type '{}' is not assignable to type '{ id: number; }': -!!! error TS2322: Property 'id' is missing in type '{}'. \ No newline at end of file +!!! error TS2322: Type 'Array' is not assignable to type '{ id: number; }[]': +!!! error TS2322: Type 'number | { id: number; }' is not assignable to type '{ id: number; }': +!!! error TS2322: Type 'number' is not assignable to type '{ id: number; }': +!!! error TS2322: Property 'id' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping30.errors.txt b/tests/baselines/reference/contextualTyping30.errors.txt index 3b2fbc8aac6..4c8d87d41b6 100644 --- a/tests/baselines/reference/contextualTyping30.errors.txt +++ b/tests/baselines/reference/contextualTyping30.errors.txt @@ -1,9 +1,11 @@ -tests/cases/compiler/contextualTyping30.ts(1,37): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. - Type '{}' is not assignable to type 'number'. +tests/cases/compiler/contextualTyping30.ts(1,37): error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. ==== tests/cases/compiler/contextualTyping30.ts (1 errors) ==== function foo(param:number[]){}; foo([1, "a"]); ~~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type '{}' is not assignable to type 'number'. \ No newline at end of file +!!! error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number': +!!! error TS2345: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping33.errors.txt b/tests/baselines/reference/contextualTyping33.errors.txt index 8f83fc37ab1..82799037ec6 100644 --- a/tests/baselines/reference/contextualTyping33.errors.txt +++ b/tests/baselines/reference/contextualTyping33.errors.txt @@ -1,9 +1,11 @@ -tests/cases/compiler/contextualTyping33.ts(1,66): error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'. - Type '{}' is not assignable to type '{ (): number; (i: number): number; }'. +tests/cases/compiler/contextualTyping33.ts(1,66): error TS2345: Argument of type 'Array<{ (): number; } | { (): string; }>' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'. + Type '{ (): number; } | { (): string; }' is not assignable to type '{ (): number; (i: number): number; }': + Type '() => string' is not assignable to type '{ (): number; (i: number): number; }'. ==== tests/cases/compiler/contextualTyping33.ts (1 errors) ==== function foo(param: {():number; (i:number):number; }[]) { }; foo([function(){return 1;}, function(){return "foo"}]); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'. -!!! error TS2345: Type '{}' is not assignable to type '{ (): number; (i: number): number; }'. \ No newline at end of file +!!! error TS2345: Argument of type 'Array<{ (): number; } | { (): string; }>' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'. +!!! error TS2345: Type '{ (): number; } | { (): string; }' is not assignable to type '{ (): number; (i: number): number; }': +!!! error TS2345: Type '() => string' is not assignable to type '{ (): number; (i: number): number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt b/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt index 0f9fc64536b..cb3b439681e 100644 --- a/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt +++ b/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt @@ -1,7 +1,8 @@ -tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type '{}[]' is not assignable to type 'I': +tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type 'Array' is not assignable to type 'I': Index signatures are incompatible: - Type '{}' is not assignable to type 'Date': - Property 'toDateString' is missing in type '{}'. + Type 'number | Date' is not assignable to type 'Date': + Type 'number' is not assignable to type 'Date': + Property 'toDateString' is missing in type 'Number'. ==== tests/cases/compiler/contextualTypingOfArrayLiterals1.ts (1 errors) ==== @@ -11,10 +12,11 @@ tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Typ var x3: I = [new Date(), 1]; ~~ -!!! error TS2322: Type '{}[]' is not assignable to type 'I': +!!! error TS2322: Type 'Array' is not assignable to type 'I': !!! error TS2322: Index signatures are incompatible: -!!! error TS2322: Type '{}' is not assignable to type 'Date': -!!! error TS2322: Property 'toDateString' is missing in type '{}'. +!!! error TS2322: Type 'number | Date' is not assignable to type 'Date': +!!! error TS2322: Type 'number' is not assignable to type 'Date': +!!! error TS2322: Property 'toDateString' is missing in type 'Number'. var r2 = x3[1]; r2.getDate(); \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingOfConditionalExpression2.errors.txt b/tests/baselines/reference/contextualTypingOfConditionalExpression2.errors.txt index c433bd1d8ca..574e25c6f45 100644 --- a/tests/baselines/reference/contextualTypingOfConditionalExpression2.errors.txt +++ b/tests/baselines/reference/contextualTypingOfConditionalExpression2.errors.txt @@ -1,8 +1,11 @@ -tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,5): error TS2323: Type '{}' is not assignable to type '(a: A) => void'. -tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,26): error TS2366: No best common type exists between '(a: A) => void', '(a: C) => number', and '(b: number) => void'. +tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,5): error TS2322: Type '{ (a: C): number; } | { (b: number): void; }' is not assignable to type '(a: A) => void': + Type '(b: number) => void' is not assignable to type '(a: A) => void': + Types of parameters 'b' and 'a' are incompatible: + Type 'number' is not assignable to type 'A': + Property 'foo' is missing in type 'Number'. -==== tests/cases/compiler/contextualTypingOfConditionalExpression2.ts (2 errors) ==== +==== tests/cases/compiler/contextualTypingOfConditionalExpression2.ts (1 errors) ==== class A { foo: number; } @@ -15,7 +18,9 @@ tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,26): error T var x2: (a: A) => void = true ? (a: C) => a.foo : (b: number) => { }; ~~ -!!! error TS2323: Type '{}' is not assignable to type '(a: A) => void'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between '(a: A) => void', '(a: C) => number', and '(b: number) => void'. +!!! error TS2322: Type '{ (a: C): number; } | { (b: number): void; }' is not assignable to type '(a: A) => void': +!!! error TS2322: Type '(b: number) => void' is not assignable to type '(a: A) => void': +!!! error TS2322: Types of parameters 'b' and 'a' are incompatible: +!!! error TS2322: Type 'number' is not assignable to type 'A': +!!! error TS2322: Property 'foo' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt index e4d8a82c47e..a524fd3be31 100644 --- a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt +++ b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt @@ -1,9 +1,12 @@ tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(2,22): error TS2339: Property 'foo' does not exist on type 'string'. +tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(3,10): error TS2346: Supplied parameters do not match any signature of call target. -==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (1 errors) ==== +==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (2 errors) ==== var f10: (x: T, b: () => (a: T) => void, y: T) => T; - f10('', () => a => a.foo, ''); // a is string, fixed by first parameter + f10('', () => a => a.foo, ''); // a is string ~~~ !!! error TS2339: Property 'foo' does not exist on type 'string'. - var r9 = f10('', () => (a => a.foo), 1); // now a should be any \ No newline at end of file + var r9 = f10('', () => (a => a.foo), 1); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.js b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.js index cf7274db8a0..55f7580b3f8 100644 --- a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.js +++ b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.js @@ -1,9 +1,9 @@ //// [contextualTypingWithFixedTypeParameters1.ts] var f10: (x: T, b: () => (a: T) => void, y: T) => T; -f10('', () => a => a.foo, ''); // a is string, fixed by first parameter -var r9 = f10('', () => (a => a.foo), 1); // now a should be any +f10('', () => a => a.foo, ''); // a is string +var r9 = f10('', () => (a => a.foo), 1); // error //// [contextualTypingWithFixedTypeParameters1.js] var f10; -f10('', function () { return function (a) { return a.foo; }; }, ''); // a is string, fixed by first parameter -var r9 = f10('', function () { return (function (a) { return a.foo; }); }, 1); // now a should be any +f10('', function () { return function (a) { return a.foo; }; }, ''); // a is string +var r9 = f10('', function () { return (function (a) { return a.foo; }); }, 1); // error diff --git a/tests/baselines/reference/contextuallyTypingOrOperator.types b/tests/baselines/reference/contextuallyTypingOrOperator.types index ee1ac4b0bba..5a20b2b921e 100644 --- a/tests/baselines/reference/contextuallyTypingOrOperator.types +++ b/tests/baselines/reference/contextuallyTypingOrOperator.types @@ -17,10 +17,10 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; >s : string var v2 = (s: string) => s.length || function (s) { s.length }; ->v2 : (s: string) => {} ->(s: string) => s.length || function (s) { s.length } : (s: string) => {} +>v2 : (s: string) => number | { (s: any): void; } +>(s: string) => s.length || function (s) { s.length } : (s: string) => number | { (s: any): void; } >s : string ->s.length || function (s) { s.length } : {} +>s.length || function (s) { s.length } : number | { (s: any): void; } >s.length : number >s : string >length : number @@ -31,10 +31,10 @@ var v2 = (s: string) => s.length || function (s) { s.length }; >length : any var v3 = (s: string) => s.length || function (s: number) { return 1 }; ->v3 : (s: string) => {} ->(s: string) => s.length || function (s: number) { return 1 } : (s: string) => {} +>v3 : (s: string) => number | { (s: number): number; } +>(s: string) => s.length || function (s: number) { return 1 } : (s: string) => number | { (s: number): number; } >s : string ->s.length || function (s: number) { return 1 } : {} +>s.length || function (s: number) { return 1 } : number | { (s: number): number; } >s.length : number >s : string >length : number @@ -42,10 +42,10 @@ var v3 = (s: string) => s.length || function (s: number) { return 1 }; >s : number var v4 = (s: number) => 1 || function (s: string) { return s.length }; ->v4 : (s: number) => {} ->(s: number) => 1 || function (s: string) { return s.length } : (s: number) => {} +>v4 : (s: number) => number | { (s: string): number; } +>(s: number) => 1 || function (s: string) { return s.length } : (s: number) => number | { (s: string): number; } >s : number ->1 || function (s: string) { return s.length } : {} +>1 || function (s: string) { return s.length } : number | { (s: string): number; } >function (s: string) { return s.length } : (s: string) => number >s : string >s.length : number diff --git a/tests/baselines/reference/contextuallyTypingOrOperator2.types b/tests/baselines/reference/contextuallyTypingOrOperator2.types index 57c9992436d..b46d0c0aedb 100644 --- a/tests/baselines/reference/contextuallyTypingOrOperator2.types +++ b/tests/baselines/reference/contextuallyTypingOrOperator2.types @@ -17,10 +17,10 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; >s : string var v2 = (s: string) => s.length || function (s) { s.aaa }; ->v2 : (s: string) => {} ->(s: string) => s.length || function (s) { s.aaa } : (s: string) => {} +>v2 : (s: string) => number | { (s: any): void; } +>(s: string) => s.length || function (s) { s.aaa } : (s: string) => number | { (s: any): void; } >s : string ->s.length || function (s) { s.aaa } : {} +>s.length || function (s) { s.aaa } : number | { (s: any): void; } >s.length : number >s : string >length : number diff --git a/tests/baselines/reference/defaultBestCommonTypesHaveDecls.errors.txt b/tests/baselines/reference/defaultBestCommonTypesHaveDecls.errors.txt index ada7f83af3d..21296783f28 100644 --- a/tests/baselines/reference/defaultBestCommonTypesHaveDecls.errors.txt +++ b/tests/baselines/reference/defaultBestCommonTypesHaveDecls.errors.txt @@ -1,31 +1,27 @@ -tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(4,6): error TS2339: Property 'length' does not exist on type '{}'. -tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(10,6): error TS2339: Property 'length' does not exist on type 'Object'. -tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(18,27): error TS2339: Property 'length' does not exist on type '{}'. +tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(2,6): error TS2339: Property 'length' does not exist on type '{}'. +tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(5,6): error TS2339: Property 'length' does not exist on type 'Object'. +tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(8,14): error TS2346: Supplied parameters do not match any signature of call target. ==== tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts (3 errors) ==== - var obj1: {}; - obj1.length; ~~~~~~ !!! error TS2339: Property 'length' does not exist on type '{}'. - - var obj2: Object; - obj2.length; ~~~~~~ !!! error TS2339: Property 'length' does not exist on type 'Object'. - - function concat(x: T, y: T): T { return null; } + var result = concat(1, ""); // error + ~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var elementCount = result.length; - var result = concat(1, ""); + function concat2(x: T, y: U) { return null; } + var result2 = concat2(1, ""); // result2 will be number|string + var elementCount2 = result.length; - var elementCount = result.length; // would like to get an error by now - ~~~~~~ -!!! error TS2339: Property 'length' does not exist on type '{}'. \ No newline at end of file diff --git a/tests/baselines/reference/defaultBestCommonTypesHaveDecls.js b/tests/baselines/reference/defaultBestCommonTypesHaveDecls.js index 59935cc53af..98e135cc712 100644 --- a/tests/baselines/reference/defaultBestCommonTypesHaveDecls.js +++ b/tests/baselines/reference/defaultBestCommonTypesHaveDecls.js @@ -1,22 +1,18 @@ //// [defaultBestCommonTypesHaveDecls.ts] - var obj1: {}; - obj1.length; - - var obj2: Object; - obj2.length; - - function concat(x: T, y: T): T { return null; } +var result = concat(1, ""); // error +var elementCount = result.length; -var result = concat(1, ""); +function concat2(x: T, y: U) { return null; } +var result2 = concat2(1, ""); // result2 will be number|string +var elementCount2 = result.length; -var elementCount = result.length; // would like to get an error by now //// [defaultBestCommonTypesHaveDecls.js] @@ -27,5 +23,10 @@ obj2.length; function concat(x, y) { return null; } -var result = concat(1, ""); -var elementCount = result.length; // would like to get an error by now +var result = concat(1, ""); // error +var elementCount = result.length; +function concat2(x, y) { + return null; +} +var result2 = concat2(1, ""); // result2 will be number|string +var elementCount2 = result.length; diff --git a/tests/baselines/reference/enumBasics.types b/tests/baselines/reference/enumBasics.types index f775295891a..696e68eded2 100644 --- a/tests/baselines/reference/enumBasics.types +++ b/tests/baselines/reference/enumBasics.types @@ -157,8 +157,8 @@ enum E9 { // (refer to .js to validate) // Enum constant members are propagated var doNotPropagate = [ ->doNotPropagate : {}[] ->[ E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z] : {}[] +>doNotPropagate : Array +>[ E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z] : Array E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z >E8.B : E8 @@ -183,8 +183,8 @@ var doNotPropagate = [ ]; // Enum computed members are not propagated var doPropagate = [ ->doPropagate : {}[] ->[ E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C] : {}[] +>doPropagate : Array +>[ E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C] : Array E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C >E9.A : E9 diff --git a/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.errors.txt b/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.errors.txt new file mode 100644 index 00000000000..d9416eb4c25 --- /dev/null +++ b/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts(2,1): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts (1 errors) ==== + function bar(item1: T, item2: T) { } + bar(1, ""); // Should be ok + ~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.types b/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.types deleted file mode 100644 index 95214571df9..00000000000 --- a/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.types +++ /dev/null @@ -1,13 +0,0 @@ -=== tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts === -function bar(item1: T, item2: T) { } ->bar : (item1: T, item2: T) => void ->T : T ->item1 : T ->T : T ->item2 : T ->T : T - -bar(1, ""); // Should be ok ->bar(1, "") : void ->bar : (item1: T, item2: T) => void - diff --git a/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt b/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt index b653bc01f55..66e8a2a66df 100644 --- a/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt +++ b/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt @@ -7,7 +7,7 @@ tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDec tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(40,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'I', but here has type 'C2'. tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(43,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'f' must be of type '(x: string) => number', but here has type '(x: number) => string'. tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(46,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. -tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(47,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '{}[]'. +tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(47,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'Array>'. tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(50,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'D[]', but here has type 'D[]'. tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(53,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'm' must be of type 'typeof M', but here has type 'typeof A'. @@ -79,7 +79,7 @@ tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDec !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. for( var arr = [new C(), new C2(), new D()];;){} ~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '{}[]'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'Array>'. for(var arr2 = [new D()];;){} for( var arr2 = new Array>();;){} diff --git a/tests/baselines/reference/generatedContextualTyping.types b/tests/baselines/reference/generatedContextualTyping.types index 57b5408eabe..c609c6aec9c 100644 --- a/tests/baselines/reference/generatedContextualTyping.types +++ b/tests/baselines/reference/generatedContextualTyping.types @@ -127,11 +127,11 @@ var x12: Genric = { func: n => { return [d1, d2]; } }; >x12 : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -243,11 +243,11 @@ class x24 { member: Genric = { func: n => { return [d1, d2]; } } } >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -359,11 +359,11 @@ class x36 { private member: Genric = { func: n => { return [d1, d2]; } } } >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -475,11 +475,11 @@ class x48 { public member: Genric = { func: n => { return [d1, d2]; } } } >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -591,11 +591,11 @@ class x60 { static member: Genric = { func: n => { return [d1, d2]; } } } >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -707,11 +707,11 @@ class x72 { private static member: Genric = { func: n => { return [d1, d2] >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -823,11 +823,11 @@ class x84 { public static member: Genric = { func: n => { return [d1, d2]; >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -939,11 +939,11 @@ class x96 { constructor(parm: Genric = { func: n => { return [d1, d2]; } } >parm : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1055,11 +1055,11 @@ class x108 { constructor(public parm: Genric = { func: n => { return [d1, >parm : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1171,11 +1171,11 @@ class x120 { constructor(private parm: Genric = { func: n => { return [d1, >parm : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1287,11 +1287,11 @@ function x132(parm: Genric = { func: n => { return [d1, d2]; } }) { } >parm : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1391,11 +1391,11 @@ function x144(): Genric { return { func: n => { return [d1, d2]; } }; } >x144 : () => Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1539,18 +1539,18 @@ function x156(): Genric { return { func: n => { return [d1, d2]; } }; retu >x156 : () => Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1661,12 +1661,12 @@ var x168: () => Genric = () => { return { func: n => { return [d1, d2]; } >x168 : () => Genric >Genric : Genric >Base : Base ->() => { return { func: n => { return [d1, d2]; } }; } : () => { func: (n: Base[]) => {}[]; } ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>() => { return { func: n => { return [d1, d2]; } }; } : () => { func: (n: Base[]) => Array; } +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1777,12 +1777,12 @@ var x180: () => Genric = function() { return { func: n => { return [d1, d2 >x180 : () => Genric >Genric : Genric >Base : Base ->function() { return { func: n => { return [d1, d2]; } }; } : () => { func: (n: Base[]) => {}[]; } ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>function() { return { func: n => { return [d1, d2]; } }; } : () => { func: (n: Base[]) => Array; } +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1894,11 +1894,11 @@ module x192 { var t: Genric = { func: n => { return [d1, d2]; } }; } >t : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2010,11 +2010,11 @@ module x204 { export var t: Genric = { func: n => { return [d1, d2]; } }; >t : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2098,11 +2098,11 @@ var x216 = >{ func: n => { return [d1, d2]; } }; >>{ func: n => { return [d1, d2]; } } : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2323,13 +2323,13 @@ var x236: Genric; x236 = { func: n => { return [d1, d2]; } }; >x236 : Genric >Genric : Genric >Base : Base ->x236 = { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } +>x236 = { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } >x236 : Genric ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2463,13 +2463,13 @@ var x248: { n: Genric; } = { n: { func: n => { return [d1, d2]; } } }; >n : Genric >Genric : Genric >Base : Base ->{ n: { func: n => { return [d1, d2]; } } } : { n: { func: (n: Base[]) => {}[]; }; } ->n : { func: (n: Base[]) => {}[]; } ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ n: { func: n => { return [d1, d2]; } } } : { n: { func: (n: Base[]) => Array; }; } +>n : { func: (n: Base[]) => Array; } +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2543,11 +2543,11 @@ var x260: Genric[] = [{ func: n => { return [d1, d2]; } }]; >Genric : Genric >Base : Base >[{ func: n => { return [d1, d2]; } }] : Genric[] ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2976,18 +2976,18 @@ var x296: Genric = true ? { func: n => { return [d1, d2]; } } : { func: n >Genric : Genric >Base : Base >true ? { func: n => { return [d1, d2]; } } : { func: n => { return [d1, d2]; } } : Genric ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3111,11 +3111,11 @@ var x308: Genric = true ? undefined : { func: n => { return [d1, d2]; } }; >Base : Base >true ? undefined : { func: n => { return [d1, d2]; } } : Genric >undefined : undefined ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3238,11 +3238,11 @@ var x320: Genric = true ? { func: n => { return [d1, d2]; } } : undefined; >Genric : Genric >Base : Base >true ? { func: n => { return [d1, d2]; } } : undefined : Genric ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3379,11 +3379,11 @@ function x332(n: Genric) { }; x332({ func: n => { return [d1, d2]; } }); >Base : Base >x332({ func: n => { return [d1, d2]; } }) : void >x332 : (n: Genric) => void ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3543,11 +3543,11 @@ var x344 = (n: Genric) => n; x344({ func: n => { return [d1, d2]; } }); >n : Genric >x344({ func: n => { return [d1, d2]; } }) : Genric >x344 : (n: Genric) => Genric ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3695,11 +3695,11 @@ var x356 = function(n: Genric) { }; x356({ func: n => { return [d1, d2]; } >Base : Base >x356({ func: n => { return [d1, d2]; } }) : void >x356 : (n: Genric) => void ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } +>func : (n: Base[]) => Array +>n => { return [d1, d2]; } : (n: Base[]) => Array >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 diff --git a/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types b/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types index 2ac2483c405..f16e747d41e 100644 --- a/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types +++ b/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types @@ -49,7 +49,7 @@ _.all([true, 1, null, 'yes'], _.identity); >_.all : (list: T[], iterator?: Underscore.Iterator, context?: any) => boolean >_ : Underscore.Static >all : (list: T[], iterator?: Underscore.Iterator, context?: any) => boolean ->[true, 1, null, 'yes'] : {}[] +>[true, 1, null, 'yes'] : Array >_.identity : (value: T) => T >_ : Underscore.Static >identity : (value: T) => T diff --git a/tests/baselines/reference/genericCallWithArrayLiteralArgs.types b/tests/baselines/reference/genericCallWithArrayLiteralArgs.types index c79efb0792c..a6a75f9bd13 100644 --- a/tests/baselines/reference/genericCallWithArrayLiteralArgs.types +++ b/tests/baselines/reference/genericCallWithArrayLiteralArgs.types @@ -40,10 +40,10 @@ var r3 = foo([]); // number[] >[] : number[] var r4 = foo([1, '']); // {}[] ->r4 : {}[] ->foo([1, '']) : {}[] +>r4 : Array +>foo([1, '']) : Array >foo : (t: T) => T ->[1, ''] : {}[] +>[1, ''] : Array var r5 = foo([1, '']); // any[] >r5 : any[] diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt b/tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt new file mode 100644 index 00000000000..36a22868333 --- /dev/null +++ b/tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt @@ -0,0 +1,58 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(26,18): error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(30,15): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(33,15): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(34,16): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(35,23): error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts (5 errors) ==== + // Generic functions used as arguments for function typed parameters are not used to make inferences from + // Using function arguments, no errors expected + + function foo(x: (a: T) => T) { + return x(null); + } + + var r = foo((x: U) => ''); // {} + var r2 = foo((x: U) => ''); // string + var r3 = foo(x => ''); // {} + + function foo2(x: T, cb: (a: T) => U) { + return cb(x); + } + + var r4 = foo2(1, function (a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions + var r5 = foo2(1, (a) => ''); // string + var r6 = foo2('', (a: Z) => 1); + + function foo3(x: T, cb: (a: T) => U, y: U) { + return cb(x); + } + + var r7 = foo3(1, (a: Z) => '', ''); // string + + var r8 = foo3(1, function (a) { return '' }, 1); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + var r9 = foo3(1, (a) => '', ''); // string + + function other(t: T, u: U) { + var r10 = foo2(1, (x: T) => ''); // error + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r10 = foo2(1, (x) => ''); // string + + var r11 = foo3(1, (x: T) => '', ''); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r11b = foo3(1, (x: T) => '', 1); // error + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r12 = foo3(1, function (a) { return '' }, 1); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + } \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments.js b/tests/baselines/reference/genericCallWithFunctionTypedArguments.js index 8e844cfbc5a..fed1d4ca990 100644 --- a/tests/baselines/reference/genericCallWithFunctionTypedArguments.js +++ b/tests/baselines/reference/genericCallWithFunctionTypedArguments.js @@ -24,16 +24,16 @@ function foo3(x: T, cb: (a: T) => U, y: U) { var r7 = foo3(1, (a: Z) => '', ''); // string -var r8 = foo3(1, function (a) { return '' }, 1); // {} +var r8 = foo3(1, function (a) { return '' }, 1); // error var r9 = foo3(1, (a) => '', ''); // string function other(t: T, u: U) { - var r10 = foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made + var r10 = foo2(1, (x: T) => ''); // error var r10 = foo2(1, (x) => ''); // string - var r11 = foo3(1, (x: T) => '', ''); // string - var r11b = foo3(1, (x: T) => '', 1); // {} - var r12 = foo3(1, function (a) { return '' }, 1); // {} + var r11 = foo3(1, (x: T) => '', ''); // error + var r11b = foo3(1, (x: T) => '', 1); // error + var r12 = foo3(1, function (a) { return '' }, 1); // error } //// [genericCallWithFunctionTypedArguments.js] @@ -59,14 +59,14 @@ function foo3(x, cb, y) { var r7 = foo3(1, function (a) { return ''; }, ''); // string var r8 = foo3(1, function (a) { return ''; -}, 1); // {} +}, 1); // error var r9 = foo3(1, function (a) { return ''; }, ''); // string function other(t, u) { - var r10 = foo2(1, function (x) { return ''; }); // string, non-generic signature allows inferences to be made + var r10 = foo2(1, function (x) { return ''; }); // error var r10 = foo2(1, function (x) { return ''; }); // string - var r11 = foo3(1, function (x) { return ''; }, ''); // string - var r11b = foo3(1, function (x) { return ''; }, 1); // {} + var r11 = foo3(1, function (x) { return ''; }, ''); // error + var r11b = foo3(1, function (x) { return ''; }, 1); // error var r12 = foo3(1, function (a) { return ''; - }, 1); // {} + }, 1); // error } diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments.types b/tests/baselines/reference/genericCallWithFunctionTypedArguments.types deleted file mode 100644 index 2d3b234d0e1..00000000000 --- a/tests/baselines/reference/genericCallWithFunctionTypedArguments.types +++ /dev/null @@ -1,173 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts === -// Generic functions used as arguments for function typed parameters are not used to make inferences from -// Using function arguments, no errors expected - -function foo(x: (a: T) => T) { ->foo : (x: (a: T) => T) => T ->T : T ->x : (a: T) => T ->a : T ->T : T ->T : T - - return x(null); ->x(null) : T ->x : (a: T) => T -} - -var r = foo((x: U) => ''); // {} ->r : {} ->foo((x: U) => '') : {} ->foo : (x: (a: T) => T) => T ->(x: U) => '' : (x: U) => string ->U : U ->x : U ->U : U - -var r2 = foo((x: U) => ''); // string ->r2 : string ->foo((x: U) => '') : string ->foo : (x: (a: T) => T) => T ->(x: U) => '' : (x: U) => string ->U : U ->x : U ->U : U - -var r3 = foo(x => ''); // {} ->r3 : {} ->foo(x => '') : {} ->foo : (x: (a: T) => T) => T ->x => '' : (x: {}) => string ->x : {} - -function foo2(x: T, cb: (a: T) => U) { ->foo2 : (x: T, cb: (a: T) => U) => U ->T : T ->U : U ->x : T ->T : T ->cb : (a: T) => U ->a : T ->T : T ->U : U - - return cb(x); ->cb(x) : U ->cb : (a: T) => U ->x : T -} - -var r4 = foo2(1, function (a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions ->r4 : string ->foo2(1, function (a: Z) { return '' }) : string ->foo2 : (x: T, cb: (a: T) => U) => U ->function (a: Z) { return '' } : (a: Z) => string ->Z : Z ->a : Z ->Z : Z - -var r5 = foo2(1, (a) => ''); // string ->r5 : string ->foo2(1, (a) => '') : string ->foo2 : (x: T, cb: (a: T) => U) => U ->(a) => '' : (a: number) => string ->a : number - -var r6 = foo2('', (a: Z) => 1); ->r6 : number ->foo2('', (a: Z) => 1) : number ->foo2 : (x: T, cb: (a: T) => U) => U ->(a: Z) => 1 : (a: Z) => number ->Z : Z ->a : Z ->Z : Z - -function foo3(x: T, cb: (a: T) => U, y: U) { ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->T : T ->U : U ->x : T ->T : T ->cb : (a: T) => U ->a : T ->T : T ->U : U ->y : U ->U : U - - return cb(x); ->cb(x) : U ->cb : (a: T) => U ->x : T -} - -var r7 = foo3(1, (a: Z) => '', ''); // string ->r7 : string ->foo3(1, (a: Z) => '', '') : string ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(a: Z) => '' : (a: Z) => string ->Z : Z ->a : Z ->Z : Z - -var r8 = foo3(1, function (a) { return '' }, 1); // {} ->r8 : {} ->foo3(1, function (a) { return '' }, 1) : {} ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->function (a) { return '' } : (a: number) => string ->a : number - -var r9 = foo3(1, (a) => '', ''); // string ->r9 : string ->foo3(1, (a) => '', '') : string ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(a) => '' : (a: number) => string ->a : number - -function other(t: T, u: U) { ->other : (t: T, u: U) => void ->T : T ->U : U ->t : T ->T : T ->u : U ->U : U - - var r10 = foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made ->r10 : string ->foo2(1, (x: T) => '') : string ->foo2 : (x: T, cb: (a: T) => U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r10 = foo2(1, (x) => ''); // string ->r10 : string ->foo2(1, (x) => '') : string ->foo2 : (x: T, cb: (a: T) => U) => U ->(x) => '' : (x: number) => string ->x : number - - var r11 = foo3(1, (x: T) => '', ''); // string ->r11 : string ->foo3(1, (x: T) => '', '') : string ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r11b = foo3(1, (x: T) => '', 1); // {} ->r11b : {} ->foo3(1, (x: T) => '', 1) : {} ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r12 = foo3(1, function (a) { return '' }, 1); // {} ->r12 : {} ->foo3(1, function (a) { return '' }, 1) : {} ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->function (a) { return '' } : (a: number) => string ->a : number -} diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.errors.txt b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.errors.txt new file mode 100644 index 00000000000..083d197bbb4 --- /dev/null +++ b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.errors.txt @@ -0,0 +1,50 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts(29,10): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts(40,10): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts (2 errors) ==== + // Generic functions used as arguments for function typed parameters are not used to make inferences from + // Using construct signature arguments, no errors expected + + function foo(x: new(a: T) => T) { + return new x(null); + } + + interface I { + new (x: T): T; + } + interface I2 { + new (x: T): T; + } + var i: I; + var i2: I2; + var a: { + new (x: T): T; + } + + var r = foo(i); // any + var r2 = foo(i); // string + var r3 = foo(i2); // string + var r3b = foo(a); // any + + function foo2(x: T, cb: new(a: T) => U) { + return new cb(x); + } + + var r4 = foo2(1, i2); // error + ~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r4b = foo2(1, a); // any + var r5 = foo2(1, i); // any + var r6 = foo2('', i2); // string + + function foo3(x: T, cb: new(a: T) => U, y: U) { + return new cb(x); + } + + var r7 = foo3(null, i, ''); // any + var r7b = foo3(null, a, ''); // any + var r8 = foo3(1, i2, 1); // error + ~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r9 = foo3('', i2, ''); // string \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.js b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.js index ca9b79c3507..7e9b7886fb4 100644 --- a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.js +++ b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.js @@ -27,7 +27,7 @@ function foo2(x: T, cb: new(a: T) => U) { return new cb(x); } -var r4 = foo2(1, i2); // string, instantiated generic +var r4 = foo2(1, i2); // error var r4b = foo2(1, a); // any var r5 = foo2(1, i); // any var r6 = foo2('', i2); // string @@ -38,7 +38,7 @@ function foo3(x: T, cb: new(a: T) => U, y: U) { var r7 = foo3(null, i, ''); // any var r7b = foo3(null, a, ''); // any -var r8 = foo3(1, i2, 1); // {} +var r8 = foo3(1, i2, 1); // error var r9 = foo3('', i2, ''); // string //// [genericCallWithFunctionTypedArguments2.js] @@ -57,7 +57,7 @@ var r3b = foo(a); // any function foo2(x, cb) { return new cb(x); } -var r4 = foo2(1, i2); // string, instantiated generic +var r4 = foo2(1, i2); // error var r4b = foo2(1, a); // any var r5 = foo2(1, i); // any var r6 = foo2('', i2); // string @@ -66,5 +66,5 @@ function foo3(x, cb, y) { } var r7 = foo3(null, i, ''); // any var r7b = foo3(null, a, ''); // any -var r8 = foo3(1, i2, 1); // {} +var r8 = foo3(1, i2, 1); // error var r9 = foo3('', i2, ''); // string diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.types b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.types deleted file mode 100644 index 89d7afd94e2..00000000000 --- a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.types +++ /dev/null @@ -1,161 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts === -// Generic functions used as arguments for function typed parameters are not used to make inferences from -// Using construct signature arguments, no errors expected - -function foo(x: new(a: T) => T) { ->foo : (x: new (a: T) => T) => T ->T : T ->x : new (a: T) => T ->a : T ->T : T ->T : T - - return new x(null); ->new x(null) : T ->x : new (a: T) => T -} - -interface I { ->I : I - - new (x: T): T; ->T : T ->x : T ->T : T ->T : T -} -interface I2 { ->I2 : I2 ->T : T - - new (x: T): T; ->x : T ->T : T ->T : T -} -var i: I; ->i : I ->I : I - -var i2: I2; ->i2 : I2 ->I2 : I2 - -var a: { ->a : new (x: T) => T - - new (x: T): T; ->T : T ->x : T ->T : T ->T : T -} - -var r = foo(i); // any ->r : any ->foo(i) : any ->foo : (x: new (a: T) => T) => T ->i : I - -var r2 = foo(i); // string ->r2 : string ->foo(i) : string ->foo : (x: new (a: T) => T) => T ->i : I - -var r3 = foo(i2); // string ->r3 : string ->foo(i2) : string ->foo : (x: new (a: T) => T) => T ->i2 : I2 - -var r3b = foo(a); // any ->r3b : any ->foo(a) : any ->foo : (x: new (a: T) => T) => T ->a : new (x: T) => T - -function foo2(x: T, cb: new(a: T) => U) { ->foo2 : (x: T, cb: new (a: T) => U) => U ->T : T ->U : U ->x : T ->T : T ->cb : new (a: T) => U ->a : T ->T : T ->U : U - - return new cb(x); ->new cb(x) : U ->cb : new (a: T) => U ->x : T -} - -var r4 = foo2(1, i2); // string, instantiated generic ->r4 : string ->foo2(1, i2) : string ->foo2 : (x: T, cb: new (a: T) => U) => U ->i2 : I2 - -var r4b = foo2(1, a); // any ->r4b : any ->foo2(1, a) : any ->foo2 : (x: T, cb: new (a: T) => U) => U ->a : new (x: T) => T - -var r5 = foo2(1, i); // any ->r5 : any ->foo2(1, i) : any ->foo2 : (x: T, cb: new (a: T) => U) => U ->i : I - -var r6 = foo2('', i2); // string ->r6 : string ->foo2('', i2) : string ->foo2 : (x: T, cb: new (a: T) => U) => U ->i2 : I2 - -function foo3(x: T, cb: new(a: T) => U, y: U) { ->foo3 : (x: T, cb: new (a: T) => U, y: U) => U ->T : T ->U : U ->x : T ->T : T ->cb : new (a: T) => U ->a : T ->T : T ->U : U ->y : U ->U : U - - return new cb(x); ->new cb(x) : U ->cb : new (a: T) => U ->x : T -} - -var r7 = foo3(null, i, ''); // any ->r7 : any ->foo3(null, i, '') : any ->foo3 : (x: T, cb: new (a: T) => U, y: U) => U ->i : I - -var r7b = foo3(null, a, ''); // any ->r7b : any ->foo3(null, a, '') : any ->foo3 : (x: T, cb: new (a: T) => U, y: U) => U ->a : new (x: T) => T - -var r8 = foo3(1, i2, 1); // {} ->r8 : {} ->foo3(1, i2, 1) : {} ->foo3 : (x: T, cb: new (a: T) => U, y: U) => U ->i2 : I2 - -var r9 = foo3('', i2, ''); // string ->r9 : string ->foo3('', i2, '') : string ->foo3 : (x: T, cb: new (a: T) => U, y: U) => U ->i2 : I2 - diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt index 7f4fa26aad1..55318f268bd 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt @@ -1,51 +1,106 @@ -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(14,17): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'. -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(15,18): error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'. -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(24,19): error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(36,32): error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(10,29): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(15,21): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(16,22): error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(25,23): error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(37,36): error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(50,21): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(51,22): error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(60,23): error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(67,51): error TS2304: Cannot find name 'U'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(67,57): error TS2304: Cannot find name 'U'. -==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts (4 errors) ==== +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts (10 errors) ==== // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, // the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. - function foo(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; - } + module onlyT { + function foo(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } - var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); + var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. - function other2(x: T) { - var r7 = foo((a: T) => a, (b: T) => b); // T => T - // BUG 835518 - var r9 = r7(new Date()); // should be ok - ~~~~~~~~~~ + function other2(x: T) { + var r7 = foo((a: T) => a, (b: T) => b); // T => T + // BUG 835518 + var r9 = r7(new Date()); // should be ok + ~~~~~~~~~~ !!! error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'. - var r10 = r7(1); // error - ~ + var r10 = r7(1); // error + ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'. - } + } - function foo2(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; - } + function foo2(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } - function other3(x: T) { - var r7 = foo2((a: T) => a, (b: T) => b); // error - ~~~~~~~~~~~ + function other3(x: T) { + var r7 = foo2((a: T) => a, (b: T) => b); // error + ~~~~~~~~~~~ !!! error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. - var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date + var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date + } + + enum E { A } + enum F { A } + + function foo3(x: T, a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error + ~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'. } - enum E { A } - enum F { A } + module TU { + function foo(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } - function foo3(x: T, a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; - } + var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); - var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error - ~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'. \ No newline at end of file + function other2(x: T) { + var r7 = foo((a: T) => a, (b: T) => b); + var r9 = r7(new Date()); + ~~~~~~~~~~ +!!! error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'. + var r10 = r7(1); + ~ +!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'. + } + + function foo2(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } + + function other3(x: T) { + var r7 = foo2((a: T) => a, (b: T) => b); + ~~~~~~~~~~~ +!!! error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. + var r7b = foo2((a) => a, (b) => b); + } + + enum E { A } + enum F { A } + + function foo3(x: T, a: (x: T) => T, b: (x: U) => U) { + ~ +!!! error TS2304: Cannot find name 'U'. + ~ +!!! error TS2304: Cannot find name 'U'. + var r: (x: T) => T; + return r; + } + + var r7 = foo3(E.A, (x) => E.A, (x) => F.A); + } \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js index 7dc955b6172..7acdcc32536 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js @@ -2,72 +2,146 @@ // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, // the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. -function foo(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; +module onlyT { + function foo(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); + + function other2(x: T) { + var r7 = foo((a: T) => a, (b: T) => b); // T => T + // BUG 835518 + var r9 = r7(new Date()); // should be ok + var r10 = r7(1); // error + } + + function foo2(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + function other3(x: T) { + var r7 = foo2((a: T) => a, (b: T) => b); // error + var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date + } + + enum E { A } + enum F { A } + + function foo3(x: T, a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error } -var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); +module TU { + function foo(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } -function other2(x: T) { - var r7 = foo((a: T) => a, (b: T) => b); // T => T - // BUG 835518 - var r9 = r7(new Date()); // should be ok - var r10 = r7(1); // error -} + var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); -function foo2(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; -} + function other2(x: T) { + var r7 = foo((a: T) => a, (b: T) => b); + var r9 = r7(new Date()); + var r10 = r7(1); + } -function other3(x: T) { - var r7 = foo2((a: T) => a, (b: T) => b); // error - var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date -} + function foo2(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } -enum E { A } -enum F { A } + function other3(x: T) { + var r7 = foo2((a: T) => a, (b: T) => b); + var r7b = foo2((a) => a, (b) => b); + } -function foo3(x: T, a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; -} + enum E { A } + enum F { A } -var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error + function foo3(x: T, a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } + + var r7 = foo3(E.A, (x) => E.A, (x) => F.A); +} //// [genericCallWithGenericSignatureArguments2.js] // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, // the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. -function foo(a, b) { - var r; - return r; -} -var r1 = foo(function (x) { return 1; }, function (x) { return ''; }); -function other2(x) { - var r7 = foo(function (a) { return a; }, function (b) { return b; }); // T => T - // BUG 835518 - var r9 = r7(new Date()); // should be ok - var r10 = r7(1); // error -} -function foo2(a, b) { - var r; - return r; -} -function other3(x) { - var r7 = foo2(function (a) { return a; }, function (b) { return b; }); // error - var r7b = foo2(function (a) { return a; }, function (b) { return b; }); // valid, T is inferred to be Date -} -var E; -(function (E) { - E[E["A"] = 0] = "A"; -})(E || (E = {})); -var F; -(function (F) { - F[F["A"] = 0] = "A"; -})(F || (F = {})); -function foo3(x, a, b) { - var r; - return r; -} -var r7 = foo3(0 /* A */, function (x) { return 0 /* A */; }, function (x) { return 0 /* A */; }); // error +var onlyT; +(function (onlyT) { + function foo(a, b) { + var r; + return r; + } + var r1 = foo(function (x) { return 1; }, function (x) { return ''; }); + function other2(x) { + var r7 = foo(function (a) { return a; }, function (b) { return b; }); // T => T + // BUG 835518 + var r9 = r7(new Date()); // should be ok + var r10 = r7(1); // error + } + function foo2(a, b) { + var r; + return r; + } + function other3(x) { + var r7 = foo2(function (a) { return a; }, function (b) { return b; }); // error + var r7b = foo2(function (a) { return a; }, function (b) { return b; }); // valid, T is inferred to be Date + } + var E; + (function (E) { + E[E["A"] = 0] = "A"; + })(E || (E = {})); + var F; + (function (F) { + F[F["A"] = 0] = "A"; + })(F || (F = {})); + function foo3(x, a, b) { + var r; + return r; + } + var r7 = foo3(0 /* A */, function (x) { return 0 /* A */; }, function (x) { return 0 /* A */; }); // error +})(onlyT || (onlyT = {})); +var TU; +(function (TU) { + function foo(a, b) { + var r; + return r; + } + var r1 = foo(function (x) { return 1; }, function (x) { return ''; }); + function other2(x) { + var r7 = foo(function (a) { return a; }, function (b) { return b; }); + var r9 = r7(new Date()); + var r10 = r7(1); + } + function foo2(a, b) { + var r; + return r; + } + function other3(x) { + var r7 = foo2(function (a) { return a; }, function (b) { return b; }); + var r7b = foo2(function (a) { return a; }, function (b) { return b; }); + } + var E; + (function (E) { + E[E["A"] = 0] = "A"; + })(E || (E = {})); + var F; + (function (F) { + F[F["A"] = 0] = "A"; + })(F || (F = {})); + function foo3(x, a, b) { + var r; + return r; + } + var r7 = foo3(0 /* A */, function (x) { return 0 /* A */; }, function (x) { return 0 /* A */; }); +})(TU || (TU = {})); diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt new file mode 100644 index 00000000000..0a42d940625 --- /dev/null +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt @@ -0,0 +1,42 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts(32,11): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts(33,11): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts (2 errors) ==== + // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, + // the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. + + function foo(x: T, a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + var r1 = foo('', (x: string) => '', (x: Object) => null); // any => any + var r1ii = foo('', (x) => '', (x) => null); // string => string + var r2 = foo('', (x: string) => '', (x: Object) => ''); // string => string + var r3 = foo(null, (x: Object) => '', (x: string) => ''); // Object => Object + var r4 = foo(null, (x) => '', (x) => ''); // any => any + var r5 = foo(new Object(), (x) => '', (x) => ''); // Object => Object + + enum E { A } + enum F { A } + + var r6 = foo(E.A, (x: number) => E.A, (x: F) => F.A); // number => number + + + function foo2(x: T, a: (x: T) => U, b: (x: T) => U) { + var r: (x: T) => U; + return r; + } + + var r8 = foo2('', (x) => '', (x) => null); // string => string + var r9 = foo2(null, (x) => '', (x) => ''); // any => any + var r10 = foo2(null, (x: Object) => '', (x: string) => ''); // Object => Object + + var x: (a: string) => boolean; + var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js index 8ffb4f9970b..ca28878daa3 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js @@ -30,8 +30,8 @@ var r9 = foo2(null, (x) => '', (x) => ''); // any => any var r10 = foo2(null, (x: Object) => '', (x: string) => ''); // Object => Object var x: (a: string) => boolean; -var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // {} => {} -var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // (string => boolean) => {} +var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // error +var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // error //// [genericCallWithGenericSignatureArguments3.js] // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, @@ -63,5 +63,5 @@ var r8 = foo2('', function (x) { return ''; }, function (x) { return null; }); / var r9 = foo2(null, function (x) { return ''; }, function (x) { return ''; }); // any => any var r10 = foo2(null, function (x) { return ''; }, function (x) { return ''; }); // Object => Object var x; -var r11 = foo2(x, function (a1) { return function (n) { return 1; }; }, function (a2) { return 2; }); // {} => {} -var r12 = foo2(x, function (a1) { return function (n) { return 1; }; }, function (a2) { return 2; }); // (string => boolean) => {} +var r11 = foo2(x, function (a1) { return function (n) { return 1; }; }, function (a2) { return 2; }); // error +var r12 = foo2(x, function (a1) { return function (n) { return 1; }; }, function (a2) { return 2; }); // error diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.types b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.types deleted file mode 100644 index 2c0d21a5a07..00000000000 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.types +++ /dev/null @@ -1,202 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts === -// When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, -// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. - -function foo(x: T, a: (x: T) => T, b: (x: T) => T) { ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->T : T ->x : T ->T : T ->a : (x: T) => T ->x : T ->T : T ->T : T ->b : (x: T) => T ->x : T ->T : T ->T : T - - var r: (x: T) => T; ->r : (x: T) => T ->x : T ->T : T ->T : T - - return r; ->r : (x: T) => T -} - -var r1 = foo('', (x: string) => '', (x: Object) => null); // any => any ->r1 : (x: any) => any ->foo('', (x: string) => '', (x: Object) => null) : (x: any) => any ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: string) => '' : (x: string) => string ->x : string ->(x: Object) => null : (x: Object) => any ->x : Object ->Object : Object - -var r1ii = foo('', (x) => '', (x) => null); // string => string ->r1ii : (x: string) => string ->foo('', (x) => '', (x) => null) : (x: string) => string ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x) => '' : (x: string) => string ->x : string ->(x) => null : (x: string) => any ->x : string - -var r2 = foo('', (x: string) => '', (x: Object) => ''); // string => string ->r2 : (x: Object) => Object ->foo('', (x: string) => '', (x: Object) => '') : (x: Object) => Object ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: string) => '' : (x: string) => string ->x : string ->(x: Object) => '' : (x: Object) => string ->x : Object ->Object : Object - -var r3 = foo(null, (x: Object) => '', (x: string) => ''); // Object => Object ->r3 : (x: Object) => Object ->foo(null, (x: Object) => '', (x: string) => '') : (x: Object) => Object ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: Object) => '' : (x: Object) => string ->x : Object ->Object : Object ->(x: string) => '' : (x: string) => string ->x : string - -var r4 = foo(null, (x) => '', (x) => ''); // any => any ->r4 : (x: any) => any ->foo(null, (x) => '', (x) => '') : (x: any) => any ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x) => '' : (x: any) => string ->x : any ->(x) => '' : (x: any) => string ->x : any - -var r5 = foo(new Object(), (x) => '', (x) => ''); // Object => Object ->r5 : (x: Object) => Object ->foo(new Object(), (x) => '', (x) => '') : (x: Object) => Object ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->new Object() : Object ->Object : { (): any; (value: any): any; new (value?: any): Object; prototype: Object; getPrototypeOf(o: any): any; getOwnPropertyDescriptor(o: any, p: string): PropertyDescriptor; getOwnPropertyNames(o: any): string[]; create(o: any, properties?: PropertyDescriptorMap): any; defineProperty(o: any, p: string, attributes: PropertyDescriptor): any; defineProperties(o: any, properties: PropertyDescriptorMap): any; seal(o: any): any; freeze(o: any): any; preventExtensions(o: any): any; isSealed(o: any): boolean; isFrozen(o: any): boolean; isExtensible(o: any): boolean; keys(o: any): string[]; } ->(x) => '' : (x: Object) => string ->x : Object ->(x) => '' : (x: Object) => string ->x : Object - -enum E { A } ->E : E ->A : E - -enum F { A } ->F : F ->A : F - -var r6 = foo(E.A, (x: number) => E.A, (x: F) => F.A); // number => number ->r6 : (x: number) => number ->foo(E.A, (x: number) => E.A, (x: F) => F.A) : (x: number) => number ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->E.A : E ->E : typeof E ->A : E ->(x: number) => E.A : (x: number) => E ->x : number ->E.A : E ->E : typeof E ->A : E ->(x: F) => F.A : (x: F) => F ->x : F ->F : F ->F.A : F ->F : typeof F ->A : F - - -function foo2(x: T, a: (x: T) => U, b: (x: T) => U) { ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->T : T ->U : U ->x : T ->T : T ->a : (x: T) => U ->x : T ->T : T ->U : U ->b : (x: T) => U ->x : T ->T : T ->U : U - - var r: (x: T) => U; ->r : (x: T) => U ->x : T ->T : T ->U : U - - return r; ->r : (x: T) => U -} - -var r8 = foo2('', (x) => '', (x) => null); // string => string ->r8 : (x: string) => any ->foo2('', (x) => '', (x) => null) : (x: string) => any ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->(x) => '' : (x: string) => string ->x : string ->(x) => null : (x: string) => any ->x : string - -var r9 = foo2(null, (x) => '', (x) => ''); // any => any ->r9 : (x: any) => string ->foo2(null, (x) => '', (x) => '') : (x: any) => string ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->(x) => '' : (x: any) => string ->x : any ->(x) => '' : (x: any) => string ->x : any - -var r10 = foo2(null, (x: Object) => '', (x: string) => ''); // Object => Object ->r10 : (x: Object) => string ->foo2(null, (x: Object) => '', (x: string) => '') : (x: Object) => string ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->(x: Object) => '' : (x: Object) => string ->x : Object ->Object : Object ->(x: string) => '' : (x: string) => string ->x : string - -var x: (a: string) => boolean; ->x : (a: string) => boolean ->a : string - -var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // {} => {} ->r11 : (x: {}) => {} ->foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2) : (x: {}) => {} ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->x : (a: string) => boolean ->(a1: (y: string) => string) => (n: Object) => 1 : (a1: (y: string) => string) => (n: Object) => number ->a1 : (y: string) => string ->y : string ->(n: Object) => 1 : (n: Object) => number ->n : Object ->Object : Object ->(a2: (z: string) => string) => 2 : (a2: (z: string) => string) => number ->a2 : (z: string) => string ->z : string - -var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // (string => boolean) => {} ->r12 : (x: (a: string) => boolean) => {} ->foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2) : (x: (a: string) => boolean) => {} ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->x : (a: string) => boolean ->(a1: (y: string) => boolean) => (n: Object) => 1 : (a1: (y: string) => boolean) => (n: Object) => number ->a1 : (y: string) => boolean ->y : string ->(n: Object) => 1 : (n: Object) => number ->n : Object ->Object : Object ->(a2: (z: string) => boolean) => 2 : (a2: (z: string) => boolean) => number ->a2 : (z: string) => boolean ->z : string - diff --git a/tests/baselines/reference/genericCallWithObjectLiteralArgs.errors.txt b/tests/baselines/reference/genericCallWithObjectLiteralArgs.errors.txt new file mode 100644 index 00000000000..856f35a57f6 --- /dev/null +++ b/tests/baselines/reference/genericCallWithObjectLiteralArgs.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts(5,9): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts (1 errors) ==== + function foo(x: { bar: T; baz: T }) { + return x; + } + + var r = foo({ bar: 1, baz: '' }); // error + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r2 = foo({ bar: 1, baz: 1 }); // T = number + var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo + var r4 = foo({ bar: 1, baz: '' }); // T = Object \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithObjectLiteralArgs.js b/tests/baselines/reference/genericCallWithObjectLiteralArgs.js index 84a630425be..2515bbef293 100644 --- a/tests/baselines/reference/genericCallWithObjectLiteralArgs.js +++ b/tests/baselines/reference/genericCallWithObjectLiteralArgs.js @@ -3,7 +3,7 @@ function foo(x: { bar: T; baz: T }) { return x; } -var r = foo({ bar: 1, baz: '' }); // T = {} +var r = foo({ bar: 1, baz: '' }); // error var r2 = foo({ bar: 1, baz: 1 }); // T = number var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo var r4 = foo({ bar: 1, baz: '' }); // T = Object @@ -12,7 +12,7 @@ var r4 = foo({ bar: 1, baz: '' }); // T = Object function foo(x) { return x; } -var r = foo({ bar: 1, baz: '' }); // T = {} +var r = foo({ bar: 1, baz: '' }); // error var r2 = foo({ bar: 1, baz: 1 }); // T = number var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo var r4 = foo({ bar: 1, baz: '' }); // T = Object diff --git a/tests/baselines/reference/genericCallWithObjectLiteralArgs.types b/tests/baselines/reference/genericCallWithObjectLiteralArgs.types deleted file mode 100644 index d23445ecbca..00000000000 --- a/tests/baselines/reference/genericCallWithObjectLiteralArgs.types +++ /dev/null @@ -1,49 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts === -function foo(x: { bar: T; baz: T }) { ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->T : T ->x : { bar: T; baz: T; } ->bar : T ->T : T ->baz : T ->T : T - - return x; ->x : { bar: T; baz: T; } -} - -var r = foo({ bar: 1, baz: '' }); // T = {} ->r : { bar: {}; baz: {}; } ->foo({ bar: 1, baz: '' }) : { bar: {}; baz: {}; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->{ bar: 1, baz: '' } : { bar: number; baz: string; } ->bar : number ->baz : string - -var r2 = foo({ bar: 1, baz: 1 }); // T = number ->r2 : { bar: number; baz: number; } ->foo({ bar: 1, baz: 1 }) : { bar: number; baz: number; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->{ bar: 1, baz: 1 } : { bar: number; baz: number; } ->bar : number ->baz : number - -var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo ->r3 : { bar: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; baz: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; } ->foo({ bar: foo, baz: foo }) : { bar: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; baz: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->{ bar: foo, baz: foo } : { bar: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; baz: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; } ->bar : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->baz : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } - -var r4 = foo({ bar: 1, baz: '' }); // T = Object ->r4 : { bar: Object; baz: Object; } ->foo({ bar: 1, baz: '' }) : { bar: Object; baz: Object; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->Object : Object ->{ bar: 1, baz: '' } : { bar: number; baz: string; } ->bar : number ->baz : string - diff --git a/tests/baselines/reference/genericCallWithObjectLiteralArguments1.errors.txt b/tests/baselines/reference/genericCallWithObjectLiteralArguments1.errors.txt index 3b3f8d43ff9..4ac64500bd1 100644 --- a/tests/baselines/reference/genericCallWithObjectLiteralArguments1.errors.txt +++ b/tests/baselines/reference/genericCallWithObjectLiteralArguments1.errors.txt @@ -1,3 +1,4 @@ +tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts(2,9): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts(4,22): error TS2345: Argument of type '{ x: number; y: string; }' is not assignable to parameter of type '{ x: number; y: number; }'. Types of property 'y' are incompatible: Type 'string' is not assignable to type 'number'. @@ -12,9 +13,11 @@ tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts(7,22): error TS23 Type 'number' is not assignable to type 'string'. -==== tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts (4 errors) ==== +==== tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts (5 errors) ==== function foo(n: { x: T; y: T }, m: T) { return m; } var x = foo({ x: 3, y: "" }, 4); // no error, x is Object, the best common type + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. // these are all errors var x2 = foo({ x: 3, y: "" }, 4); ~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgs.errors.txt b/tests/baselines/reference/genericCallWithObjectTypeArgs.errors.txt new file mode 100644 index 00000000000..dce9562a8f5 --- /dev/null +++ b/tests/baselines/reference/genericCallWithObjectTypeArgs.errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs.ts(20,9): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs.ts (1 errors) ==== + class C { + private x: string; + } + + class D { + private x: string; + } + + class X { + x: T; + } + + function foo(t: X, t2: X) { + var x: T; + return x; + } + + var c1 = new X(); + var d1 = new X(); + var r = foo(c1, d1); // error + ~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r2 = foo(c1, c1); // ok \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgs.types b/tests/baselines/reference/genericCallWithObjectTypeArgs.types deleted file mode 100644 index ddbd7d83054..00000000000 --- a/tests/baselines/reference/genericCallWithObjectTypeArgs.types +++ /dev/null @@ -1,68 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs.ts === -class C { ->C : C - - private x: string; ->x : string -} - -class D { ->D : D - - private x: string; ->x : string -} - -class X { ->X : X ->T : T - - x: T; ->x : T ->T : T -} - -function foo(t: X, t2: X) { ->foo : (t: X, t2: X) => T ->T : T ->t : X ->X : X ->T : T ->t2 : X ->X : X ->T : T - - var x: T; ->x : T ->T : T - - return x; ->x : T -} - -var c1 = new X(); ->c1 : X ->new X() : X ->X : typeof X ->C : C - -var d1 = new X(); ->d1 : X ->new X() : X ->X : typeof X ->D : D - -var r = foo(c1, d1); // error ->r : {} ->foo(c1, d1) : {} ->foo : (t: X, t2: X) => T ->c1 : X ->d1 : X - -var r2 = foo(c1, c1); // ok ->r2 : C ->foo(c1, c1) : C ->foo : (t: X, t2: X) => T ->c1 : X ->c1 : X - diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgs2.types b/tests/baselines/reference/genericCallWithObjectTypeArgs2.types index 0065811fdc1..6c8ed4e468a 100644 --- a/tests/baselines/reference/genericCallWithObjectTypeArgs2.types +++ b/tests/baselines/reference/genericCallWithObjectTypeArgs2.types @@ -22,7 +22,7 @@ class Derived2 extends Base { // returns {}[] function f(a: { x: T; y: U }) { ->f : (a: { x: T; y: U; }) => {}[] +>f : (a: { x: T; y: U; }) => Array >T : T >Base : Base >U : U @@ -34,7 +34,7 @@ function f(a: { x: T; y: U }) { >U : U return [a.x, a.y]; ->[a.x, a.y] : {}[] +>[a.x, a.y] : Array >a.x : T >a : { x: T; y: U; } >x : T @@ -44,9 +44,9 @@ function f(a: { x: T; y: U }) { } var r = f({ x: new Derived(), y: new Derived2() }); // {}[] ->r : {}[] ->f({ x: new Derived(), y: new Derived2() }) : {}[] ->f : (a: { x: T; y: U; }) => {}[] +>r : Array +>f({ x: new Derived(), y: new Derived2() }) : Array +>f : (a: { x: T; y: U; }) => Array >{ x: new Derived(), y: new Derived2() } : { x: Derived; y: Derived2; } >x : Derived >new Derived() : Derived @@ -56,9 +56,9 @@ var r = f({ x: new Derived(), y: new Derived2() }); // {}[] >Derived2 : typeof Derived2 var r2 = f({ x: new Base(), y: new Derived2() }); // {}[] ->r2 : {}[] ->f({ x: new Base(), y: new Derived2() }) : {}[] ->f : (a: { x: T; y: U; }) => {}[] +>r2 : Base[] +>f({ x: new Base(), y: new Derived2() }) : Base[] +>f : (a: { x: T; y: U; }) => Array >{ x: new Base(), y: new Derived2() } : { x: Base; y: Derived2; } >x : Base >new Base() : Base diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints3.errors.txt b/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints3.errors.txt index c41ca0e8875..9cb190ddecd 100644 --- a/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints3.errors.txt +++ b/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints3.errors.txt @@ -1,7 +1,8 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts(18,10): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts(20,29): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts (1 errors) ==== +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts (2 errors) ==== // Generic call with constraints infering type parameter from object member properties class Base { @@ -20,6 +21,8 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObj } var r1 = f({ x: new Derived(), y: new Derived2() }); // ok, both extend Base + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. function f2(a: U) { ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.errors.txt b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.errors.txt new file mode 100644 index 00000000000..3ddb094970a --- /dev/null +++ b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.errors.txt @@ -0,0 +1,54 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts(36,14): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts (1 errors) ==== + // Function typed arguments with multiple signatures must be passed an implementation that matches all of them + // Inferences are made quadratic-pairwise to and from these overload sets + + module NonGenericParameter { + var a: { + new(x: boolean): boolean; + new(x: string): string; + } + + function foo4(cb: typeof a) { + return new cb(null); + } + + var r = foo4(a); + var b: { new (x: T): T }; + var r2 = foo4(b); + } + + module GenericParameter { + function foo5(cb: { new(x: T): string; new(x: number): T }) { + return cb; + } + + var a: { + new (x: boolean): string; + new (x: number): boolean; + } + var r5 = foo5(a); // new{} => string; new(x:number) => {} + var b: { new(x: T): string; new(x: number): T; } + var r7 = foo5(b); // new any => string; new(x:number) => any + + function foo6(cb: { new(x: T): string; new(x: T, y?: T): string }) { + return cb; + } + + var r8 = foo6(a); // error + ~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r9 = foo6(b); // new any => string; new(x:any, y?:any) => string + + function foo7(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }) { + return cb; + } + + var r13 = foo7(1, b); // new any => string; new(x:any, y?:any) => string + var c: { new (x: T): string; (x: number): T; } + var c2: { new (x: T): string; new(x: number): T; } + var r14 = foo7(1, c); // new any => string; new(x:any, y?:any) => string + var r15 = foo7(1, c2); // new any => string; new(x:any, y?:any) => string + } \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.js b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.js index 9da34ebad86..4f74b043bd9 100644 --- a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.js +++ b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.js @@ -34,7 +34,7 @@ module GenericParameter { return cb; } - var r8 = foo6(a); // new{} => string; new(x:{}, y?:{}) => string + var r8 = foo6(a); // error var r9 = foo6(b); // new any => string; new(x:any, y?:any) => string function foo7(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }) { @@ -73,7 +73,7 @@ var GenericParameter; function foo6(cb) { return cb; } - var r8 = foo6(a); // new{} => string; new(x:{}, y?:{}) => string + var r8 = foo6(a); // error var r9 = foo6(b); // new any => string; new(x:any, y?:any) => string function foo7(x, cb) { return cb; diff --git a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.types b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.types deleted file mode 100644 index 6c16ad0259c..00000000000 --- a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.types +++ /dev/null @@ -1,173 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts === -// Function typed arguments with multiple signatures must be passed an implementation that matches all of them -// Inferences are made quadratic-pairwise to and from these overload sets - -module NonGenericParameter { ->NonGenericParameter : typeof NonGenericParameter - - var a: { ->a : { new (x: boolean): boolean; new (x: string): string; } - - new(x: boolean): boolean; ->x : boolean - - new(x: string): string; ->x : string - } - - function foo4(cb: typeof a) { ->foo4 : (cb: { new (x: boolean): boolean; new (x: string): string; }) => boolean ->cb : { new (x: boolean): boolean; new (x: string): string; } ->a : { new (x: boolean): boolean; new (x: string): string; } - - return new cb(null); ->new cb(null) : boolean ->cb : { new (x: boolean): boolean; new (x: string): string; } - } - - var r = foo4(a); ->r : boolean ->foo4(a) : boolean ->foo4 : (cb: { new (x: boolean): boolean; new (x: string): string; }) => boolean ->a : { new (x: boolean): boolean; new (x: string): string; } - - var b: { new (x: T): T }; ->b : new (x: T) => T ->T : T ->x : T ->T : T ->T : T - - var r2 = foo4(b); ->r2 : boolean ->foo4(b) : boolean ->foo4 : (cb: { new (x: boolean): boolean; new (x: string): string; }) => boolean ->b : new (x: T) => T -} - -module GenericParameter { ->GenericParameter : typeof GenericParameter - - function foo5(cb: { new(x: T): string; new(x: number): T }) { ->foo5 : (cb: { new (x: T): string; new (x: number): T; }) => { new (x: T): string; new (x: number): T; } ->T : T ->cb : { new (x: T): string; new (x: number): T; } ->x : T ->T : T ->x : number ->T : T - - return cb; ->cb : { new (x: T): string; new (x: number): T; } - } - - var a: { ->a : { new (x: boolean): string; new (x: number): boolean; } - - new (x: boolean): string; ->x : boolean - - new (x: number): boolean; ->x : number - } - var r5 = foo5(a); // new{} => string; new(x:number) => {} ->r5 : { new (x: boolean): string; new (x: number): boolean; } ->foo5(a) : { new (x: boolean): string; new (x: number): boolean; } ->foo5 : (cb: { new (x: T): string; new (x: number): T; }) => { new (x: T): string; new (x: number): T; } ->a : { new (x: boolean): string; new (x: number): boolean; } - - var b: { new(x: T): string; new(x: number): T; } ->b : { new (x: T): string; new (x: number): T; } ->T : T ->x : T ->T : T ->T : T ->x : number ->T : T - - var r7 = foo5(b); // new any => string; new(x:number) => any ->r7 : { new (x: any): string; new (x: number): any; } ->foo5(b) : { new (x: any): string; new (x: number): any; } ->foo5 : (cb: { new (x: T): string; new (x: number): T; }) => { new (x: T): string; new (x: number): T; } ->b : { new (x: T): string; new (x: number): T; } - - function foo6(cb: { new(x: T): string; new(x: T, y?: T): string }) { ->foo6 : (cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->T : T ->cb : { new (x: T): string; new (x: T, y?: T): string; } ->x : T ->T : T ->x : T ->T : T ->y : T ->T : T - - return cb; ->cb : { new (x: T): string; new (x: T, y?: T): string; } - } - - var r8 = foo6(a); // new{} => string; new(x:{}, y?:{}) => string ->r8 : { new (x: {}): string; new (x: {}, y?: {}): string; } ->foo6(a) : { new (x: {}): string; new (x: {}, y?: {}): string; } ->foo6 : (cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->a : { new (x: boolean): string; new (x: number): boolean; } - - var r9 = foo6(b); // new any => string; new(x:any, y?:any) => string ->r9 : { new (x: any): string; new (x: any, y?: any): string; } ->foo6(b) : { new (x: any): string; new (x: any, y?: any): string; } ->foo6 : (cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->b : { new (x: T): string; new (x: number): T; } - - function foo7(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }) { ->foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->T : T ->x : T ->T : T ->cb : { new (x: T): string; new (x: T, y?: T): string; } ->x : T ->T : T ->x : T ->T : T ->y : T ->T : T - - return cb; ->cb : { new (x: T): string; new (x: T, y?: T): string; } - } - - var r13 = foo7(1, b); // new any => string; new(x:any, y?:any) => string ->r13 : { new (x: any): string; new (x: any, y?: any): string; } ->foo7(1, b) : { new (x: any): string; new (x: any, y?: any): string; } ->foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->b : { new (x: T): string; new (x: number): T; } - - var c: { new (x: T): string; (x: number): T; } ->c : { (x: number): T; new (x: T): string; } ->T : T ->x : T ->T : T ->T : T ->x : number ->T : T - - var c2: { new (x: T): string; new(x: number): T; } ->c2 : { new (x: T): string; new (x: number): T; } ->T : T ->x : T ->T : T ->T : T ->x : number ->T : T - - var r14 = foo7(1, c); // new any => string; new(x:any, y?:any) => string ->r14 : { new (x: any): string; new (x: any, y?: any): string; } ->foo7(1, c) : { new (x: any): string; new (x: any, y?: any): string; } ->foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->c : { (x: number): T; new (x: T): string; } - - var r15 = foo7(1, c2); // new any => string; new(x:any, y?:any) => string ->r15 : { new (x: any): string; new (x: any, y?: any): string; } ->foo7(1, c2) : { new (x: any): string; new (x: any, y?: any): string; } ->foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->c2 : { new (x: T): string; new (x: number): T; } -} diff --git a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.errors.txt b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.errors.txt new file mode 100644 index 00000000000..30ed4bc431f --- /dev/null +++ b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.errors.txt @@ -0,0 +1,81 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts(57,19): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts(60,19): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts(61,20): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts(62,30): error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts (4 errors) ==== + // Generic functions used as arguments for function typed parameters are not used to make inferences from + // Using function arguments, no errors expected + + module ImmediatelyFix { + class C { + foo(x: (a: T) => T) { + return x(null); + } + } + + var c = new C(); + var r = c.foo((x: U) => ''); // {} + var r2 = c.foo((x: U) => ''); // string + var r3 = c.foo(x => ''); // {} + + class C2 { + foo(x: (a: T) => T) { + return x(null); + } + } + + var c2 = new C2(); + var ra = c2.foo((x: U) => 1); // number + var r3a = c2.foo(x => 1); // number + } + + module WithCandidates { + class C { + foo2(x: T, cb: (a: T) => U) { + return cb(x); + } + } + + var c: C; + var r4 = c.foo2(1, function (a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions + var r5 = c.foo2(1, (a) => ''); // string + var r6 = c.foo2('', (a: Z) => 1); // number + + class C2 { + foo3(x: T, cb: (a: T) => U, y: U) { + return cb(x); + } + } + + var c2: C2; + var r7 = c2.foo3(1, (a: Z) => '', ''); // string + var r8 = c2.foo3(1, function (a) { return '' }, ''); // string + + class C3 { + foo3(x: T, cb: (a: T) => U, y: U) { + return cb(x); + } + } + var c3: C3; + + function other(t: T, u: U) { + var r10 = c.foo2(1, (x: T) => ''); // error + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r10 = c.foo2(1, (x) => ''); // string + + var r11 = c3.foo3(1, (x: T) => '', ''); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r11b = c3.foo3(1, (x: T) => '', 1); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r12 = c3.foo3(1, function (a) { return '' }, 1); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.js b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.js index 1af5f0ea6e6..7ec25949534 100644 --- a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.js +++ b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.js @@ -55,12 +55,12 @@ module WithCandidates { var c3: C3; function other(t: T, u: U) { - var r10 = c.foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made + var r10 = c.foo2(1, (x: T) => ''); // error var r10 = c.foo2(1, (x) => ''); // string - var r11 = c3.foo3(1, (x: T) => '', ''); // string - var r11b = c3.foo3(1, (x: T) => '', 1); // {} - var r12 = c3.foo3(1, function (a) { return '' }, 1); // {} + var r11 = c3.foo3(1, (x: T) => '', ''); // error + var r11b = c3.foo3(1, (x: T) => '', 1); // error + var r12 = c3.foo3(1, function (a) { return '' }, 1); // error } } @@ -132,12 +132,12 @@ var WithCandidates; })(); var c3; function other(t, u) { - var r10 = c.foo2(1, function (x) { return ''; }); // string, non-generic signature allows inferences to be made + var r10 = c.foo2(1, function (x) { return ''; }); // error var r10 = c.foo2(1, function (x) { return ''; }); // string - var r11 = c3.foo3(1, function (x) { return ''; }, ''); // string - var r11b = c3.foo3(1, function (x) { return ''; }, 1); // {} + var r11 = c3.foo3(1, function (x) { return ''; }, ''); // error + var r11b = c3.foo3(1, function (x) { return ''; }, 1); // error var r12 = c3.foo3(1, function (a) { return ''; - }, 1); // {} + }, 1); // error } })(WithCandidates || (WithCandidates = {})); diff --git a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.types b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.types deleted file mode 100644 index 68b94d81d02..00000000000 --- a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.types +++ /dev/null @@ -1,297 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts === -// Generic functions used as arguments for function typed parameters are not used to make inferences from -// Using function arguments, no errors expected - -module ImmediatelyFix { ->ImmediatelyFix : typeof ImmediatelyFix - - class C { ->C : C ->T : T - - foo(x: (a: T) => T) { ->foo : (x: (a: T) => T) => T ->T : T ->x : (a: T) => T ->a : T ->T : T ->T : T - - return x(null); ->x(null) : T ->x : (a: T) => T - } - } - - var c = new C(); ->c : C ->new C() : C ->C : typeof C - - var r = c.foo((x: U) => ''); // {} ->r : {} ->c.foo((x: U) => '') : {} ->c.foo : (x: (a: T) => T) => T ->c : C ->foo : (x: (a: T) => T) => T ->(x: U) => '' : (x: U) => string ->U : U ->x : U ->U : U - - var r2 = c.foo((x: U) => ''); // string ->r2 : string ->c.foo((x: U) => '') : string ->c.foo : (x: (a: T) => T) => T ->c : C ->foo : (x: (a: T) => T) => T ->(x: U) => '' : (x: U) => string ->U : U ->x : U ->U : U - - var r3 = c.foo(x => ''); // {} ->r3 : {} ->c.foo(x => '') : {} ->c.foo : (x: (a: T) => T) => T ->c : C ->foo : (x: (a: T) => T) => T ->x => '' : (x: {}) => string ->x : {} - - class C2 { ->C2 : C2 ->T : T - - foo(x: (a: T) => T) { ->foo : (x: (a: T) => T) => T ->x : (a: T) => T ->a : T ->T : T ->T : T - - return x(null); ->x(null) : T ->x : (a: T) => T - } - } - - var c2 = new C2(); ->c2 : C2 ->new C2() : C2 ->C2 : typeof C2 - - var ra = c2.foo((x: U) => 1); // number ->ra : number ->c2.foo((x: U) => 1) : number ->c2.foo : (x: (a: number) => number) => number ->c2 : C2 ->foo : (x: (a: number) => number) => number ->(x: U) => 1 : (x: U) => number ->U : U ->x : U ->U : U - - var r3a = c2.foo(x => 1); // number ->r3a : number ->c2.foo(x => 1) : number ->c2.foo : (x: (a: number) => number) => number ->c2 : C2 ->foo : (x: (a: number) => number) => number ->x => 1 : (x: number) => number ->x : number -} - -module WithCandidates { ->WithCandidates : typeof WithCandidates - - class C { ->C : C ->T : T - - foo2(x: T, cb: (a: T) => U) { ->foo2 : (x: T, cb: (a: T) => U) => U ->T : T ->U : U ->x : T ->T : T ->cb : (a: T) => U ->a : T ->T : T ->U : U - - return cb(x); ->cb(x) : U ->cb : (a: T) => U ->x : T - } - } - - var c: C; ->c : C ->C : C - - var r4 = c.foo2(1, function (a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions ->r4 : string ->c.foo2(1, function (a: Z) { return '' }) : string ->c.foo2 : (x: T, cb: (a: T) => U) => U ->c : C ->foo2 : (x: T, cb: (a: T) => U) => U ->function (a: Z) { return '' } : (a: Z) => string ->Z : Z ->a : Z ->Z : Z - - var r5 = c.foo2(1, (a) => ''); // string ->r5 : string ->c.foo2(1, (a) => '') : string ->c.foo2 : (x: T, cb: (a: T) => U) => U ->c : C ->foo2 : (x: T, cb: (a: T) => U) => U ->(a) => '' : (a: number) => string ->a : number - - var r6 = c.foo2('', (a: Z) => 1); // number ->r6 : number ->c.foo2('', (a: Z) => 1) : number ->c.foo2 : (x: T, cb: (a: T) => U) => U ->c : C ->foo2 : (x: T, cb: (a: T) => U) => U ->(a: Z) => 1 : (a: Z) => number ->Z : Z ->a : Z ->Z : Z - - class C2 { ->C2 : C2 ->T : T ->U : U - - foo3(x: T, cb: (a: T) => U, y: U) { ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->x : T ->T : T ->cb : (a: T) => U ->a : T ->T : T ->U : U ->y : U ->U : U - - return cb(x); ->cb(x) : U ->cb : (a: T) => U ->x : T - } - } - - var c2: C2; ->c2 : C2 ->C2 : C2 - - var r7 = c2.foo3(1, (a: Z) => '', ''); // string ->r7 : string ->c2.foo3(1, (a: Z) => '', '') : string ->c2.foo3 : (x: number, cb: (a: number) => string, y: string) => string ->c2 : C2 ->foo3 : (x: number, cb: (a: number) => string, y: string) => string ->(a: Z) => '' : (a: Z) => string ->Z : Z ->a : Z ->Z : Z - - var r8 = c2.foo3(1, function (a) { return '' }, ''); // string ->r8 : string ->c2.foo3(1, function (a) { return '' }, '') : string ->c2.foo3 : (x: number, cb: (a: number) => string, y: string) => string ->c2 : C2 ->foo3 : (x: number, cb: (a: number) => string, y: string) => string ->function (a) { return '' } : (a: number) => string ->a : number - - class C3 { ->C3 : C3 ->T : T ->U : U - - foo3(x: T, cb: (a: T) => U, y: U) { ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->T : T ->U : U ->x : T ->T : T ->cb : (a: T) => U ->a : T ->T : T ->U : U ->y : U ->U : U - - return cb(x); ->cb(x) : U ->cb : (a: T) => U ->x : T - } - } - var c3: C3; ->c3 : C3 ->C3 : C3 - - function other(t: T, u: U) { ->other : (t: T, u: U) => void ->T : T ->U : U ->t : T ->T : T ->u : U ->U : U - - var r10 = c.foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made ->r10 : string ->c.foo2(1, (x: T) => '') : string ->c.foo2 : (x: T, cb: (a: T) => U) => U ->c : C ->foo2 : (x: T, cb: (a: T) => U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r10 = c.foo2(1, (x) => ''); // string ->r10 : string ->c.foo2(1, (x) => '') : string ->c.foo2 : (x: T, cb: (a: T) => U) => U ->c : C ->foo2 : (x: T, cb: (a: T) => U) => U ->(x) => '' : (x: number) => string ->x : number - - var r11 = c3.foo3(1, (x: T) => '', ''); // string ->r11 : string ->c3.foo3(1, (x: T) => '', '') : string ->c3.foo3 : (x: T, cb: (a: T) => U, y: U) => U ->c3 : C3 ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r11b = c3.foo3(1, (x: T) => '', 1); // {} ->r11b : {} ->c3.foo3(1, (x: T) => '', 1) : {} ->c3.foo3 : (x: T, cb: (a: T) => U, y: U) => U ->c3 : C3 ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r12 = c3.foo3(1, function (a) { return '' }, 1); // {} ->r12 : {} ->c3.foo3(1, function (a) { return '' }, 1) : {} ->c3.foo3 : (x: T, cb: (a: T) => U, y: U) => U ->c3 : C3 ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->function (a) { return '' } : (a: number) => string ->a : number - } -} diff --git a/tests/baselines/reference/genericRestArgs.errors.txt b/tests/baselines/reference/genericRestArgs.errors.txt index db36a9a0162..49f61de325f 100644 --- a/tests/baselines/reference/genericRestArgs.errors.txt +++ b/tests/baselines/reference/genericRestArgs.errors.txt @@ -1,10 +1,14 @@ +tests/cases/compiler/genericRestArgs.ts(2,12): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/genericRestArgs.ts(5,34): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. +tests/cases/compiler/genericRestArgs.ts(10,12): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/genericRestArgs.ts(12,30): error TS2345: Argument of type 'number' is not assignable to parameter of type 'any[]'. -==== tests/cases/compiler/genericRestArgs.ts (2 errors) ==== +==== tests/cases/compiler/genericRestArgs.ts (4 errors) ==== function makeArrayG(...items: T[]): T[] { return items; } var a1Ga = makeArrayG(1, ""); // no error + ~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var a1Gb = makeArrayG(1, ""); var a1Gc = makeArrayG(1, ""); var a1Gd = makeArrayG(1, ""); // error @@ -15,6 +19,8 @@ tests/cases/compiler/genericRestArgs.ts(12,30): error TS2345: Argument of type ' return [item1, item2, item3]; } var a2Ga = makeArrayGOpt(1, ""); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var a2Gb = makeArrayG(1, ""); var a2Gc = makeArrayG(1, ""); // error ~ diff --git a/tests/baselines/reference/genericTypeArgumentInference1.types b/tests/baselines/reference/genericTypeArgumentInference1.types index 20a9a0ca8f9..c7d932befb8 100644 --- a/tests/baselines/reference/genericTypeArgumentInference1.types +++ b/tests/baselines/reference/genericTypeArgumentInference1.types @@ -42,12 +42,12 @@ declare var _: Underscore.Static; >Static : Underscore.Static var r = _.all([true, 1, null, 'yes'], _.identity); ->r : {} ->_.all([true, 1, null, 'yes'], _.identity) : {} +>r : string | number | boolean +>_.all([true, 1, null, 'yes'], _.identity) : string | number | boolean >_.all : (list: T[], iterator?: Underscore.Iterator, context?: any) => T >_ : Underscore.Static >all : (list: T[], iterator?: Underscore.Iterator, context?: any) => T ->[true, 1, null, 'yes'] : {}[] +>[true, 1, null, 'yes'] : Array >_.identity : (value: T) => T >_ : Underscore.Static >identity : (value: T) => T diff --git a/tests/baselines/reference/genericsManyTypeParameters.types b/tests/baselines/reference/genericsManyTypeParameters.types index 65f9a7c115e..df2144de866 100644 --- a/tests/baselines/reference/genericsManyTypeParameters.types +++ b/tests/baselines/reference/genericsManyTypeParameters.types @@ -1,6 +1,6 @@ === tests/cases/compiler/genericsManyTypeParameters.ts === function Foo< ->Foo : (x1: a1, y1: a21, z1: a31, a1: a41, b1: a51, c1: a61, x2: a119, y2: a22, z2: a32, a2: a42, b2: a52, c2: a62, x3: a219, y3: a23, z3: a33, a3: a43, b3: a53, c3: a63, x4: a319, y4: a24, z4: a34, a4: a44, b4: a54, c4: a64, x5: a419, y5: a25, z5: a35, a5: a45, b5: a55, c5: a65, x6: a519, y6: a26, z6: a36, a6: a46, b6: a56, c6: a66, x7: a619, y7: a27, z7: a37, a7: a47, b7: a57, c7: a67, x8: a71, y8: a28, z8: a38, a8: a48, b8: a58, c8: a68, x9: a81, y9: a29, z9: a39, a9: a49, b9: a59, c9: a69, x10: a91, y12: a210, z10: a310, a10: a410, b10: a510, c10: a610, x11: a111, y13: a211, z11: a311, a11: a411, b11: a511, c11: a611, x12: a112, y14: a212, z12: a312, a12: a412, b12: a512, c12: a612, x13: a113, y15: a213, z13: a313, a13: a413, b13: a513, c13: a613, x14: a114, y16: a214, z14: a314, a14: a414, b14: a514, c14: a614, x15: a115, y17: a215, z15: a315, a15: a415, b15: a515, c15: a615, x16: a116, y18: a216, z16: a316, a16: a416, b16: a516, c16: a616, x17: a117, y19: a217, z17: a317, a17: a417, b17: a517, c17: a617, x18: a118, y10: a218, z18: a318, a18: a418, b18: a518, c18: a618) => {}[] +>Foo : (x1: a1, y1: a21, z1: a31, a1: a41, b1: a51, c1: a61, x2: a119, y2: a22, z2: a32, a2: a42, b2: a52, c2: a62, x3: a219, y3: a23, z3: a33, a3: a43, b3: a53, c3: a63, x4: a319, y4: a24, z4: a34, a4: a44, b4: a54, c4: a64, x5: a419, y5: a25, z5: a35, a5: a45, b5: a55, c5: a65, x6: a519, y6: a26, z6: a36, a6: a46, b6: a56, c6: a66, x7: a619, y7: a27, z7: a37, a7: a47, b7: a57, c7: a67, x8: a71, y8: a28, z8: a38, a8: a48, b8: a58, c8: a68, x9: a81, y9: a29, z9: a39, a9: a49, b9: a59, c9: a69, x10: a91, y12: a210, z10: a310, a10: a410, b10: a510, c10: a610, x11: a111, y13: a211, z11: a311, a11: a411, b11: a511, c11: a611, x12: a112, y14: a212, z12: a312, a12: a412, b12: a512, c12: a612, x13: a113, y15: a213, z13: a313, a13: a413, b13: a513, c13: a613, x14: a114, y16: a214, z14: a314, a14: a414, b14: a514, c14: a614, x15: a115, y17: a215, z15: a315, a15: a415, b15: a515, c15: a615, x16: a116, y18: a216, z16: a316, a16: a416, b16: a516, c16: a616, x17: a117, y19: a217, z17: a317, a17: a417, b17: a517, c17: a617, x18: a118, y10: a218, z18: a318, a18: a418, b18: a518, c18: a618) => Array a1, a21, a31, a41, a51, a61, >a1 : a1 @@ -402,7 +402,7 @@ function Foo< ) { return [x1 , y1 , z1 , a1 , b1 , c1, ->[x1 , y1 , z1 , a1 , b1 , c1, x2 , y2 , z2 , a2 , b2 , c2, x3 , y3 , z3 , a3 , b3 , c3, x4 , y4 , z4 , a4 , b4 , c4, x5 , y5 , z5 , a5 , b5 , c5, x6 , y6 , z6 , a6 , b6 , c6, x7 , y7 , z7 , a7 , b7 , c7, x8 , y8 , z8 , a8 , b8 , c8, x9 , y9 , z9 , a9 , b9 , c9, x10 , y12 , z10 , a10 , b10 , c10, x11 , y13 , z11 , a11 , b11 , c11, x12 , y14 , z12 , a12 , b12 , c12, x13 , y15 , z13 , a13 , b13 , c13, x14 , y16 , z14 , a14 , b14 , c14, x15 , y17 , z15 , a15 , b15 , c15, x16 , y18 , z16 , a16 , b16 , c16, x17 , y19 , z17 , a17 , b17 , c17, x18 , y10 , z18 , a18 , b18 , c18] : {}[] +>[x1 , y1 , z1 , a1 , b1 , c1, x2 , y2 , z2 , a2 , b2 , c2, x3 , y3 , z3 , a3 , b3 , c3, x4 , y4 , z4 , a4 , b4 , c4, x5 , y5 , z5 , a5 , b5 , c5, x6 , y6 , z6 , a6 , b6 , c6, x7 , y7 , z7 , a7 , b7 , c7, x8 , y8 , z8 , a8 , b8 , c8, x9 , y9 , z9 , a9 , b9 , c9, x10 , y12 , z10 , a10 , b10 , c10, x11 , y13 , z11 , a11 , b11 , c11, x12 , y14 , z12 , a12 , b12 , c12, x13 , y15 , z13 , a13 , b13 , c13, x14 , y16 , z14 , a14 , b14 , c14, x15 , y17 , z15 , a15 , b15 , c15, x16 , y18 , z16 , a16 , b16 , c16, x17 , y19 , z17 , a17 , b17 , c17, x18 , y10 , z18 , a18 , b18 , c18] : Array >x1 : a1 >y1 : a21 >z1 : a31 diff --git a/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt b/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt index 072d06e8686..985aaa7948c 100644 --- a/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt +++ b/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt @@ -1,5 +1,6 @@ -tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,19): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'string[]'. - Type '{}' is not assignable to type 'string'. +tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,19): error TS2345: Argument of type 'Array' is not assignable to parameter of type 'string[]'. + Type 'string | number' is not assignable to type 'string': + Type 'number' is not assignable to type 'string'. ==== tests/cases/compiler/heterogeneousArrayAndOverloads.ts (1 errors) ==== @@ -13,7 +14,8 @@ tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,19): error TS2345: Argu this.test([]); this.test([1, 2, "hi", 5]); // Error ~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'string[]'. -!!! error TS2345: Type '{}' is not assignable to type 'string'. +!!! error TS2345: Argument of type 'Array' is not assignable to parameter of type 'string[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'string': +!!! error TS2345: Type 'number' is not assignable to type 'string'. } } \ No newline at end of file diff --git a/tests/baselines/reference/heterogeneousArrayLiterals.types b/tests/baselines/reference/heterogeneousArrayLiterals.types index 81770731633..882fe1e8295 100644 --- a/tests/baselines/reference/heterogeneousArrayLiterals.types +++ b/tests/baselines/reference/heterogeneousArrayLiterals.types @@ -2,16 +2,16 @@ // type of an array is the best common type of its elements (plus its contextual type if it exists) var a = [1, '']; // {}[] ->a : {}[] ->[1, ''] : {}[] +>a : Array +>[1, ''] : Array var b = [1, null]; // number[] >b : number[] >[1, null] : number[] var c = [1, '', null]; // {}[] ->c : {}[] ->[1, '', null] : {}[] +>c : Array +>[1, '', null] : Array var d = [{}, 1]; // {}[] >d : {}[] @@ -31,8 +31,8 @@ var f = [[], [1]]; // number[][] >[1] : number[] var g = [[1], ['']]; // {}[] ->g : {}[] ->[[1], ['']] : {}[] +>g : Array +>[[1], ['']] : Array >[1] : number[] >[''] : string[] @@ -46,8 +46,8 @@ var h = [{ foo: 1, bar: '' }, { foo: 2 }]; // {foo: number}[] >foo : number var i = [{ foo: 1, bar: '' }, { foo: '' }]; // {}[] ->i : {}[] ->[{ foo: 1, bar: '' }, { foo: '' }] : {}[] +>i : Array<{ foo: number; bar: string; } | { foo: string; }> +>[{ foo: 1, bar: '' }, { foo: '' }] : Array<{ foo: number; bar: string; } | { foo: string; }> >{ foo: 1, bar: '' } : { foo: number; bar: string; } >foo : number >bar : string @@ -55,8 +55,8 @@ var i = [{ foo: 1, bar: '' }, { foo: '' }]; // {}[] >foo : string var j = [() => 1, () => '']; // {}[] ->j : {}[] ->[() => 1, () => ''] : {}[] +>j : Array<{ (): number; } | { (): string; }> +>[() => 1, () => ''] : Array<{ (): number; } | { (): string; }> >() => 1 : () => number >() => '' : () => string @@ -80,8 +80,8 @@ var m = [() => 1, () => '', () => null]; // { (): any }[] >() => null : () => any var n = [[() => 1], [() => '']]; // {}[] ->n : {}[] ->[[() => 1], [() => '']] : {}[] +>n : Array<{ (): number; }[] | { (): string; }[]> +>[[() => 1], [() => '']] : Array<{ (): number; }[] | { (): string; }[]> >[() => 1] : { (): number; }[] >() => 1 : () => number >[() => ''] : { (): string; }[] @@ -129,8 +129,8 @@ module Derived { >base : Base var i = [{ foo: base, basear: derived }, { foo: derived }]; // {foo: Derived}[] ->i : {}[] ->[{ foo: base, basear: derived }, { foo: derived }] : {}[] +>i : Array<{ foo: Base; basear: Derived; } | { foo: Derived; }> +>[{ foo: base, basear: derived }, { foo: derived }] : Array<{ foo: Base; basear: Derived; } | { foo: Derived; }> >{ foo: base, basear: derived } : { foo: Base; basear: Derived; } >foo : Base >base : Base @@ -149,8 +149,8 @@ module Derived { >derived : Derived var k = [() => base, () => 1]; // {}[]~ ->k : {}[] ->[() => base, () => 1] : {}[] +>k : Array<{ (): Base; } | { (): number; }> +>[() => base, () => 1] : Array<{ (): Base; } | { (): number; }> >() => base : () => Base >base : Base >() => 1 : () => number @@ -182,8 +182,8 @@ module Derived { >derived : Derived var o = [derived, derived2]; // {}[] ->o : {}[] ->[derived, derived2] : {}[] +>o : Array +>[derived, derived2] : Array >derived : Derived >derived2 : Derived2 @@ -195,8 +195,8 @@ module Derived { >base : Base var q = [[() => derived2], [() => derived]]; // {}[] ->q : {}[] ->[[() => derived2], [() => derived]] : {}[] +>q : Array<{ (): Derived2; }[] | { (): Derived; }[]> +>[[() => derived2], [() => derived]] : Array<{ (): Derived2; }[] | { (): Derived; }[]> >[() => derived2] : { (): Derived2; }[] >() => derived2 : () => Derived2 >derived2 : Derived2 @@ -257,19 +257,19 @@ function foo(t: T, u: U) { >t : T var c = [t, u]; // {}[] ->c : {}[] ->[t, u] : {}[] +>c : Array +>[t, u] : Array >t : T >u : U var d = [t, 1]; // {}[] ->d : {}[] ->[t, 1] : {}[] +>d : Array +>[t, 1] : Array >t : T var e = [() => t, () => u]; // {}[] ->e : {}[] ->[() => t, () => u] : {}[] +>e : Array<{ (): T; } | { (): U; }> +>[() => t, () => u] : Array<{ (): T; } | { (): U; }> >() => t : () => T >t : T >() => u : () => U @@ -308,19 +308,19 @@ function foo2(t: T, u: U) { >t : T var c = [t, u]; // {}[] ->c : {}[] ->[t, u] : {}[] +>c : Array +>[t, u] : Array >t : T >u : U var d = [t, 1]; // {}[] ->d : {}[] ->[t, 1] : {}[] +>d : Array +>[t, 1] : Array >t : T var e = [() => t, () => u]; // {}[] ->e : {}[] ->[() => t, () => u] : {}[] +>e : Array<{ (): T; } | { (): U; }> +>[() => t, () => u] : Array<{ (): T; } | { (): U; }> >() => t : () => T >t : T >() => u : () => U @@ -342,8 +342,8 @@ function foo2(t: T, u: U) { >base : Base var h = [t, derived]; // Derived[] ->h : {}[] ->[t, derived] : {}[] +>h : Array +>[t, derived] : Array >t : T >derived : Derived @@ -383,19 +383,19 @@ function foo3(t: T, u: U) { >t : T var c = [t, u]; // {}[] ->c : {}[] ->[t, u] : {}[] +>c : Array +>[t, u] : Array >t : T >u : U var d = [t, 1]; // {}[] ->d : {}[] ->[t, 1] : {}[] +>d : Array +>[t, 1] : Array >t : T var e = [() => t, () => u]; // {}[] ->e : {}[] ->[() => t, () => u] : {}[] +>e : Array<{ (): T; } | { (): U; }> +>[() => t, () => u] : Array<{ (): T; } | { (): U; }> >() => t : () => T >t : T >() => u : () => U @@ -458,19 +458,19 @@ function foo4(t: T, u: U) { >t : T var c = [t, u]; // BUG 821629 ->c : {}[] ->[t, u] : {}[] +>c : Array +>[t, u] : Array >t : T >u : U var d = [t, 1]; // {}[] ->d : {}[] ->[t, 1] : {}[] +>d : Array +>[t, 1] : Array >t : T var e = [() => t, () => u]; // {}[] ->e : {}[] ->[() => t, () => u] : {}[] +>e : Array<{ (): T; } | { (): U; }> +>[() => t, () => u] : Array<{ (): T; } | { (): U; }> >() => t : () => T >t : T >() => u : () => U @@ -492,8 +492,8 @@ function foo4(t: T, u: U) { >base : Base var h = [t, derived]; // Derived[] ->h : {}[] ->[t, derived] : {}[] +>h : Array +>[t, derived] : Array >t : T >derived : Derived @@ -504,8 +504,8 @@ function foo4(t: T, u: U) { >base : Base var j = [u, derived]; // Derived[] ->j : {}[] ->[u, derived] : {}[] +>j : Array +>[u, derived] : Array >u : U >derived : Derived diff --git a/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt b/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt index 0a4761994dd..b82c82b9eb5 100644 --- a/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt +++ b/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt @@ -7,7 +7,7 @@ tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDec tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(40,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'I', but here has type 'C2'. tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(43,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'f' must be of type '(x: string) => number', but here has type '(x: number) => string'. tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(46,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. -tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(47,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '{}[]'. +tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(47,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'Array>'. tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(50,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'D[]', but here has type 'D[]'. tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(53,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'm' must be of type 'typeof M', but here has type 'typeof A'. @@ -79,7 +79,7 @@ tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDec !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. var arr = [new C(), new C2(), new D()]; ~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '{}[]'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'Array>'. var arr2 = [new D()]; var arr2 = new Array>(); diff --git a/tests/baselines/reference/logicalOrOperatorWithEveryType.types b/tests/baselines/reference/logicalOrOperatorWithEveryType.types index 3cf0399f437..3e3b0dcf37f 100644 --- a/tests/baselines/reference/logicalOrOperatorWithEveryType.types +++ b/tests/baselines/reference/logicalOrOperatorWithEveryType.types @@ -108,38 +108,38 @@ var rb2 = a2 || a2; // boolean || boolean is boolean >a2 : boolean var rb3 = a3 || a2; // number || boolean is {} ->rb3 : {} ->a3 || a2 : {} +>rb3 : number | boolean +>a3 || a2 : number | boolean >a3 : number >a2 : boolean var rb4 = a4 || a2; // string || boolean is {} ->rb4 : {} ->a4 || a2 : {} +>rb4 : string | boolean +>a4 || a2 : string | boolean >a4 : string >a2 : boolean var rb5 = a5 || a2; // void || boolean is {} ->rb5 : {} ->a5 || a2 : {} +>rb5 : boolean | void +>a5 || a2 : boolean | void >a5 : void >a2 : boolean var rb6 = a6 || a2; // enum || boolean is {} ->rb6 : {} ->a6 || a2 : {} +>rb6 : boolean | E +>a6 || a2 : boolean | E >a6 : E >a2 : boolean var rb7 = a7 || a2; // object || boolean is {} ->rb7 : {} ->a7 || a2 : {} +>rb7 : boolean | { a: string; } +>a7 || a2 : boolean | { a: string; } >a7 : { a: string; } >a2 : boolean var rb8 = a8 || a2; // array || boolean is {} ->rb8 : {} ->a8 || a2 : {} +>rb8 : boolean | string[] +>a8 || a2 : boolean | string[] >a8 : string[] >a2 : boolean @@ -161,8 +161,8 @@ var rc1 = a1 || a3; // any || number is any >a3 : number var rc2 = a2 || a3; // boolean || number is {} ->rc2 : {} ->a2 || a3 : {} +>rc2 : number | boolean +>a2 || a3 : number | boolean >a2 : boolean >a3 : number @@ -173,14 +173,14 @@ var rc3 = a3 || a3; // number || number is number >a3 : number var rc4 = a4 || a3; // string || number is {} ->rc4 : {} ->a4 || a3 : {} +>rc4 : string | number +>a4 || a3 : string | number >a4 : string >a3 : number var rc5 = a5 || a3; // void || number is {} ->rc5 : {} ->a5 || a3 : {} +>rc5 : number | void +>a5 || a3 : number | void >a5 : void >a3 : number @@ -191,14 +191,14 @@ var rc6 = a6 || a3; // enum || number is number >a3 : number var rc7 = a7 || a3; // object || number is {} ->rc7 : {} ->a7 || a3 : {} +>rc7 : number | { a: string; } +>a7 || a3 : number | { a: string; } >a7 : { a: string; } >a3 : number var rc8 = a8 || a3; // array || number is {} ->rc8 : {} ->a8 || a3 : {} +>rc8 : number | string[] +>a8 || a3 : number | string[] >a8 : string[] >a3 : number @@ -220,14 +220,14 @@ var rd1 = a1 || a4; // any || string is any >a4 : string var rd2 = a2 || a4; // boolean || string is {} ->rd2 : {} ->a2 || a4 : {} +>rd2 : string | boolean +>a2 || a4 : string | boolean >a2 : boolean >a4 : string var rd3 = a3 || a4; // number || string is {} ->rd3 : {} ->a3 || a4 : {} +>rd3 : string | number +>a3 || a4 : string | number >a3 : number >a4 : string @@ -238,26 +238,26 @@ var rd4 = a4 || a4; // string || string is string >a4 : string var rd5 = a5 || a4; // void || string is {} ->rd5 : {} ->a5 || a4 : {} +>rd5 : string | void +>a5 || a4 : string | void >a5 : void >a4 : string var rd6 = a6 || a4; // enum || string is {} ->rd6 : {} ->a6 || a4 : {} +>rd6 : string | E +>a6 || a4 : string | E >a6 : E >a4 : string var rd7 = a7 || a4; // object || string is {} ->rd7 : {} ->a7 || a4 : {} +>rd7 : string | { a: string; } +>a7 || a4 : string | { a: string; } >a7 : { a: string; } >a4 : string var rd8 = a8 || a4; // array || string is {} ->rd8 : {} ->a8 || a4 : {} +>rd8 : string | string[] +>a8 || a4 : string | string[] >a8 : string[] >a4 : string @@ -279,20 +279,20 @@ var re1 = a1 || a5; // any || void is any >a5 : void var re2 = a2 || a5; // boolean || void is {} ->re2 : {} ->a2 || a5 : {} +>re2 : boolean | void +>a2 || a5 : boolean | void >a2 : boolean >a5 : void var re3 = a3 || a5; // number || void is {} ->re3 : {} ->a3 || a5 : {} +>re3 : number | void +>a3 || a5 : number | void >a3 : number >a5 : void var re4 = a4 || a5; // string || void is {} ->re4 : {} ->a4 || a5 : {} +>re4 : string | void +>a4 || a5 : string | void >a4 : string >a5 : void @@ -303,20 +303,20 @@ var re5 = a5 || a5; // void || void is void >a5 : void var re6 = a6 || a5; // enum || void is {} ->re6 : {} ->a6 || a5 : {} +>re6 : void | E +>a6 || a5 : void | E >a6 : E >a5 : void var re7 = a7 || a5; // object || void is {} ->re7 : {} ->a7 || a5 : {} +>re7 : void | { a: string; } +>a7 || a5 : void | { a: string; } >a7 : { a: string; } >a5 : void var re8 = a8 || a5; // array || void is {} ->re8 : {} ->a8 || a5 : {} +>re8 : void | string[] +>a8 || a5 : void | string[] >a8 : string[] >a5 : void @@ -338,8 +338,8 @@ var rg1 = a1 || a6; // any || enum is any >a6 : E var rg2 = a2 || a6; // boolean || enum is {} ->rg2 : {} ->a2 || a6 : {} +>rg2 : boolean | E +>a2 || a6 : boolean | E >a2 : boolean >a6 : E @@ -350,14 +350,14 @@ var rg3 = a3 || a6; // number || enum is number >a6 : E var rg4 = a4 || a6; // string || enum is {} ->rg4 : {} ->a4 || a6 : {} +>rg4 : string | E +>a4 || a6 : string | E >a4 : string >a6 : E var rg5 = a5 || a6; // void || enum is {} ->rg5 : {} ->a5 || a6 : {} +>rg5 : void | E +>a5 || a6 : void | E >a5 : void >a6 : E @@ -368,14 +368,14 @@ var rg6 = a6 || a6; // enum || enum is E >a6 : E var rg7 = a7 || a6; // object || enum is {} ->rg7 : {} ->a7 || a6 : {} +>rg7 : E | { a: string; } +>a7 || a6 : E | { a: string; } >a7 : { a: string; } >a6 : E var rg8 = a8 || a6; // array || enum is {} ->rg8 : {} ->a8 || a6 : {} +>rg8 : string[] | E +>a8 || a6 : string[] | E >a8 : string[] >a6 : E @@ -397,32 +397,32 @@ var rh1 = a1 || a7; // any || object is any >a7 : { a: string; } var rh2 = a2 || a7; // boolean || object is {} ->rh2 : {} ->a2 || a7 : {} +>rh2 : boolean | { a: string; } +>a2 || a7 : boolean | { a: string; } >a2 : boolean >a7 : { a: string; } var rh3 = a3 || a7; // number || object is {} ->rh3 : {} ->a3 || a7 : {} +>rh3 : number | { a: string; } +>a3 || a7 : number | { a: string; } >a3 : number >a7 : { a: string; } var rh4 = a4 || a7; // string || object is {} ->rh4 : {} ->a4 || a7 : {} +>rh4 : string | { a: string; } +>a4 || a7 : string | { a: string; } >a4 : string >a7 : { a: string; } var rh5 = a5 || a7; // void || object is {} ->rh5 : {} ->a5 || a7 : {} +>rh5 : void | { a: string; } +>a5 || a7 : void | { a: string; } >a5 : void >a7 : { a: string; } var rh6 = a6 || a7; // enum || object is {} ->rh6 : {} ->a6 || a7 : {} +>rh6 : E | { a: string; } +>a6 || a7 : E | { a: string; } >a6 : E >a7 : { a: string; } @@ -433,8 +433,8 @@ var rh7 = a7 || a7; // object || object is object >a7 : { a: string; } var rh8 = a8 || a7; // array || object is {} ->rh8 : {} ->a8 || a7 : {} +>rh8 : string[] | { a: string; } +>a8 || a7 : string[] | { a: string; } >a8 : string[] >a7 : { a: string; } @@ -456,38 +456,38 @@ var ri1 = a1 || a8; // any || array is any >a8 : string[] var ri2 = a2 || a8; // boolean || array is {} ->ri2 : {} ->a2 || a8 : {} +>ri2 : boolean | string[] +>a2 || a8 : boolean | string[] >a2 : boolean >a8 : string[] var ri3 = a3 || a8; // number || array is {} ->ri3 : {} ->a3 || a8 : {} +>ri3 : number | string[] +>a3 || a8 : number | string[] >a3 : number >a8 : string[] var ri4 = a4 || a8; // string || array is {} ->ri4 : {} ->a4 || a8 : {} +>ri4 : string | string[] +>a4 || a8 : string | string[] >a4 : string >a8 : string[] var ri5 = a5 || a8; // void || array is {} ->ri5 : {} ->a5 || a8 : {} +>ri5 : void | string[] +>a5 || a8 : void | string[] >a5 : void >a8 : string[] var ri6 = a6 || a8; // enum || array is {} ->ri6 : {} ->a6 || a8 : {} +>ri6 : string[] | E +>a6 || a8 : string[] | E >a6 : E >a8 : string[] var ri7 = a7 || a8; // object || array is {} ->ri7 : {} ->a7 || a8 : {} +>ri7 : string[] | { a: string; } +>a7 || a8 : string[] | { a: string; } >a7 : { a: string; } >a8 : string[] diff --git a/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types b/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types index ff0e0ce568a..9a450b87784 100644 --- a/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types +++ b/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types @@ -22,8 +22,8 @@ function fn1(t: T, u: U) { >t : T var r3 = t || u; ->r3 : {} ->t || u : {} +>r3 : T | U +>t || u : T | U >t : T >u : U @@ -47,8 +47,8 @@ function fn2(t: T, u: U, v: V) { >V : V var r1 = t || u; ->r1 : {} ->t || u : {} +>r1 : T | U +>t || u : T | U >t : T >u : U @@ -67,8 +67,8 @@ function fn2(t: T, u: U, v: V) { >u : U var r5 = u || v; ->r5 : {} ->u || v : {} +>r5 : U | V +>u || v : U | V >u : U >v : V @@ -95,8 +95,8 @@ function fn3U : U var r1 = t || u; ->r1 : {} ->t || u : {} +>r1 : T | U +>t || u : T | U >t : T >u : U diff --git a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt index 557f60967a6..ed4f45ec1de 100644 --- a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt +++ b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt @@ -1,5 +1,6 @@ -tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(10,30): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. - Type '{}' is not assignable to type 'number'. +tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(10,30): error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): error TS2346: Supplied parameters do not match any signature of call target. @@ -15,8 +16,9 @@ tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): e var r6 = map([1, ""], (x) => x.toString()); var r7 = map([1, ""], (x) => x.toString()); // error ~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type '{}' is not assignable to type 'number'. +!!! error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number': +!!! error TS2345: Type 'string' is not assignable to type 'number'. var r7b = map([1, ""], (x) => x.toString()); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. diff --git a/tests/baselines/reference/nonContextuallyTypedLogicalOr.errors.txt b/tests/baselines/reference/nonContextuallyTypedLogicalOr.errors.txt deleted file mode 100644 index ca4dc9f67e3..00000000000 --- a/tests/baselines/reference/nonContextuallyTypedLogicalOr.errors.txt +++ /dev/null @@ -1,22 +0,0 @@ -tests/cases/compiler/nonContextuallyTypedLogicalOr.ts(16,10): error TS2339: Property 'dummy' does not exist on type '{}'. - - -==== tests/cases/compiler/nonContextuallyTypedLogicalOr.ts (1 errors) ==== - interface Contextual { - dummy; - p?: number; - } - - interface Ellement { - dummy; - p: any; - } - - var c: Contextual; - var e: Ellement; - - // This should error. Even though we are contextually typing e with Contextual, the RHS still - // needs to be a supertype of the LHS to win as the best common type. - (c || e).dummy; - ~~~~~ -!!! error TS2339: Property 'dummy' does not exist on type '{}'. \ No newline at end of file diff --git a/tests/baselines/reference/nonContextuallyTypedLogicalOr.js b/tests/baselines/reference/nonContextuallyTypedLogicalOr.js index a29390bcf7f..e3ec95533fd 100644 --- a/tests/baselines/reference/nonContextuallyTypedLogicalOr.js +++ b/tests/baselines/reference/nonContextuallyTypedLogicalOr.js @@ -12,13 +12,9 @@ interface Ellement { var c: Contextual; var e: Ellement; -// This should error. Even though we are contextually typing e with Contextual, the RHS still -// needs to be a supertype of the LHS to win as the best common type. (c || e).dummy; //// [nonContextuallyTypedLogicalOr.js] var c; var e; -// This should error. Even though we are contextually typing e with Contextual, the RHS still -// needs to be a supertype of the LHS to win as the best common type. (c || e).dummy; diff --git a/tests/baselines/reference/nonContextuallyTypedLogicalOr.types b/tests/baselines/reference/nonContextuallyTypedLogicalOr.types new file mode 100644 index 00000000000..aeb9d1409c6 --- /dev/null +++ b/tests/baselines/reference/nonContextuallyTypedLogicalOr.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/nonContextuallyTypedLogicalOr.ts === +interface Contextual { +>Contextual : Contextual + + dummy; +>dummy : any + + p?: number; +>p : number +} + +interface Ellement { +>Ellement : Ellement + + dummy; +>dummy : any + + p: any; +>p : any +} + +var c: Contextual; +>c : Contextual +>Contextual : Contextual + +var e: Ellement; +>e : Ellement +>Ellement : Ellement + +(c || e).dummy; +>(c || e).dummy : any +>(c || e) : Contextual | Ellement +>c || e : Contextual | Ellement +>c : Contextual +>e : Ellement +>dummy : any + diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt index fd23cab9956..7fb3d450f01 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt @@ -10,9 +10,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(55,5): error TS2412: Property '"4.0"' of type 'number' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(68,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(73,5): error TS2412: Property '"4.0"' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: number]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: unknown; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }': +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: unknown; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }': Index signatures are incompatible: - Type '{}' is not assignable to type 'string'. + Type 'string | number' is not assignable to type 'string': + Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(88,9): error TS2304: Cannot find name 'Myn'. @@ -116,9 +117,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo // error var b: { [x: number]: string; } = { ~ -!!! error TS2322: Type '{ [x: number]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: unknown; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }': +!!! error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: unknown; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }': !!! error TS2322: Index signatures are incompatible: -!!! error TS2322: Type '{}' is not assignable to type 'string'. +!!! error TS2322: Type 'string | number' is not assignable to type 'string': +!!! error TS2322: Type 'number' is not assignable to type 'string'. a: '', b: 1, c: () => { }, diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt index 0e9cff15560..4d0488ec80f 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt @@ -4,10 +4,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(26,5): error TS2412: Property '"4.0"' of type 'string' is not assignable to numeric index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(34,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(35,5): error TS2412: Property '"4.0"' of type 'string' is not assignable to numeric index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(39,5): error TS2322: Type '{ [x: number]: {}; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }': +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(39,5): error TS2322: Type '{ [x: number]: string | number | A; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }': Index signatures are incompatible: - Type '{}' is not assignable to type 'A': - Property 'foo' is missing in type '{}'. + Type 'string | number | A' is not assignable to type 'A': + Type 'string' is not assignable to type 'A'. ==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts (7 errors) ==== @@ -63,10 +63,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo // error var b: { [x: number]: A } = { ~ -!!! error TS2322: Type '{ [x: number]: {}; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }': +!!! error TS2322: Type '{ [x: number]: string | number | A; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }': !!! error TS2322: Index signatures are incompatible: -!!! error TS2322: Type '{}' is not assignable to type 'A': -!!! error TS2322: Property 'foo' is missing in type '{}'. +!!! error TS2322: Type 'string | number | A' is not assignable to type 'A': +!!! error TS2322: Type 'string' is not assignable to type 'A'. 1.0: new A(), 2.0: new B(), "2.5": new B(), diff --git a/tests/baselines/reference/parser15.4.4.14-9-2.errors.txt b/tests/baselines/reference/parser15.4.4.14-9-2.errors.txt index ab9bab7890c..237541b40f7 100644 --- a/tests/baselines/reference/parser15.4.4.14-9-2.errors.txt +++ b/tests/baselines/reference/parser15.4.4.14-9-2.errors.txt @@ -1,7 +1,8 @@ +tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(16,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(25,1): error TS2304: Cannot find name 'runTestCase'. -==== tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts (2 errors) ==== /// Copyright (c) 2012 Ecma International. All rights reserved. /// Ecma International makes this code available under the terms and conditions set /// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the @@ -18,6 +19,8 @@ tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(25,1): error T var one = 1; var _float = -(4/3); var a = new Array(false,undefined,null,"0",obj,-1.3333333333333, "str",-0,true,+0, one, 1,0, false, _float, -(4/3)); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. if (a.indexOf(-(4/3)) === 14 && // a[14]=_float===-(4/3) a.indexOf(0) === 7 && // a[7] = +0, 0===+0 a.indexOf(-0) === 7 && // a[7] = +0, -0===+0 diff --git a/tests/baselines/reference/promisePermutations.errors.txt b/tests/baselines/reference/promisePermutations.errors.txt index ee723821cce..0b2aa01bb5c 100644 --- a/tests/baselines/reference/promisePermutations.errors.txt +++ b/tests/baselines/reference/promisePermutations.errors.txt @@ -1,3 +1,4 @@ +tests/cases/compiler/promisePermutations.ts(74,70): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. tests/cases/compiler/promisePermutations.ts(79,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations.ts(82,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations.ts(83,19): error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. @@ -19,13 +20,20 @@ tests/cases/compiler/promisePermutations.ts(120,19): error TS2345: Argument of t tests/cases/compiler/promisePermutations.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations.ts(122,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations.ts(126,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(129,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/promisePermutations.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations.ts(134,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(137,11): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations.ts(144,12): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations.ts(152,12): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations.ts(156,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(159,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. -==== tests/cases/compiler/promisePermutations.ts (25 errors) ==== +==== tests/cases/compiler/promisePermutations.ts (33 errors) ==== interface Promise { then(success?: (value: T) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; then(success?: (value: T) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; @@ -39,7 +47,7 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -99,7 +107,9 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); - var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); + var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // error + ~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -118,7 +128,7 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. - var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); + var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -197,6 +207,8 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -210,7 +222,9 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok - var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok + var s9f = s9.then(testFunction, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); @@ -218,6 +232,8 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -225,17 +241,25 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok - var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok + var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; - var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok + var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. - var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok - var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok + var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. + var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/baselines/reference/promisePermutations.js b/tests/baselines/reference/promisePermutations.js index 189ef40335e..e59e49d6f8c 100644 --- a/tests/baselines/reference/promisePermutations.js +++ b/tests/baselines/reference/promisePermutations.js @@ -12,7 +12,7 @@ interface IPromise { then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -72,7 +72,7 @@ var s3: Promise; var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); -var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); +var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // error var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -83,7 +83,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -135,7 +135,7 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); @@ -150,15 +150,15 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok @@ -192,7 +192,7 @@ var s3; var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); -var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); +var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // error var r4; var sIPromise; var sPromise; @@ -249,7 +249,7 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(function (x) { return x; }); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok @@ -263,14 +263,14 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(function (x) { return x; }); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok var s12 = testFunction12(function (x) { return x; }); diff --git a/tests/baselines/reference/promisePermutations2.errors.txt b/tests/baselines/reference/promisePermutations2.errors.txt index f85a3eb925f..e512ca73277 100644 --- a/tests/baselines/reference/promisePermutations2.errors.txt +++ b/tests/baselines/reference/promisePermutations2.errors.txt @@ -20,15 +20,20 @@ tests/cases/compiler/promisePermutations2.ts(119,19): error TS2345: Argument of tests/cases/compiler/promisePermutations2.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations2.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(125,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(128,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/promisePermutations2.ts(131,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations2.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(136,11): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations2.ts(143,12): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations2.ts(151,12): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations2.ts(155,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(157,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(158,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. -==== tests/cases/compiler/promisePermutations2.ts (28 errors) ==== +==== tests/cases/compiler/promisePermutations2.ts (33 errors) ==== // same as promisePermutations but without the same overloads in Promise interface Promise { @@ -41,7 +46,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -122,7 +127,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. - var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); + var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -200,7 +205,9 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok - var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok + var r9d = r9.then(testFunction, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -214,14 +221,18 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok - var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok + var s9f = s9.then(testFunction, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok - var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok + var r10d = r10.then(testFunction, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -229,11 +240,15 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok - var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok + var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; - var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok + var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok ~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/promisePermutations2.js b/tests/baselines/reference/promisePermutations2.js index 008594ee120..a7b5d8cf835 100644 --- a/tests/baselines/reference/promisePermutations2.js +++ b/tests/baselines/reference/promisePermutations2.js @@ -11,7 +11,7 @@ interface IPromise { then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -82,7 +82,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -126,7 +126,7 @@ var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -134,14 +134,14 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -149,11 +149,11 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok @@ -241,7 +241,7 @@ var r9; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -249,13 +249,13 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(function (x) { return x; }); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(function (x) { return x; }); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -263,10 +263,10 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok diff --git a/tests/baselines/reference/promisePermutations3.errors.txt b/tests/baselines/reference/promisePermutations3.errors.txt index edd5f879043..97d47cc7f7f 100644 --- a/tests/baselines/reference/promisePermutations3.errors.txt +++ b/tests/baselines/reference/promisePermutations3.errors.txt @@ -1,4 +1,5 @@ tests/cases/compiler/promisePermutations3.ts(68,69): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(73,70): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. tests/cases/compiler/promisePermutations3.ts(78,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations3.ts(81,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations3.ts(82,19): error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. @@ -20,15 +21,21 @@ tests/cases/compiler/promisePermutations3.ts(119,19): error TS2345: Argument of tests/cases/compiler/promisePermutations3.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations3.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(125,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(128,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/promisePermutations3.ts(131,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations3.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(136,11): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations3.ts(143,12): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations3.ts(151,12): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/promisePermutations3.ts(155,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(157,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(158,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations3.ts(159,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of type '{ (x: T): IPromise; (x: T, y: T): Promise; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise'. -==== tests/cases/compiler/promisePermutations3.ts (28 errors) ==== +==== tests/cases/compiler/promisePermutations3.ts (35 errors) ==== // same as promisePermutations but without the same overloads in IPromise interface Promise { @@ -41,7 +48,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of interface IPromise { then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -104,6 +111,8 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); + ~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -122,7 +131,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. - var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); + var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -200,7 +209,9 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok - var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok + var r9d = r9.then(testFunction, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -214,14 +225,18 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok - var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok + var s9f = s9.then(testFunction, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok - var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok + var r10d = r10.then(testFunction, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -229,7 +244,9 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok - var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok + var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; @@ -240,8 +257,12 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. - var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok - var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok + var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. + var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/baselines/reference/promisePermutations3.js b/tests/baselines/reference/promisePermutations3.js index d65d8c233f8..eb9c882b971 100644 --- a/tests/baselines/reference/promisePermutations3.js +++ b/tests/baselines/reference/promisePermutations3.js @@ -11,7 +11,7 @@ interface Promise { interface IPromise { then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -82,7 +82,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -126,7 +126,7 @@ var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -134,14 +134,14 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -149,15 +149,15 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok @@ -241,7 +241,7 @@ var r9; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -249,13 +249,13 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(function (x) { return x; }); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(function (x) { return x; }); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -263,14 +263,14 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11; var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok var s11; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(function (x) { return x; }); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok var s12 = testFunction12(function (x) { return x; }); diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt index a731dcca188..b71b04263b1 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt @@ -24,9 +24,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(71,5): error TS2411: Property 'foo' of type '() => string' is not assignable to string index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(73,5): error TS2411: Property '"4.0"' of type 'number' is not assignable to string index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(74,5): error TS2411: Property 'f' of type 'MyString' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: string]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: string]: string | number | MyString | { (): void; }; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': Index signatures are incompatible: - Type '{}' is not assignable to type 'string'. + Type 'string | number | MyString | { (): void; }' is not assignable to type 'string': + Type 'number' is not assignable to type 'string'. ==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts (27 errors) ==== @@ -159,9 +160,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon // error var b: { [x: string]: string; } = { ~ -!!! error TS2322: Type '{ [x: string]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': +!!! error TS2322: Type '{ [x: string]: string | number | MyString | { (): void; }; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': !!! error TS2322: Index signatures are incompatible: -!!! error TS2322: Type '{}' is not assignable to type 'string'. +!!! error TS2322: Type 'string | number | MyString | { (): void; }' is not assignable to type 'string': +!!! error TS2322: Type 'number' is not assignable to type 'string'. a: '', b: 1, c: () => { }, diff --git a/tests/baselines/reference/subtypesOfTypeParameter.errors.txt b/tests/baselines/reference/subtypesOfTypeParameter.errors.txt index a986258bf11..bdb3c9a056f 100644 --- a/tests/baselines/reference/subtypesOfTypeParameter.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameter.errors.txt @@ -1,46 +1,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(7,7): error TS2416: Class 'D1' incorrectly extends base class 'C3': Types of property 'foo' are incompatible: Type 'U' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(12,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(13,13): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(38,14): error TS2367: No best common type exists between 'number' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(39,14): error TS2367: No best common type exists between 'T' and 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(41,14): error TS2367: No best common type exists between 'string' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(42,14): error TS2367: No best common type exists between 'T' and 'string'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(44,14): error TS2367: No best common type exists between 'boolean' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(45,14): error TS2367: No best common type exists between 'T' and 'boolean'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(47,14): error TS2367: No best common type exists between 'Date' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(48,14): error TS2367: No best common type exists between 'T' and 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(50,14): error TS2367: No best common type exists between 'RegExp' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(51,14): error TS2367: No best common type exists between 'T' and 'RegExp'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(53,14): error TS2367: No best common type exists between '{ foo: number; }' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(54,14): error TS2367: No best common type exists between 'T' and '{ foo: number; }'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(56,14): error TS2367: No best common type exists between '() => void' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(57,14): error TS2367: No best common type exists between 'T' and '() => void'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(59,14): error TS2367: No best common type exists between '(x: T) => T' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(60,15): error TS2367: No best common type exists between 'T' and '(x: T) => T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(63,14): error TS2367: No best common type exists between 'I1' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(64,14): error TS2367: No best common type exists between 'T' and 'I1'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(67,15): error TS2367: No best common type exists between 'C1' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(68,15): error TS2367: No best common type exists between 'T' and 'C1'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(72,15): error TS2367: No best common type exists between 'C2' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(73,15): error TS2367: No best common type exists between 'T' and 'C2'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(76,15): error TS2367: No best common type exists between 'typeof E' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(77,15): error TS2367: No best common type exists between 'T' and 'typeof E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(79,15): error TS2367: No best common type exists between 'E' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(80,15): error TS2367: No best common type exists between 'T' and 'E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(83,15): error TS2367: No best common type exists between 'typeof f' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(84,15): error TS2367: No best common type exists between 'T' and 'typeof f'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(87,15): error TS2367: No best common type exists between 'typeof c' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(88,15): error TS2367: No best common type exists between 'T' and 'typeof c'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(91,19): error TS2367: No best common type exists between 'T' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(92,19): error TS2367: No best common type exists between 'T' and 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(95,21): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(96,19): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(97,19): error TS2367: No best common type exists between 'U' and 'T'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts (38 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts (2 errors) ==== // checking whether other types are subtypes of type parameters class C3 { @@ -57,11 +21,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf function f1(x: T, y: U) { var r = true ? x : y; // error - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? y : x; // error - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. } interface I1 { foo: number; } @@ -87,135 +47,67 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf var r0b = true ? x : u; var r1 = true ? 1 : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'number' and 'T'. var r1 = true ? x : 1; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'number'. var r2 = true ? '' : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'string' and 'T'. var r2 = true ? x : ''; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'string'. var r3 = true ? true : x; - ~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'boolean' and 'T'. var r3 = true ? x : true; - ~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'boolean'. var r4 = true ? new Date() : x; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Date' and 'T'. var r4 = true ? x : new Date(); - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'Date'. var r5 = true ? /1/ : x; - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'RegExp' and 'T'. var r5 = true ? x : /1/; - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'RegExp'. var r6 = true ? { foo: 1 } : x; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between '{ foo: number; }' and 'T'. var r6 = true ? x : { foo: 1 }; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and '{ foo: number; }'. var r7 = true ? () => { } : x; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between '() => void' and 'T'. var r7 = true ? x : () => { }; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and '() => void'. var r8 = true ? (x: T) => { return x } : x; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between '(x: T) => T' and 'T'. var r8b = true ? x : (x: T) => { return x }; // type parameters not identical across declarations - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and '(x: T) => T'. var i1: I1; var r9 = true ? i1 : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'I1' and 'T'. var r9 = true ? x : i1; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'I1'. var c1: C1; var r10 = true ? c1 : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'C1' and 'T'. var r10 = true ? x : c1; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'C1'. var c2: C2; var r12 = true ? c2 : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'C2' and 'T'. var r12 = true ? x : c2; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'C2'. var r13 = true ? E : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'typeof E' and 'T'. var r13 = true ? x : E; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'typeof E'. var r14 = true ? E.A : x; - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'E' and 'T'. var r14 = true ? x : E.A; - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'E'. var af: typeof f; var r15 = true ? af : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'typeof f' and 'T'. var r15 = true ? x : af; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'typeof f'. var ac: typeof c; var r16 = true ? ac : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'typeof c' and 'T'. var r16 = true ? x : ac; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'typeof c'. function f17(a: T) { var r17 = true ? x : a; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'T'. var r17 = true ? a : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'T'. } function f18(a: U) { ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. var r18 = true ? x : a; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r18 = true ? a : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. } var r19 = true ? new Object() : x; // BCT is Object diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.errors.txt index c2b429c08bb..1a2ced3b6f2 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.errors.txt @@ -1,46 +1,18 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(3,13): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(4,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(5,13): error TS2367: No best common type exists between 'U' and 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(9,13): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(9,26): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(10,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(11,13): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(14,14): error TS2367: No best common type exists between 'V' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(15,14): error TS2367: No best common type exists between 'U' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(18,14): error TS2367: No best common type exists between 'V' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(19,14): error TS2367: No best common type exists between 'T' and 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(23,13): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(24,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(25,13): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(28,14): error TS2367: No best common type exists between 'T' and 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(29,14): error TS2367: No best common type exists between 'Date' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(60,14): error TS2367: No best common type exists between 'number' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(61,14): error TS2367: No best common type exists between 'T' and 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(65,14): error TS2367: No best common type exists between 'string' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(66,14): error TS2367: No best common type exists between 'T' and 'string'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(70,14): error TS2367: No best common type exists between 'boolean' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(71,14): error TS2367: No best common type exists between 'T' and 'boolean'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(118,15): error TS2367: No best common type exists between 'typeof E' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(119,15): error TS2367: No best common type exists between 'T' and 'typeof E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(121,15): error TS2367: No best common type exists between 'E' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(122,15): error TS2367: No best common type exists between 'T' and 'E'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(143,18): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(144,19): error TS2367: No best common type exists between 'T' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(145,19): error TS2367: No best common type exists between 'V' and 'T'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts (29 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts (5 errors) ==== // checking whether other types are subtypes of type parameters with constraints function f1(x: T, y: U) { ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. var r = true ? x : y; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? y : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. } // V > U > T @@ -50,27 +22,15 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. var r = true ? x : y; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? y : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. // ok var r2 = true ? z : y; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'U'. var r2 = true ? y : z; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'V'. // ok - var r2 = true ? z : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'T'. - var r2 = true ? x : z; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'V'. + var r2a = true ? z : x; + var r2b = true ? x : z; } // Date > U > T @@ -78,19 +38,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. var r = true ? x : y; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? y : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. // ok var r2 = true ? x : new Date(); - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'Date'. var r2 = true ? new Date() : x; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Date' and 'T'. // ok var r3 = true ? y : new Date(); @@ -121,30 +73,18 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf } function f5(x: T) { - var r1 = true ? 1 : x; // error - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'number' and 'T'. - var r1 = true ? x : 1; // error - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'number'. + var r1 = true ? 1 : x; // ok + var r1 = true ? x : 1; // ok } function f6(x: T) { - var r2 = true ? '' : x; // error - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'string' and 'T'. - var r2 = true ? x : ''; // error - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'string'. + var r2 = true ? '' : x; // ok + var r2 = true ? x : ''; // ok } function f7(x: T) { - var r3 = true ? true : x; // error - ~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'boolean' and 'T'. - var r3 = true ? x : true; // error - ~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'boolean'. + var r3 = true ? true : x; // ok + var r3 = true ? x : true; // ok } function f8(x: T) { @@ -191,19 +131,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf } function f16(x: T) { - var r13 = true ? E : x; // BUG 831833 - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'typeof E' and 'T'. - var r13 = true ? x : E; // BUG 831833 - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'typeof E'. + var r13 = true ? E : x; // ok + var r13 = true ? x : E; // ok - var r14 = true ? E.A : x; // BUG 831833 - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'E' and 'T'. - var r14 = true ? x : E.A; // BUG 831833 - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'E'. + var r14 = true ? E.A : x; // ok + var r14 = true ? x : E.A; // ok } function f17(x: T) { @@ -228,11 +160,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. var r18 = true ? x : a; // ok - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'V'. var r18 = true ? a : x; // ok - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'T'. } } diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.js b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.js index bf582fe13e5..bd729f36222 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.js +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.js @@ -16,8 +16,8 @@ function f2(x: T, y: U, z: V) { var r2 = true ? y : z; // ok - var r2 = true ? z : x; - var r2 = true ? x : z; + var r2a = true ? z : x; + var r2b = true ? x : z; } // Date > U > T @@ -58,18 +58,18 @@ function f4(x: T) { } function f5(x: T) { - var r1 = true ? 1 : x; // error - var r1 = true ? x : 1; // error + var r1 = true ? 1 : x; // ok + var r1 = true ? x : 1; // ok } function f6(x: T) { - var r2 = true ? '' : x; // error - var r2 = true ? x : ''; // error + var r2 = true ? '' : x; // ok + var r2 = true ? x : ''; // ok } function f7(x: T) { - var r3 = true ? true : x; // error - var r3 = true ? x : true; // error + var r3 = true ? true : x; // ok + var r3 = true ? x : true; // ok } function f8(x: T) { @@ -116,11 +116,11 @@ function f15>(x: T) { } function f16(x: T) { - var r13 = true ? E : x; // BUG 831833 - var r13 = true ? x : E; // BUG 831833 + var r13 = true ? E : x; // ok + var r13 = true ? x : E; // ok - var r14 = true ? E.A : x; // BUG 831833 - var r14 = true ? x : E.A; // BUG 831833 + var r14 = true ? E.A : x; // ok + var r14 = true ? x : E.A; // ok } function f17(x: T) { @@ -171,8 +171,8 @@ function f2(x, y, z) { var r2 = true ? z : y; var r2 = true ? y : z; // ok - var r2 = true ? z : x; - var r2 = true ? x : z; + var r2a = true ? z : x; + var r2b = true ? x : z; } // Date > U > T function f3(x, y) { @@ -222,16 +222,16 @@ function f4(x) { var r0b = true ? x : u; // ok } function f5(x) { - var r1 = true ? 1 : x; // error - var r1 = true ? x : 1; // error + var r1 = true ? 1 : x; // ok + var r1 = true ? x : 1; // ok } function f6(x) { - var r2 = true ? '' : x; // error - var r2 = true ? x : ''; // error + var r2 = true ? '' : x; // ok + var r2 = true ? x : ''; // ok } function f7(x) { - var r3 = true ? true : x; // error - var r3 = true ? x : true; // error + var r3 = true ? true : x; // ok + var r3 = true ? x : true; // ok } function f8(x) { var r4 = true ? new Date() : x; // ok @@ -275,10 +275,10 @@ function f15(x) { var r12 = true ? x : c2; // ok } function f16(x) { - var r13 = true ? E : x; // BUG 831833 - var r13 = true ? x : E; // BUG 831833 - var r14 = true ? 0 /* A */ : x; // BUG 831833 - var r14 = true ? x : 0 /* A */; // BUG 831833 + var r13 = true ? E : x; // ok + var r13 = true ? x : E; // ok + var r14 = true ? 0 /* A */ : x; // ok + var r14 = true ? x : 0 /* A */; // ok } function f17(x) { var af; diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.errors.txt index f26389bb2a2..2a5fa5ad362 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.errors.txt @@ -1,13 +1,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(3,12): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(5,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(6,13): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(9,14): error TS2367: No best common type exists between 'T' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(10,14): error TS2367: No best common type exists between 'V' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(13,14): error TS2367: No best common type exists between 'V' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(14,14): error TS2367: No best common type exists between 'U' and 'V'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts (7 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts (1 errors) ==== // checking whether other types are subtypes of type parameters with constraints function f(t: T, u: U, v: V) { @@ -15,25 +9,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. // ok var r = true ? t : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? u : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. - // error + // ok var r2 = true ? t : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'V'. var r2 = true ? v : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'T'. - // error + // ok var r3 = true ? v : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'U'. var r3 = true ? u : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'V'. } \ No newline at end of file diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.js b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.js index 229beffd334..790c0fa5b96 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.js +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.js @@ -6,11 +6,11 @@ function f(t: T, u: U, v: V) { var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; } @@ -21,10 +21,10 @@ function f(t, u, v) { // ok var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; } diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt index 082d78d43d5..872cb8ef965 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt @@ -1,11 +1,3 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(6,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(7,13): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(10,14): error TS2367: No best common type exists between 'T' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(11,14): error TS2367: No best common type exists between 'V' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(14,14): error TS2367: No best common type exists between 'V' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(15,14): error TS2367: No best common type exists between 'U' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(26,14): error TS2367: No best common type exists between 'V' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(27,14): error TS2367: No best common type exists between 'Foo' and 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(45,7): error TS2416: Class 'D3' incorrectly extends base class 'B1': Types of property 'foo' are incompatible: Type 'V' is not assignable to type 'Foo': @@ -29,34 +21,22 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts (18 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts (10 errors) ==== // checking whether other types are subtypes of type parameters with constraints class Foo { foo: number; } function f(t: T, u: U, v: V) { - // error + // ok var r = true ? t : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? u : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. - // error + // ok var r2 = true ? t : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'V'. var r2 = true ? v : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'T'. - // error + // ok var r3 = true ? v : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'U'. var r3 = true ? u : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'V'. // ok var r4 = true ? t : new Foo(); @@ -66,13 +46,9 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // BUG, should be error + // ok var r6 = true ? v : new Foo(); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'Foo'. var r6 = true ? new Foo() : v; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'V'. } diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.js b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.js index 96983ecf68f..f1cf61d484f 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.js +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.js @@ -3,15 +3,15 @@ class Foo { foo: number; } function f(t: T, u: U, v: V) { - // error + // ok var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; @@ -23,7 +23,7 @@ function f(t: T, u: U, v: V) { var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // BUG, should be error + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; @@ -92,13 +92,13 @@ var Foo = (function () { return Foo; })(); function f(t, u, v) { - // error + // ok var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; // ok @@ -107,7 +107,7 @@ function f(t, u, v) { // ok var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // BUG, should be error + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; } diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt index bf7cbbcae03..f4b1d7ef041 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt @@ -1,30 +1,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(4,12): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(4,30): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(4,48): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(6,14): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(7,14): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(10,14): error TS2367: No best common type exists between 'T' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(11,14): error TS2367: No best common type exists between 'V' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(14,14): error TS2367: No best common type exists between 'V' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(15,14): error TS2367: No best common type exists between 'U' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(18,14): error TS2367: No best common type exists between 'T' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(19,14): error TS2367: No best common type exists between 'Foo' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(22,14): error TS2367: No best common type exists between 'U' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(23,14): error TS2367: No best common type exists between 'Foo' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(26,14): error TS2367: No best common type exists between 'V' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(27,14): error TS2367: No best common type exists between 'Foo' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(31,14): error TS2367: No best common type exists between 'T' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(32,14): error TS2367: No best common type exists between 'Foo' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(35,14): error TS2367: No best common type exists between 'U' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(36,14): error TS2367: No best common type exists between 'Foo' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(39,14): error TS2367: No best common type exists between 'V' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(40,14): error TS2367: No best common type exists between 'Foo' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(44,15): error TS2367: No best common type exists between 'T' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(45,15): error TS2367: No best common type exists between 'Foo' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(48,15): error TS2367: No best common type exists between 'U' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(49,15): error TS2367: No best common type exists between 'Foo' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(52,15): error TS2367: No best common type exists between 'V' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(53,15): error TS2367: No best common type exists between 'Foo' and 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(61,14): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(61,32): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(61,50): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. @@ -111,7 +87,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(153,50): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts (99 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts (75 errors) ==== // checking whether other types are subtypes of type parameters with constraints class Foo { foo: T; } @@ -122,103 +98,55 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. ~~~~~~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. - // error + // ok var r1 = true ? t : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r1 = true ? u : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. - // error + // ok var r2 = true ? t : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'V'. var r2 = true ? v : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'T'. - // error + // ok var r3 = true ? v : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'U'. var r3 = true ? u : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'V'. - // ok? + // ok var r4 = true ? t : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'Foo'. var r4 = true ? new Foo() : t; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'T'. - // ok? + // ok var r5 = true ? u : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'Foo'. var r5 = true ? new Foo() : u; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'U'. - // ok? + // ok var r6 = true ? v : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'Foo'. var r6 = true ? new Foo() : v; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'V'. - // ok? + // ok var r7 = true ? t : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'Foo'. var r7 = true ? new Foo() : t; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'T'. - // ok? + // ok var r8 = true ? u : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'Foo'. var r8 = true ? new Foo() : u; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'U'. - // ok? + // ok var r9 = true ? v : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'Foo'. var r9 = true ? new Foo() : v; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'V'. - // ok? + // ok var r10 = true ? t : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'Foo'. var r10 = true ? new Foo() : t; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'T'. - // ok? + // ok var r11 = true ? u : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'Foo'. var r11 = true ? new Foo() : u; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'U'. - // ok? + // ok var r12 = true ? v : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'Foo'. var r12 = true ? new Foo() : v; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'V'. } module M1 { diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.js b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.js index e345d746bf7..1caa7d99087 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.js +++ b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.js @@ -3,53 +3,53 @@ class Foo { foo: T; } function f, U extends Foo, V extends Foo>(t: T, u: U, v: V) { - // error + // ok var r1 = true ? t : u; var r1 = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; - // ok? + // ok var r4 = true ? t : new Foo(); var r4 = true ? new Foo() : t; - // ok? + // ok var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // ok? + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; - // ok? + // ok var r7 = true ? t : new Foo(); var r7 = true ? new Foo() : t; - // ok? + // ok var r8 = true ? u : new Foo(); var r8 = true ? new Foo() : u; - // ok? + // ok var r9 = true ? v : new Foo(); var r9 = true ? new Foo() : v; - // ok? + // ok var r10 = true ? t : new Foo(); var r10 = true ? new Foo() : t; - // ok? + // ok var r11 = true ? u : new Foo(); var r11 = true ? new Foo() : u; - // ok? + // ok var r12 = true ? v : new Foo(); var r12 = true ? new Foo() : v; } @@ -171,40 +171,40 @@ var Foo = (function () { return Foo; })(); function f(t, u, v) { - // error + // ok var r1 = true ? t : u; var r1 = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; - // ok? + // ok var r4 = true ? t : new Foo(); var r4 = true ? new Foo() : t; - // ok? + // ok var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // ok? + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; - // ok? + // ok var r7 = true ? t : new Foo(); var r7 = true ? new Foo() : t; - // ok? + // ok var r8 = true ? u : new Foo(); var r8 = true ? new Foo() : u; - // ok? + // ok var r9 = true ? v : new Foo(); var r9 = true ? new Foo() : v; - // ok? + // ok var r10 = true ? t : new Foo(); var r10 = true ? new Foo() : t; - // ok? + // ok var r11 = true ? u : new Foo(); var r11 = true ? new Foo() : u; - // ok? + // ok var r12 = true ? v : new Foo(); var r12 = true ? new Foo() : v; } diff --git a/tests/baselines/reference/subtypingWithCallSignatures2.types b/tests/baselines/reference/subtypingWithCallSignatures2.types index 5006e00d52b..12344a46f3f 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures2.types +++ b/tests/baselines/reference/subtypingWithCallSignatures2.types @@ -368,8 +368,8 @@ var r2a = [r2arg1, r2arg2]; >r2arg2 : (x: number) => string[] var r2b = [r2arg2, r2arg1]; ->r2b : { (x: number): string[]; }[] ->[r2arg2, r2arg1] : { (x: number): string[]; }[] +>r2b : { (x: T): string[]; }[] +>[r2arg2, r2arg1] : { (x: T): string[]; }[] >r2arg2 : (x: number) => string[] >r2arg1 : (x: T) => string[] @@ -399,8 +399,8 @@ var r3a = [r3arg1, r3arg2]; >r3arg2 : (x: number) => void var r3b = [r3arg2, r3arg1]; ->r3b : { (x: number): void; }[] ->[r3arg2, r3arg1] : { (x: number): void; }[] +>r3b : { (x: T): T; }[] +>[r3arg2, r3arg1] : { (x: T): T; }[] >r3arg2 : (x: number) => void >r3arg1 : (x: T) => T @@ -795,8 +795,8 @@ var r12a = [r12arg1, r12arg2]; >r12arg2 : (x: Base[], y: Derived2[]) => Derived[] var r12b = [r12arg2, r12arg1]; ->r12b : { (x: Base[], y: Derived2[]): Derived[]; }[] ->[r12arg2, r12arg1] : { (x: Base[], y: Derived2[]): Derived[]; }[] +>r12b : { (x: Base[], y: T): Derived[]; }[] +>[r12arg2, r12arg1] : { (x: Base[], y: T): Derived[]; }[] >r12arg2 : (x: Base[], y: Derived2[]) => Derived[] >r12arg1 : (x: Base[], y: T) => Derived[] diff --git a/tests/baselines/reference/subtypingWithCallSignatures3.types b/tests/baselines/reference/subtypingWithCallSignatures3.types index 8c136113464..be5fb44c9c7 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures3.types +++ b/tests/baselines/reference/subtypingWithCallSignatures3.types @@ -340,14 +340,14 @@ module Errors { >r3arg : (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U var r3a = [r3arg2, r3arg]; ->r3a : {}[] ->[r3arg2, r3arg] : {}[] +>r3a : Array<{ (x: (arg: T) => U, y: (arg2: { foo: number; }) => U): (r: T) => U; } | { (x: (arg: Base) => Derived, y: (arg2: Base) => Derived): (r: Base) => Derived; }> +>[r3arg2, r3arg] : Array<{ (x: (arg: T) => U, y: (arg2: { foo: number; }) => U): (r: T) => U; } | { (x: (arg: Base) => Derived, y: (arg2: Base) => Derived): (r: Base) => Derived; }> >r3arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived >r3arg : (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U var r3b = [r3arg, r3arg2]; ->r3b : {}[] ->[r3arg, r3arg2] : {}[] +>r3b : Array<{ (x: (arg: T) => U, y: (arg2: { foo: number; }) => U): (r: T) => U; } | { (x: (arg: Base) => Derived, y: (arg2: Base) => Derived): (r: Base) => Derived; }> +>[r3arg, r3arg2] : Array<{ (x: (arg: T) => U, y: (arg2: { foo: number; }) => U): (r: T) => U; } | { (x: (arg: Base) => Derived, y: (arg2: Base) => Derived): (r: Base) => Derived; }> >r3arg : (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U >r3arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived @@ -535,8 +535,8 @@ module Errors { >r7arg3 : (x: { a: T; b: T; }) => number var r7e = [r7arg3, r7arg2]; ->r7e : { (x: { a: T; b: T; }): number; }[] ->[r7arg3, r7arg2] : { (x: { a: T; b: T; }): number; }[] +>r7e : { (x: { a: string; b: number; }): number; }[] +>[r7arg3, r7arg2] : { (x: { a: string; b: number; }): number; }[] >r7arg3 : (x: { a: T; b: T; }) => number >r7arg2 : (x: { a: string; b: number; }) => number diff --git a/tests/baselines/reference/subtypingWithCallSignatures4.types b/tests/baselines/reference/subtypingWithCallSignatures4.types index 07b3af3e540..f31a4fa928e 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures4.types +++ b/tests/baselines/reference/subtypingWithCallSignatures4.types @@ -318,8 +318,8 @@ var r3a = [r3arg, r3arg2]; >r3arg2 : (x: T) => void var r3b = [r3arg2, r3arg]; ->r3b : { (x: T): void; }[] ->[r3arg2, r3arg] : { (x: T): void; }[] +>r3b : { (x: T): T; }[] +>[r3arg2, r3arg] : { (x: T): T; }[] >r3arg2 : (x: T) => void >r3arg : (x: T) => T @@ -442,8 +442,8 @@ var r6a = [r6arg, r6arg2]; >r6arg2 : (x: (arg: T) => Derived) => T var r6b = [r6arg2, r6arg]; ->r6b : { (x: (arg: T) => Derived): T; }[] ->[r6arg2, r6arg] : { (x: (arg: T) => Derived): T; }[] +>r6b : { (x: (arg: T) => U): T; }[] +>[r6arg2, r6arg] : { (x: (arg: T) => U): T; }[] >r6arg2 : (x: (arg: T) => Derived) => T >r6arg : (x: (arg: T) => U) => T @@ -491,8 +491,8 @@ var r11a = [r11arg, r11arg2]; >r11arg2 : (x: { foo: T; }, y: { foo: T; bar: T; }) => Base var r11b = [r11arg2, r11arg]; ->r11b : { (x: { foo: T; }, y: { foo: T; bar: T; }): Base; }[] ->[r11arg2, r11arg] : { (x: { foo: T; }, y: { foo: T; bar: T; }): Base; }[] +>r11b : { (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] +>[r11arg2, r11arg] : { (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] >r11arg2 : (x: { foo: T; }, y: { foo: T; bar: T; }) => Base >r11arg : (x: { foo: T; }, y: { foo: U; bar: U; }) => Base @@ -534,8 +534,8 @@ var r15a = [r15arg, r15arg2]; >r15arg2 : (x: { a: T; b: T; }) => T[] var r15b = [r15arg2, r15arg]; ->r15b : { (x: { a: T; b: T; }): T[]; }[] ->[r15arg2, r15arg] : { (x: { a: T; b: T; }): T[]; }[] +>r15b : { (x: { a: U; b: V; }): U[]; }[] +>[r15arg2, r15arg] : { (x: { a: U; b: V; }): U[]; }[] >r15arg2 : (x: { a: T; b: T; }) => T[] >r15arg : (x: { a: U; b: V; }) => U[] diff --git a/tests/baselines/reference/subtypingWithConstructSignatures2.types b/tests/baselines/reference/subtypingWithConstructSignatures2.types index fdba6014751..3832697d04c 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures2.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures2.types @@ -360,8 +360,8 @@ var r2a = [r2arg1, r2arg2]; >r2arg2 : new (x: number) => string[] var r2b = [r2arg2, r2arg1]; ->r2b : { new (x: number): string[]; }[] ->[r2arg2, r2arg1] : { new (x: number): string[]; }[] +>r2b : { new (x: T): string[]; }[] +>[r2arg2, r2arg1] : { new (x: T): string[]; }[] >r2arg2 : new (x: number) => string[] >r2arg1 : new (x: T) => string[] @@ -389,8 +389,8 @@ var r3a = [r3arg1, r3arg2]; >r3arg2 : new (x: number) => void var r3b = [r3arg2, r3arg1]; ->r3b : { new (x: number): void; }[] ->[r3arg2, r3arg1] : { new (x: number): void; }[] +>r3b : { new (x: T): T; }[] +>[r3arg2, r3arg1] : { new (x: T): T; }[] >r3arg2 : new (x: number) => void >r3arg1 : new (x: T) => T @@ -630,14 +630,14 @@ var r9 = foo9(r9arg1); // any >r9arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U var r9a = [r9arg1, r9arg2]; ->r9a : {}[] ->[r9arg1, r9arg2] : {}[] +>r9a : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): new (r: T) => U; } | { new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> +>[r9arg1, r9arg2] : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): new (r: T) => U; } | { new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> >r9arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U >r9arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived var r9b = [r9arg2, r9arg1]; ->r9b : {}[] ->[r9arg2, r9arg1] : {}[] +>r9b : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): new (r: T) => U; } | { new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> +>[r9arg2, r9arg1] : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): new (r: T) => U; } | { new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> >r9arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived >r9arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U @@ -747,8 +747,8 @@ var r12a = [r12arg1, r12arg2]; >r12arg2 : new (x: Base[], y: Derived2[]) => Derived[] var r12b = [r12arg2, r12arg1]; ->r12b : { new (x: Base[], y: Derived2[]): Derived[]; }[] ->[r12arg2, r12arg1] : { new (x: Base[], y: Derived2[]): Derived[]; }[] +>r12b : { new (x: Base[], y: T): Derived[]; }[] +>[r12arg2, r12arg1] : { new (x: Base[], y: T): Derived[]; }[] >r12arg2 : new (x: Base[], y: Derived2[]) => Derived[] >r12arg1 : new (x: Base[], y: T) => Derived[] diff --git a/tests/baselines/reference/subtypingWithConstructSignatures3.types b/tests/baselines/reference/subtypingWithConstructSignatures3.types index cf4db8939fd..ff6b9adef0a 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures3.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures3.types @@ -318,14 +318,14 @@ module Errors { >r3arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U var r3a = [r3arg2, r3arg1]; ->r3a : {}[] ->[r3arg2, r3arg1] : {}[] +>r3a : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U): new (r: T) => U; } | { new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> +>[r3arg2, r3arg1] : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U): new (r: T) => U; } | { new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> >r3arg2 : new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived >r3arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U var r3b = [r3arg1, r3arg2]; ->r3b : {}[] ->[r3arg1, r3arg2] : {}[] +>r3b : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U): new (r: T) => U; } | { new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> +>[r3arg1, r3arg2] : Array<{ new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U): new (r: T) => U; } | { new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived): new (r: Base) => Derived; }> >r3arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U >r3arg2 : new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived @@ -497,8 +497,8 @@ module Errors { >r7arg3 : new (x: { a: T; b: T; }) => number var r7e = [r7arg3, r7arg2]; ->r7e : { new (x: { a: T; b: T; }): number; }[] ->[r7arg3, r7arg2] : { new (x: { a: T; b: T; }): number; }[] +>r7e : { new (x: { a: string; b: number; }): number; }[] +>[r7arg3, r7arg2] : { new (x: { a: string; b: number; }): number; }[] >r7arg3 : new (x: { a: T; b: T; }) => number >r7arg2 : new (x: { a: string; b: number; }) => number diff --git a/tests/baselines/reference/subtypingWithConstructSignatures4.types b/tests/baselines/reference/subtypingWithConstructSignatures4.types index a9116880df3..473bbe9a205 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures4.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures4.types @@ -307,8 +307,8 @@ var r3a = [r3arg, r3arg2]; >r3arg2 : new (x: T) => void var r3b = [r3arg2, r3arg]; ->r3b : { new (x: T): void; }[] ->[r3arg2, r3arg] : { new (x: T): void; }[] +>r3b : { new (x: T): T; }[] +>[r3arg2, r3arg] : { new (x: T): T; }[] >r3arg2 : new (x: T) => void >r3arg : new (x: T) => T @@ -421,8 +421,8 @@ var r6a = [r6arg, r6arg2]; >r6arg2 : new (x: new (arg: T) => Derived) => T var r6b = [r6arg2, r6arg]; ->r6b : { new (x: new (arg: T) => Derived): T; }[] ->[r6arg2, r6arg] : { new (x: new (arg: T) => Derived): T; }[] +>r6b : { new (x: new (arg: T) => U): T; }[] +>[r6arg2, r6arg] : { new (x: new (arg: T) => U): T; }[] >r6arg2 : new (x: new (arg: T) => Derived) => T >r6arg : new (x: new (arg: T) => U) => T @@ -466,8 +466,8 @@ var r11a = [r11arg, r11arg2]; >r11arg2 : new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base var r11b = [r11arg2, r11arg]; ->r11b : { new (x: { foo: T; }, y: { foo: T; bar: T; }): Base; }[] ->[r11arg2, r11arg] : { new (x: { foo: T; }, y: { foo: T; bar: T; }): Base; }[] +>r11b : { new (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] +>[r11arg2, r11arg] : { new (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] >r11arg2 : new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base >r11arg : new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base @@ -505,8 +505,8 @@ var r15a = [r15arg, r15arg2]; >r15arg2 : new (x: { a: T; b: T; }) => T[] var r15b = [r15arg2, r15arg]; ->r15b : { new (x: { a: T; b: T; }): T[]; }[] ->[r15arg2, r15arg] : { new (x: { a: T; b: T; }): T[]; }[] +>r15b : { new (x: { a: U; b: V; }): U[]; }[] +>[r15arg2, r15arg] : { new (x: { a: U; b: V; }): U[]; }[] >r15arg2 : new (x: { a: T; b: T; }) => T[] >r15arg : new (x: { a: U; b: V; }) => U[] diff --git a/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt b/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt index 74d47f12565..ac17303572d 100644 --- a/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt +++ b/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt @@ -4,10 +4,9 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW Property '1' is optional in type 'S2' but required in type 'T2'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts(26,11): error TS2429: Interface 'S3' incorrectly extends interface 'T3': Property ''1'' is optional in type 'S3' but required in type 'T3'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts(33,9): error TS2367: No best common type exists between '{ Foo: Base; }' and '{ Foo?: Derived; }'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts (4 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts (3 errors) ==== // Derived member is optional but base member is not, should be an error interface Base { foo: string; } @@ -49,6 +48,4 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW // object literal case var a: { Foo: Base; } var b: { Foo?: Derived; } - var r = true ? a : b; // error - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between '{ Foo: Base; }' and '{ Foo?: Derived; }'. \ No newline at end of file + var r = true ? a : b; // ok \ No newline at end of file diff --git a/tests/baselines/reference/subtypingWithObjectMembersOptionality2.js b/tests/baselines/reference/subtypingWithObjectMembersOptionality2.js index 186f3ba4544..33c4cc927da 100644 --- a/tests/baselines/reference/subtypingWithObjectMembersOptionality2.js +++ b/tests/baselines/reference/subtypingWithObjectMembersOptionality2.js @@ -31,11 +31,11 @@ interface S3 extends T3 { // object literal case var a: { Foo: Base; } var b: { Foo?: Derived; } -var r = true ? a : b; // error +var r = true ? a : b; // ok //// [subtypingWithObjectMembersOptionality2.js] // Derived member is optional but base member is not, should be an error // object literal case var a; var b; -var r = true ? a : b; // error +var r = true ? a : b; // ok diff --git a/tests/baselines/reference/targetTypeTest3.errors.txt b/tests/baselines/reference/targetTypeTest3.errors.txt index e81cba71a47..d9dbec41150 100644 --- a/tests/baselines/reference/targetTypeTest3.errors.txt +++ b/tests/baselines/reference/targetTypeTest3.errors.txt @@ -1,5 +1,6 @@ -tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type '{}[]' is not assignable to type 'string[]': - Type '{}' is not assignable to type 'string'. +tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type 'Array' is not assignable to type 'string[]': + Type 'string | number' is not assignable to type 'string': + Type 'number' is not assignable to type 'string'. ==== tests/cases/compiler/targetTypeTest3.ts (1 errors) ==== @@ -8,8 +9,9 @@ tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type '{}[]' is not a var a : string[] = [1,2,"3"]; // should produce an error ~ -!!! error TS2322: Type '{}[]' is not assignable to type 'string[]': -!!! error TS2322: Type '{}' is not assignable to type 'string'. +!!! error TS2322: Type 'Array' is not assignable to type 'string[]': +!!! error TS2322: Type 'string | number' is not assignable to type 'string': +!!! error TS2322: Type 'number' is not assignable to type 'string'. function func1(stuff:any[]) { return stuff; } diff --git a/tests/baselines/reference/throwStatements.types b/tests/baselines/reference/throwStatements.types index efc2ff24124..7f106daced9 100644 --- a/tests/baselines/reference/throwStatements.types +++ b/tests/baselines/reference/throwStatements.types @@ -219,7 +219,7 @@ throw []; >[] : undefined[] throw ['a', ['b']]; ->['a', ['b']] : {}[] +>['a', ['b']] : Array >['b'] : string[] throw /[a-z]/; diff --git a/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt b/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt index e1681f5cc29..823bf93e535 100644 --- a/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt +++ b/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt @@ -1,7 +1,9 @@ -tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(5,19): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. - Type '{}' is not assignable to type 'number'. -tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. - Type '{}' is not assignable to type 'number'. +tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(5,19): error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. +tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. ==== tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts (2 errors) ==== @@ -11,12 +13,14 @@ tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS // these two should give the same error this.test([1, 2, "hi", 5, ]); ~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type '{}' is not assignable to type 'number'. +!!! error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number': +!!! error TS2345: Type 'string' is not assignable to type 'number'. this.test([1, 2, "hi", 5]); ~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type '{}' is not assignable to type 'number'. +!!! error TS2345: Argument of type 'Array' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number': +!!! error TS2345: Type 'string' is not assignable to type 'number'. } } \ No newline at end of file diff --git a/tests/baselines/reference/tupleTypes.errors.txt b/tests/baselines/reference/tupleTypes.errors.txt index fcc65ff5c23..824148bc2e2 100644 --- a/tests/baselines/reference/tupleTypes.errors.txt +++ b/tests/baselines/reference/tupleTypes.errors.txt @@ -1,16 +1,17 @@ tests/cases/compiler/tupleTypes.ts(1,9): error TS1122: A tuple type element list cannot be empty. -tests/cases/compiler/tupleTypes.ts(14,1): error TS2322: Type '{}[]' is not assignable to type '[number, string]': - Property '0' is missing in type '{}[]'. +tests/cases/compiler/tupleTypes.ts(14,1): error TS2322: Type 'Array' is not assignable to type '[number, string]': + Property '0' is missing in type 'Array'. tests/cases/compiler/tupleTypes.ts(15,1): error TS2322: Type '[number]' is not assignable to type '[number, string]': Property '1' is missing in type '[number]'. tests/cases/compiler/tupleTypes.ts(17,1): error TS2322: Type '[string, number]' is not assignable to type '[number, string]': Types of property '0' are incompatible: Type 'string' is not assignable to type 'number'. -tests/cases/compiler/tupleTypes.ts(41,1): error TS2323: Type '{}[]' is not assignable to type '[number, string]'. +tests/cases/compiler/tupleTypes.ts(41,1): error TS2323: Type 'Array' is not assignable to type '[number, string]'. tests/cases/compiler/tupleTypes.ts(47,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]': Types of property 'pop' are incompatible: - Type '() => {}' is not assignable to type '() => number': - Type '{}' is not assignable to type 'number'. + Type '() => string | number' is not assignable to type '() => number': + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. tests/cases/compiler/tupleTypes.ts(49,1): error TS2322: Type '[number, {}]' is not assignable to type 'number[]': Types of property 'pop' are incompatible: Type '() => {}' is not assignable to type '() => number': @@ -36,13 +37,13 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n var t0: number; var t1 = t[1]; // string var t1: string; - var t2 = t[2]; // {} - var t2: {}; + var t2 = t[2]; // number|string + var t2: number|string; t = []; // Error ~ -!!! error TS2322: Type '{}[]' is not assignable to type '[number, string]': -!!! error TS2322: Property '0' is missing in type '{}[]'. +!!! error TS2322: Type 'Array' is not assignable to type '[number, string]': +!!! error TS2322: Property '0' is missing in type 'Array'. t = [1]; // Error ~ !!! error TS2322: Type '[number]' is not assignable to type '[number, string]': @@ -70,15 +71,15 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n var tt0: number; var tt1 = tt[1]; var tt1: string; - var tt2 = tt[2]; - var tt2: {}; + var tt2 = tt[2]; + var tt2: number | string; tt = tuple2(1, undefined); tt = [1, undefined]; tt = [undefined, undefined]; tt = []; // Error ~~ -!!! error TS2323: Type '{}[]' is not assignable to type '[number, string]'. +!!! error TS2323: Type 'Array' is not assignable to type '[number, string]'. var a: number[]; var a1: [number, string]; @@ -88,8 +89,9 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n ~ !!! error TS2322: Type '[number, string]' is not assignable to type 'number[]': !!! error TS2322: Types of property 'pop' are incompatible: -!!! error TS2322: Type '() => {}' is not assignable to type '() => number': -!!! error TS2322: Type '{}' is not assignable to type 'number'. +!!! error TS2322: Type '() => string | number' is not assignable to type '() => number': +!!! error TS2322: Type 'string | number' is not assignable to type 'number': +!!! error TS2322: Type 'string' is not assignable to type 'number'. a = a2; a = a3; // Error ~ diff --git a/tests/baselines/reference/typeArgInference2.errors.txt b/tests/baselines/reference/typeArgInference2.errors.txt new file mode 100644 index 00000000000..cf188972b7d --- /dev/null +++ b/tests/baselines/reference/typeArgInference2.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/typeArgInference2.ts(12,10): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/compiler/typeArgInference2.ts (1 errors) ==== + interface Item { + name: string; + } + + declare function foo(x?: T, y?: T): T; + + var z1 = foo(null); // any + var z2 = foo(); // Item + var z3 = foo({ name: null }); // { name: any } + var z4 = foo({ name: "abc" }); // { name: string } + var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } + var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgInference2.js b/tests/baselines/reference/typeArgInference2.js index ef76c9b33e7..193345cdeb3 100644 --- a/tests/baselines/reference/typeArgInference2.js +++ b/tests/baselines/reference/typeArgInference2.js @@ -10,7 +10,7 @@ var z2 = foo(); // Item var z3 = foo({ name: null }); // { name: any } var z4 = foo({ name: "abc" }); // { name: string } var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } -var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // Item +var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // error //// [typeArgInference2.js] var z1 = foo(null); // any @@ -18,4 +18,4 @@ var z2 = foo(); // Item var z3 = foo({ name: null }); // { name: any } var z4 = foo({ name: "abc" }); // { name: string } var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } -var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // Item +var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // error diff --git a/tests/baselines/reference/typeArgInference2.types b/tests/baselines/reference/typeArgInference2.types deleted file mode 100644 index 1b94a0638bd..00000000000 --- a/tests/baselines/reference/typeArgInference2.types +++ /dev/null @@ -1,61 +0,0 @@ -=== tests/cases/compiler/typeArgInference2.ts === -interface Item { ->Item : Item - - name: string; ->name : string -} - -declare function foo(x?: T, y?: T): T; ->foo : (x?: T, y?: T) => T ->T : T ->Item : Item ->x : T ->T : T ->y : T ->T : T ->T : T - -var z1 = foo(null); // any ->z1 : any ->foo(null) : any ->foo : (x?: T, y?: T) => T - -var z2 = foo(); // Item ->z2 : Item ->foo() : Item ->foo : (x?: T, y?: T) => T - -var z3 = foo({ name: null }); // { name: any } ->z3 : { name: any; } ->foo({ name: null }) : { name: any; } ->foo : (x?: T, y?: T) => T ->{ name: null } : { name: null; } ->name : null - -var z4 = foo({ name: "abc" }); // { name: string } ->z4 : { name: string; } ->foo({ name: "abc" }) : { name: string; } ->foo : (x?: T, y?: T) => T ->{ name: "abc" } : { name: string; } ->name : string - -var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } ->z5 : { name: string; a: number; } ->foo({ name: "abc", a: 5 }) : { name: string; a: number; } ->foo : (x?: T, y?: T) => T ->{ name: "abc", a: 5 } : { name: string; a: number; } ->name : string ->a : number - -var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // Item ->z6 : Item ->foo({ name: "abc", a: 5 }, { name: "def", b: 5 }) : Item ->foo : (x?: T, y?: T) => T ->{ name: "abc", a: 5 } : { name: string; a: number; } ->name : string ->a : number ->{ name: "def", b: 5 } : { name: string; b: number; } ->name : string ->b : number - diff --git a/tests/baselines/reference/typeArgInference2WithError.errors.txt b/tests/baselines/reference/typeArgInference2WithError.errors.txt index 26259abf37b..83fa81b5524 100644 --- a/tests/baselines/reference/typeArgInference2WithError.errors.txt +++ b/tests/baselines/reference/typeArgInference2WithError.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/typeArgInference2WithError.ts(7,14): error TS2345: Argument of type 'string' is not assignable to parameter of type 'Item'. +tests/cases/compiler/typeArgInference2WithError.ts(7,10): error TS2346: Supplied parameters do not match any signature of call target. ==== tests/cases/compiler/typeArgInference2WithError.ts (1 errors) ==== @@ -9,5 +9,5 @@ tests/cases/compiler/typeArgInference2WithError.ts(7,14): error TS2345: Argument declare function foo(x?: T, y?: T): T; var z7 = foo("abc", 5); // Error - ~~~~~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'Item'. \ No newline at end of file + ~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentInference.errors.txt b/tests/baselines/reference/typeArgumentInference.errors.txt new file mode 100644 index 00000000000..dbff8b83854 --- /dev/null +++ b/tests/baselines/reference/typeArgumentInference.errors.txt @@ -0,0 +1,109 @@ +tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts(68,11): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts(82,11): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts (2 errors) ==== + // Generic call with no parameters + function noParams() { } + noParams(); + noParams(); + noParams<{}>(); + + // Generic call with parameters but none use type parameter type + function noGenericParams(n: string) { } + noGenericParams(''); + noGenericParams(''); + noGenericParams<{}>(''); + + // Generic call with multiple type parameters and only one used in parameter type annotation + function someGenerics1(n: T, m: number) { } + someGenerics1(3, 4); + someGenerics1(3, 4); + + // Generic call with argument of function type whose parameter is of type parameter type + function someGenerics2a(n: (x: T) => void) { } + someGenerics2a((n: string) => n); + someGenerics2a((n: string) => n); + someGenerics2a((n) => n.substr(0)); + + function someGenerics2b(n: (x: T, y: U) => void) { } + someGenerics2b((n: string, x: number) => n); + someGenerics2b((n: string, t: number) => n); + someGenerics2b((n, t) => n.substr(t * t)); + + // Generic call with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter + function someGenerics3(producer: () => T) { } + someGenerics3(() => ''); + someGenerics3(() => undefined); + someGenerics3(() => 3); + + // 2 parameter generic call with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type + function someGenerics4(n: T, f: (x: U) => void) { } + someGenerics4(4, () => null); + someGenerics4('', () => 3); + someGenerics4(null, null); + + // 2 parameter generic call with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type + function someGenerics5(n: T, f: (x: U) => void) { } + someGenerics5(4, () => null); + someGenerics5('', () => 3); + someGenerics5(null, null); + + // Generic call with multiple arguments of function types that each have parameters of the same generic type + function someGenerics6(a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } + someGenerics6(n => n, n => n, n => n); + someGenerics6(n => n, n => n, n => n); + someGenerics6((n: number) => n, (n: number) => n, (n: number) => n); + + // Generic call with multiple arguments of function types that each have parameters of different generic type + function someGenerics7(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } + someGenerics7(n => n, n => n, n => n); + someGenerics7(n => n, n => n, n => n); + someGenerics7((n: number) => n, (n: string) => n, (n: number) => n); + + // Generic call with argument of generic function type + function someGenerics8(n: T): T { return n; } + var x = someGenerics8(someGenerics7); + x(null, null, null); + + // Generic call with multiple parameters of generic type passed arguments with no best common type + function someGenerics9(a: T, b: T, c: T): T { + return null; + } + var a9a = someGenerics9('', 0, []); + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var a9a: {}; + var a9b = someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null); + var a9b: { a?: number; b?: string; }; + + // Generic call with multiple parameters of generic type passed arguments with multiple best common types + interface A91 { + x: number; + y?: string; + } + interface A92 { + x: number; + z?: Date; + } + var a9e = someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var a9e: {}; + var a9f = someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }); + var a9f: A92; + + // Generic call with multiple parameters of generic type passed arguments with a single best common type + var a9d = someGenerics9({ x: 3 }, { x: 6 }, { x: 6 }); + var a9d: { x: number; }; + + // Generic call with multiple parameters of generic type where one argument is of type 'any' + var anyVar: any; + var a = someGenerics9(7, anyVar, 4); + var a: any; + + // Generic call with multiple parameters of generic type where one argument is [] and the other is not 'any' + var arr = someGenerics9([], null, undefined); + var arr: any[]; + + \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentInference.types b/tests/baselines/reference/typeArgumentInference.types deleted file mode 100644 index 40136bd10c3..00000000000 --- a/tests/baselines/reference/typeArgumentInference.types +++ /dev/null @@ -1,468 +0,0 @@ -=== tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts === -// Generic call with no parameters -function noParams() { } ->noParams : () => void ->T : T - -noParams(); ->noParams() : void ->noParams : () => void - -noParams(); ->noParams() : void ->noParams : () => void - -noParams<{}>(); ->noParams<{}>() : void ->noParams : () => void - -// Generic call with parameters but none use type parameter type -function noGenericParams(n: string) { } ->noGenericParams : (n: string) => void ->T : T ->n : string - -noGenericParams(''); ->noGenericParams('') : void ->noGenericParams : (n: string) => void - -noGenericParams(''); ->noGenericParams('') : void ->noGenericParams : (n: string) => void - -noGenericParams<{}>(''); ->noGenericParams<{}>('') : void ->noGenericParams : (n: string) => void - -// Generic call with multiple type parameters and only one used in parameter type annotation -function someGenerics1(n: T, m: number) { } ->someGenerics1 : (n: T, m: number) => void ->T : T ->U : U ->n : T ->T : T ->m : number - -someGenerics1(3, 4); ->someGenerics1(3, 4) : void ->someGenerics1 : (n: T, m: number) => void - -someGenerics1(3, 4); ->someGenerics1(3, 4) : void ->someGenerics1 : (n: T, m: number) => void - -// Generic call with argument of function type whose parameter is of type parameter type -function someGenerics2a(n: (x: T) => void) { } ->someGenerics2a : (n: (x: T) => void) => void ->T : T ->n : (x: T) => void ->x : T ->T : T - -someGenerics2a((n: string) => n); ->someGenerics2a((n: string) => n) : void ->someGenerics2a : (n: (x: T) => void) => void ->(n: string) => n : (n: string) => string ->n : string ->n : string - -someGenerics2a((n: string) => n); ->someGenerics2a((n: string) => n) : void ->someGenerics2a : (n: (x: T) => void) => void ->(n: string) => n : (n: string) => string ->n : string ->n : string - -someGenerics2a((n) => n.substr(0)); ->someGenerics2a((n) => n.substr(0)) : void ->someGenerics2a : (n: (x: T) => void) => void ->(n) => n.substr(0) : (n: string) => string ->n : string ->n.substr(0) : string ->n.substr : (from: number, length?: number) => string ->n : string ->substr : (from: number, length?: number) => string - -function someGenerics2b(n: (x: T, y: U) => void) { } ->someGenerics2b : (n: (x: T, y: U) => void) => void ->T : T ->U : U ->n : (x: T, y: U) => void ->x : T ->T : T ->y : U ->U : U - -someGenerics2b((n: string, x: number) => n); ->someGenerics2b((n: string, x: number) => n) : void ->someGenerics2b : (n: (x: T, y: U) => void) => void ->(n: string, x: number) => n : (n: string, x: number) => string ->n : string ->x : number ->n : string - -someGenerics2b((n: string, t: number) => n); ->someGenerics2b((n: string, t: number) => n) : void ->someGenerics2b : (n: (x: T, y: U) => void) => void ->(n: string, t: number) => n : (n: string, t: number) => string ->n : string ->t : number ->n : string - -someGenerics2b((n, t) => n.substr(t * t)); ->someGenerics2b((n, t) => n.substr(t * t)) : void ->someGenerics2b : (n: (x: T, y: U) => void) => void ->(n, t) => n.substr(t * t) : (n: string, t: number) => string ->n : string ->t : number ->n.substr(t * t) : string ->n.substr : (from: number, length?: number) => string ->n : string ->substr : (from: number, length?: number) => string ->t * t : number ->t : number ->t : number - -// Generic call with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter -function someGenerics3(producer: () => T) { } ->someGenerics3 : (producer: () => T) => void ->T : T ->producer : () => T ->T : T - -someGenerics3(() => ''); ->someGenerics3(() => '') : void ->someGenerics3 : (producer: () => T) => void ->() => '' : () => string - -someGenerics3(() => undefined); ->someGenerics3(() => undefined) : void ->someGenerics3 : (producer: () => T) => void ->Date : Date ->() => undefined : () => any ->undefined : undefined - -someGenerics3(() => 3); ->someGenerics3(() => 3) : void ->someGenerics3 : (producer: () => T) => void ->() => 3 : () => number - -// 2 parameter generic call with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type -function someGenerics4(n: T, f: (x: U) => void) { } ->someGenerics4 : (n: T, f: (x: U) => void) => void ->T : T ->U : U ->n : T ->T : T ->f : (x: U) => void ->x : U ->U : U - -someGenerics4(4, () => null); ->someGenerics4(4, () => null) : void ->someGenerics4 : (n: T, f: (x: U) => void) => void ->() => null : () => any - -someGenerics4('', () => 3); ->someGenerics4('', () => 3) : void ->someGenerics4 : (n: T, f: (x: U) => void) => void ->() => 3 : () => number - -someGenerics4(null, null); ->someGenerics4(null, null) : void ->someGenerics4 : (n: T, f: (x: U) => void) => void - -// 2 parameter generic call with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type -function someGenerics5(n: T, f: (x: U) => void) { } ->someGenerics5 : (n: T, f: (x: U) => void) => void ->U : U ->T : T ->n : T ->T : T ->f : (x: U) => void ->x : U ->U : U - -someGenerics5(4, () => null); ->someGenerics5(4, () => null) : void ->someGenerics5 : (n: T, f: (x: U) => void) => void ->() => null : () => any - -someGenerics5('', () => 3); ->someGenerics5('', () => 3) : void ->someGenerics5 : (n: T, f: (x: U) => void) => void ->() => 3 : () => number - -someGenerics5(null, null); ->someGenerics5(null, null) : void ->someGenerics5 : (n: T, f: (x: U) => void) => void - -// Generic call with multiple arguments of function types that each have parameters of the same generic type -function someGenerics6(a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } ->someGenerics6 : (a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) => void ->A : A ->a : (a: A) => A ->a : A ->A : A ->A : A ->b : (b: A) => A ->b : A ->A : A ->A : A ->c : (c: A) => A ->c : A ->A : A ->A : A - -someGenerics6(n => n, n => n, n => n); ->someGenerics6(n => n, n => n, n => n) : void ->someGenerics6 : (a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) => void ->n => n : (n: {}) => {} ->n : {} ->n : {} ->n => n : (n: {}) => {} ->n : {} ->n : {} ->n => n : (n: {}) => {} ->n : {} ->n : {} - -someGenerics6(n => n, n => n, n => n); ->someGenerics6(n => n, n => n, n => n) : void ->someGenerics6 : (a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) => void ->n => n : (n: number) => number ->n : number ->n : number ->n => n : (n: number) => number ->n : number ->n : number ->n => n : (n: number) => number ->n : number ->n : number - -someGenerics6((n: number) => n, (n: number) => n, (n: number) => n); ->someGenerics6((n: number) => n, (n: number) => n, (n: number) => n) : void ->someGenerics6 : (a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) => void ->(n: number) => n : (n: number) => number ->n : number ->n : number ->(n: number) => n : (n: number) => number ->n : number ->n : number ->(n: number) => n : (n: number) => number ->n : number ->n : number - -// Generic call with multiple arguments of function types that each have parameters of different generic type -function someGenerics7(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } ->someGenerics7 : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->A : A ->B : B ->C : C ->a : (a: A) => A ->a : A ->A : A ->A : A ->b : (b: B) => B ->b : B ->B : B ->B : B ->c : (c: C) => C ->c : C ->C : C ->C : C - -someGenerics7(n => n, n => n, n => n); ->someGenerics7(n => n, n => n, n => n) : void ->someGenerics7 : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->n => n : (n: {}) => {} ->n : {} ->n : {} ->n => n : (n: {}) => {} ->n : {} ->n : {} ->n => n : (n: {}) => {} ->n : {} ->n : {} - -someGenerics7(n => n, n => n, n => n); ->someGenerics7(n => n, n => n, n => n) : void ->someGenerics7 : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->n => n : (n: number) => number ->n : number ->n : number ->n => n : (n: string) => string ->n : string ->n : string ->n => n : (n: number) => number ->n : number ->n : number - -someGenerics7((n: number) => n, (n: string) => n, (n: number) => n); ->someGenerics7((n: number) => n, (n: string) => n, (n: number) => n) : void ->someGenerics7 : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->(n: number) => n : (n: number) => number ->n : number ->n : number ->(n: string) => n : (n: string) => string ->n : string ->n : string ->(n: number) => n : (n: number) => number ->n : number ->n : number - -// Generic call with argument of generic function type -function someGenerics8(n: T): T { return n; } ->someGenerics8 : (n: T) => T ->T : T ->n : T ->T : T ->T : T ->n : T - -var x = someGenerics8(someGenerics7); ->x : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->someGenerics8(someGenerics7) : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->someGenerics8 : (n: T) => T ->someGenerics7 : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void - -x(null, null, null); ->x(null, null, null) : void ->x : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void - -// Generic call with multiple parameters of generic type passed arguments with no best common type -function someGenerics9(a: T, b: T, c: T): T { ->someGenerics9 : (a: T, b: T, c: T) => T ->T : T ->a : T ->T : T ->b : T ->T : T ->c : T ->T : T ->T : T - - return null; -} -var a9a = someGenerics9('', 0, []); ->a9a : {} ->someGenerics9('', 0, []) : {} ->someGenerics9 : (a: T, b: T, c: T) => T ->[] : undefined[] - -var a9a: {}; ->a9a : {} - -var a9b = someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null); ->a9b : { a?: number; b?: string; } ->someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null) : { a?: number; b?: string; } ->someGenerics9 : (a: T, b: T, c: T) => T ->a : number ->b : string ->{ a: 0 } : { a: number; } ->a : number ->{ b: '' } : { b: string; } ->b : string - -var a9b: { a?: number; b?: string; }; ->a9b : { a?: number; b?: string; } ->a : number ->b : string - -// Generic call with multiple parameters of generic type passed arguments with multiple best common types -interface A91 { ->A91 : A91 - - x: number; ->x : number - - y?: string; ->y : string -} -interface A92 { ->A92 : A92 - - x: number; ->x : number - - z?: Date; ->z : Date ->Date : Date -} -var a9e = someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }); ->a9e : {} ->someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }) : {} ->someGenerics9 : (a: T, b: T, c: T) => T ->undefined : undefined ->{ x: 6, z: new Date() } : { x: number; z: Date; } ->x : number ->z : Date ->new Date() : Date ->Date : { (): string; new (): Date; new (value: number): Date; new (value: string): Date; new (year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date; prototype: Date; parse(s: string): number; UTC(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number; now(): number; } ->{ x: 6, y: '' } : { x: number; y: string; } ->x : number ->y : string - -var a9e: {}; ->a9e : {} - -var a9f = someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }); ->a9f : A92 ->someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }) : A92 ->someGenerics9 : (a: T, b: T, c: T) => T ->A92 : A92 ->undefined : undefined ->{ x: 6, z: new Date() } : { x: number; z: Date; } ->x : number ->z : Date ->new Date() : Date ->Date : { (): string; new (): Date; new (value: number): Date; new (value: string): Date; new (year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date; prototype: Date; parse(s: string): number; UTC(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number; now(): number; } ->{ x: 6, y: '' } : { x: number; y: string; } ->x : number ->y : string - -var a9f: A92; ->a9f : A92 ->A92 : A92 - -// Generic call with multiple parameters of generic type passed arguments with a single best common type -var a9d = someGenerics9({ x: 3 }, { x: 6 }, { x: 6 }); ->a9d : { x: number; } ->someGenerics9({ x: 3 }, { x: 6 }, { x: 6 }) : { x: number; } ->someGenerics9 : (a: T, b: T, c: T) => T ->{ x: 3 } : { x: number; } ->x : number ->{ x: 6 } : { x: number; } ->x : number ->{ x: 6 } : { x: number; } ->x : number - -var a9d: { x: number; }; ->a9d : { x: number; } ->x : number - -// Generic call with multiple parameters of generic type where one argument is of type 'any' -var anyVar: any; ->anyVar : any - -var a = someGenerics9(7, anyVar, 4); ->a : any ->someGenerics9(7, anyVar, 4) : any ->someGenerics9 : (a: T, b: T, c: T) => T ->anyVar : any - -var a: any; ->a : any - -// Generic call with multiple parameters of generic type where one argument is [] and the other is not 'any' -var arr = someGenerics9([], null, undefined); ->arr : any[] ->someGenerics9([], null, undefined) : any[] ->someGenerics9 : (a: T, b: T, c: T) => T ->[] : any[] ->undefined : undefined - -var arr: any[]; ->arr : any[] - - diff --git a/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt b/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt index a9de02d4226..4f11cb6135e 100644 --- a/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt @@ -3,12 +3,14 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstruct tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(61,39): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(71,39): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(81,45): error TS2345: Argument of type '(n: string) => string' is not assignable to parameter of type '(b: number) => number'. +tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(106,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(118,9): error TS2304: Cannot find name 'Window'. +tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(120,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(120,51): error TS2304: Cannot find name 'window'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(122,56): error TS2304: Cannot find name 'window'. -==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts (8 errors) ==== +==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts (10 errors) ==== // Generic call with no parameters interface NoParams { new (); @@ -125,6 +127,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstruct } var someGenerics9: someGenerics9; var a9a = new someGenerics9('', 0, []); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var a9a: {}; var a9b = new someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null); var a9b: { a?: number; b?: string; }; @@ -141,6 +145,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstruct !!! error TS2304: Cannot find name 'Window'. } var a9e = new someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' }); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. ~~~~~~ !!! error TS2304: Cannot find name 'window'. var a9e: {}; diff --git a/tests/baselines/reference/typeArgumentInferenceTransitiveConstraints.errors.txt b/tests/baselines/reference/typeArgumentInferenceTransitiveConstraints.errors.txt index e6e59308dd4..08cb5348c27 100644 --- a/tests/baselines/reference/typeArgumentInferenceTransitiveConstraints.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceTransitiveConstraints.errors.txt @@ -1,9 +1,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiveConstraints.ts(2,29): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiveConstraints.ts(2,42): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiveConstraints.ts(7,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'd' must be of type '{}[]', but here has type 'Date[]'. -==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiveConstraints.ts (3 errors) ==== +==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiveConstraints.ts (2 errors) ==== function fn(a: A, b: B, c: C) { ~~~~~~~~~~~ @@ -15,6 +14,4 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiv var d = fn(new Date(), new Date(), new Date()); var d: Date[]; // Should be OK (d should be Date[]) - ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'd' must be of type '{}[]', but here has type 'Date[]'. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.errors.txt b/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.errors.txt new file mode 100644 index 00000000000..c0ee4329c8d --- /dev/null +++ b/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/typeArgumentInferenceWithConstraintAsCommonRoot.ts(7,1): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/compiler/typeArgumentInferenceWithConstraintAsCommonRoot.ts (1 errors) ==== + interface Animal { x } + interface Giraffe extends Animal { y } + interface Elephant extends Animal { z } + function f(x: T, y: T): T { return undefined; } + var g: Giraffe; + var e: Elephant; + f(g, e); // valid because both Giraffe and Elephant satisfy the constraint. T is Animal + ~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.types b/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.types deleted file mode 100644 index 35328f72803..00000000000 --- a/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.types +++ /dev/null @@ -1,40 +0,0 @@ -=== tests/cases/compiler/typeArgumentInferenceWithConstraintAsCommonRoot.ts === -interface Animal { x } ->Animal : Animal ->x : any - -interface Giraffe extends Animal { y } ->Giraffe : Giraffe ->Animal : Animal ->y : any - -interface Elephant extends Animal { z } ->Elephant : Elephant ->Animal : Animal ->z : any - -function f(x: T, y: T): T { return undefined; } ->f : (x: T, y: T) => T ->T : T ->Animal : Animal ->x : T ->T : T ->y : T ->T : T ->T : T ->undefined : undefined - -var g: Giraffe; ->g : Giraffe ->Giraffe : Giraffe - -var e: Elephant; ->e : Elephant ->Elephant : Elephant - -f(g, e); // valid because both Giraffe and Elephant satisfy the constraint. T is Animal ->f(g, e) : Animal ->f : (x: T, y: T) => T ->g : Giraffe ->e : Elephant - diff --git a/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt b/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt index 8cf2a2d3503..c0dbf74f66e 100644 --- a/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt @@ -8,12 +8,14 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(49,15): error TS2344: Type 'string' does not satisfy the constraint 'number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(55,41): error TS2345: Argument of type '(n: string) => string' is not assignable to parameter of type '(b: number) => number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(66,31): error TS2345: Argument of type '(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void' is not assignable to parameter of type 'string'. +tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(73,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(85,9): error TS2304: Cannot find name 'Window'. +tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(87,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(87,47): error TS2304: Cannot find name 'window'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(89,52): error TS2304: Cannot find name 'window'. -==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts (13 errors) ==== +==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts (15 errors) ==== // Generic call with no parameters function noParams() { } noParams(); @@ -107,6 +109,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst return null; } var a9a = someGenerics9('', 0, []); + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var a9a: {}; var a9b = someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null); var a9b: { a?: number; b?: string; }; @@ -123,6 +127,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst !!! error TS2304: Cannot find name 'Window'. } var a9e = someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' }); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. ~~~~~~ !!! error TS2304: Cannot find name 'window'. var a9e: {}; diff --git a/tests/baselines/reference/typeInferenceConflictingCandidates.errors.txt b/tests/baselines/reference/typeInferenceConflictingCandidates.errors.txt new file mode 100644 index 00000000000..5f9f980e735 --- /dev/null +++ b/tests/baselines/reference/typeInferenceConflictingCandidates.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/typeInferenceConflictingCandidates.ts(3,1): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/compiler/typeInferenceConflictingCandidates.ts (1 errors) ==== + declare function g(a: T, b: T, c: (t: T) => T): T; + + g("", 3, a => a); + ~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/typeInferenceConflictingCandidates.types b/tests/baselines/reference/typeInferenceConflictingCandidates.types deleted file mode 100644 index 7a77daf4092..00000000000 --- a/tests/baselines/reference/typeInferenceConflictingCandidates.types +++ /dev/null @@ -1,21 +0,0 @@ -=== tests/cases/compiler/typeInferenceConflictingCandidates.ts === -declare function g(a: T, b: T, c: (t: T) => T): T; ->g : (a: T, b: T, c: (t: T) => T) => T ->T : T ->a : T ->T : T ->b : T ->T : T ->c : (t: T) => T ->t : T ->T : T ->T : T ->T : T - -g("", 3, a => a); ->g("", 3, a => a) : {} ->g : (a: T, b: T, c: (t: T) => T) => T ->a => a : (a: {}) => {} ->a : {} ->a : {} - diff --git a/tests/baselines/reference/typeParameterAsElementType.types b/tests/baselines/reference/typeParameterAsElementType.types index 0dbbbf5ac7a..828c7034a58 100644 --- a/tests/baselines/reference/typeParameterAsElementType.types +++ b/tests/baselines/reference/typeParameterAsElementType.types @@ -8,7 +8,7 @@ function fee() { >T : T var arr = [t, ""]; ->arr : {}[] ->[t, ""] : {}[] +>arr : Array +>[t, ""] : Array >t : T } diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index 115bc09195d..a23eff1f8ea 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -176,7 +176,7 @@ _.all([true, 1, null, 'yes'], _.identity); >_.all : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } >_ : Underscore.Static >all : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } ->[true, 1, null, 'yes'] : {}[] +>[true, 1, null, 'yes'] : Array >_.identity : (value: T) => T >_ : Underscore.Static >identity : (value: T) => T @@ -186,7 +186,7 @@ _.any([null, 0, 'yes', false]); >_.any : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } >_ : Underscore.Static >any : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } ->[null, 0, 'yes', false] : {}[] +>[null, 0, 'yes', false] : Array _.contains([1, 2, 3], 3); >_.contains([1, 2, 3], 3) : boolean @@ -364,11 +364,11 @@ _.rest([5, 4, 3, 2, 1]); >[5, 4, 3, 2, 1] : number[] _.compact([0, 1, false, 2, '', 3]); ->_.compact([0, 1, false, 2, '', 3]) : {}[] +>_.compact([0, 1, false, 2, '', 3]) : Array >_.compact : (list: T[]) => T[] >_ : Underscore.Static >compact : (list: T[]) => T[] ->[0, 1, false, 2, '', 3] : {}[] +>[0, 1, false, 2, '', 3] : Array _.flatten([1, 2, 3, 4]); >_.flatten([1, 2, 3, 4]) : {}[] @@ -393,7 +393,7 @@ _.flatten([1, [2], [3, [[4]]]]); >flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } >[1, [2], [3, [[4]]]] : any[] >[2] : number[] ->[3, [[4]]] : {}[] +>[3, [[4]]] : Array >[[4]] : number[][] >[4] : number[] @@ -404,7 +404,7 @@ _.flatten([1, [2], [3, [[4]]]], true); >flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } >[1, [2], [3, [[4]]]] : any[] >[2] : number[] ->[3, [[4]]] : {}[] +>[3, [[4]]] : Array >[[4]] : number[][] >[4] : number[] diff --git a/tests/cases/compiler/arrayBestCommonTypes.ts b/tests/cases/compiler/arrayBestCommonTypes.ts index ee09c4d07f6..c7466b5181e 100644 --- a/tests/cases/compiler/arrayBestCommonTypes.ts +++ b/tests/cases/compiler/arrayBestCommonTypes.ts @@ -1,52 +1,106 @@ -interface iface { } -class base implements iface { } -class base2 implements iface { } -class derived extends base { } +module EmptyTypes { + interface iface { } + class base implements iface { } + class base2 implements iface { } + class derived extends base { } -class f { - public voidIfAny(x: boolean, y?: boolean): number; - public voidIfAny(x: string, y?: boolean): number; - public voidIfAny(x: number, y?: boolean): number; - public voidIfAny(x: any, y =false): any { return null; } - - public x() { - (this.voidIfAny([4, 2][0])); - (this.voidIfAny([4, 2, undefined][0])); - (this.voidIfAny([undefined, 2, 4][0])); - (this.voidIfAny([null, 2, 4][0])); - (this.voidIfAny([2, 4, null][0])); - (this.voidIfAny([undefined, 4, null][0])); + class f { + public voidIfAny(x: boolean, y?: boolean): number; + public voidIfAny(x: string, y?: boolean): number; + public voidIfAny(x: number, y?: boolean): number; + public voidIfAny(x: any, y = false): any { return null; } - (this.voidIfAny(['', "q"][0])); - (this.voidIfAny(['', "q", undefined][0])); - (this.voidIfAny([undefined, "q", ''][0])); - (this.voidIfAny([null, "q", ''][0])); - (this.voidIfAny(["q", '', null][0])); - (this.voidIfAny([undefined, '', null][0])); + public x() { + (this.voidIfAny([4, 2][0])); + (this.voidIfAny([4, 2, undefined][0])); + (this.voidIfAny([undefined, 2, 4][0])); + (this.voidIfAny([null, 2, 4][0])); + (this.voidIfAny([2, 4, null][0])); + (this.voidIfAny([undefined, 4, null][0])); - (this.voidIfAny([[3,4],[null]][0][0])); - - - var t1: { x: number; y: base; }[] = [ { x: 7, y: new derived() }, { x: 5, y: new base() } ]; - var t2: { x: boolean; y: base; }[] = [ { x: true, y: new derived() }, { x: false, y: new base() } ]; - var t3: { x: string; y: base; }[] = [ { x: undefined, y: new base() }, { x: '', y: new derived() } ]; + (this.voidIfAny(['', "q"][0])); + (this.voidIfAny(['', "q", undefined][0])); + (this.voidIfAny([undefined, "q", ''][0])); + (this.voidIfAny([null, "q", ''][0])); + (this.voidIfAny(["q", '', null][0])); + (this.voidIfAny([undefined, '', null][0])); - var anyObj: any = null; - // Order matters here so test all the variants - var a1 = [ {x: 0, y: 'a'}, {x: 'a', y: 'a'}, {x: anyObj, y: 'a'} ]; - var a2 = [ {x: anyObj, y: 'a'}, {x: 0, y: 'a'}, {x: 'a', y: 'a'} ]; - var a3 = [ {x: 0, y: 'a'}, {x: anyObj, y: 'a'}, {x: 'a', y: 'a'} ]; - - var ifaceObj: iface = null; - var baseObj = new base(); - var base2Obj = new base2(); + (this.voidIfAny([[3, 4], [null]][0][0])); - var b1 = [ baseObj, base2Obj, ifaceObj ]; - var b2 = [ base2Obj, baseObj, ifaceObj ]; - var b3 = [ baseObj, ifaceObj, base2Obj ]; - var b4 = [ ifaceObj, baseObj, base2Obj ]; + + var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; + var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }]; + var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; + + var anyObj: any = null; + // Order matters here so test all the variants + var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; + var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; + var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; + + var ifaceObj: iface = null; + var baseObj = new base(); + var base2Obj = new base2(); + + var b1 = [baseObj, base2Obj, ifaceObj]; + var b2 = [base2Obj, baseObj, ifaceObj]; + var b3 = [baseObj, ifaceObj, base2Obj]; + var b4 = [ifaceObj, baseObj, base2Obj]; + } } } +module NonEmptyTypes { + interface iface { x: string; } + class base implements iface { x: string; y: string; } + class base2 implements iface { x: string; z: string; } + class derived extends base { a: string; } + + + class f { + public voidIfAny(x: boolean, y?: boolean): number; + public voidIfAny(x: string, y?: boolean): number; + public voidIfAny(x: number, y?: boolean): number; + public voidIfAny(x: any, y = false): any { return null; } + + public x() { + (this.voidIfAny([4, 2][0])); + (this.voidIfAny([4, 2, undefined][0])); + (this.voidIfAny([undefined, 2, 4][0])); + (this.voidIfAny([null, 2, 4][0])); + (this.voidIfAny([2, 4, null][0])); + (this.voidIfAny([undefined, 4, null][0])); + + (this.voidIfAny(['', "q"][0])); + (this.voidIfAny(['', "q", undefined][0])); + (this.voidIfAny([undefined, "q", ''][0])); + (this.voidIfAny([null, "q", ''][0])); + (this.voidIfAny(["q", '', null][0])); + (this.voidIfAny([undefined, '', null][0])); + + (this.voidIfAny([[3, 4], [null]][0][0])); + + + var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; + var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }]; + var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; + + var anyObj: any = null; + // Order matters here so test all the variants + var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; + var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; + var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; + + var ifaceObj: iface = null; + var baseObj = new base(); + var base2Obj = new base2(); + + var b1 = [baseObj, base2Obj, ifaceObj]; + var b2 = [base2Obj, baseObj, ifaceObj]; + var b3 = [baseObj, ifaceObj, base2Obj]; + var b4 = [ifaceObj, baseObj, base2Obj]; + } + } +} diff --git a/tests/cases/compiler/arrayLiteralContextualType.ts b/tests/cases/compiler/arrayLiteralContextualType.ts index 1518d2e4ac0..be05929e8e7 100644 --- a/tests/cases/compiler/arrayLiteralContextualType.ts +++ b/tests/cases/compiler/arrayLiteralContextualType.ts @@ -25,5 +25,5 @@ bar([ ]); // Legal because of the contextual type IAnimal provided by the parameter var arr = [new Giraffe(), new Elephant()]; -foo(arr); // Error because of no contextual type -bar(arr); // Error because of no contextual type \ No newline at end of file +foo(arr); // ok because arr is Array not {}[] +bar(arr); // ok because arr is Array not {}[] \ No newline at end of file diff --git a/tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts b/tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts index bd1f22f44dc..1ea001057a9 100644 --- a/tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts +++ b/tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts @@ -1,3 +1,3 @@ var f10: (x: T, b: () => (a: T) => void, y: T) => T; -f10('', () => a => a.foo, ''); // a is string, fixed by first parameter -var r9 = f10('', () => (a => a.foo), 1); // now a should be any \ No newline at end of file +f10('', () => a => a.foo, ''); // a is string +var r9 = f10('', () => (a => a.foo), 1); // error \ No newline at end of file diff --git a/tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts b/tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts index b9fecdc6ffc..254197bf309 100644 --- a/tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts +++ b/tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts @@ -1,18 +1,14 @@ - var obj1: {}; - obj1.length; - - var obj2: Object; - obj2.length; - - function concat(x: T, y: T): T { return null; } +var result = concat(1, ""); // error +var elementCount = result.length; -var result = concat(1, ""); +function concat2(x: T, y: U) { return null; } +var result2 = concat2(1, ""); // result2 will be number|string +var elementCount2 = result.length; -var elementCount = result.length; // would like to get an error by now diff --git a/tests/cases/compiler/nonContextuallyTypedLogicalOr.ts b/tests/cases/compiler/nonContextuallyTypedLogicalOr.ts index f77ad5105ab..cadd60ea398 100644 --- a/tests/cases/compiler/nonContextuallyTypedLogicalOr.ts +++ b/tests/cases/compiler/nonContextuallyTypedLogicalOr.ts @@ -11,6 +11,4 @@ interface Ellement { var c: Contextual; var e: Ellement; -// This should error. Even though we are contextually typing e with Contextual, the RHS still -// needs to be a supertype of the LHS to win as the best common type. (c || e).dummy; \ No newline at end of file diff --git a/tests/cases/compiler/promisePermutations.ts b/tests/cases/compiler/promisePermutations.ts index c5091aaa630..0ce62be8181 100644 --- a/tests/cases/compiler/promisePermutations.ts +++ b/tests/cases/compiler/promisePermutations.ts @@ -11,7 +11,7 @@ interface IPromise { then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -71,7 +71,7 @@ var s3: Promise; var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); -var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); +var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // error var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -82,7 +82,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -134,7 +134,7 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); @@ -149,15 +149,15 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/cases/compiler/promisePermutations2.ts b/tests/cases/compiler/promisePermutations2.ts index 66f9806de00..05a60860929 100644 --- a/tests/cases/compiler/promisePermutations2.ts +++ b/tests/cases/compiler/promisePermutations2.ts @@ -10,7 +10,7 @@ interface IPromise { then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -81,7 +81,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -125,7 +125,7 @@ var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -133,14 +133,14 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -148,11 +148,11 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok diff --git a/tests/cases/compiler/promisePermutations3.ts b/tests/cases/compiler/promisePermutations3.ts index 78d6b17c9ec..3aab00b0ed0 100644 --- a/tests/cases/compiler/promisePermutations3.ts +++ b/tests/cases/compiler/promisePermutations3.ts @@ -10,7 +10,7 @@ interface Promise { interface IPromise { then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -81,7 +81,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -125,7 +125,7 @@ var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -133,14 +133,14 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -148,15 +148,15 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/cases/compiler/tupleTypes.ts b/tests/cases/compiler/tupleTypes.ts index 3b22c284cb1..80181f8b332 100644 --- a/tests/cases/compiler/tupleTypes.ts +++ b/tests/cases/compiler/tupleTypes.ts @@ -8,8 +8,8 @@ var t0 = t[0]; // number var t0: number; var t1 = t[1]; // string var t1: string; -var t2 = t[2]; // {} -var t2: {}; +var t2 = t[2]; // number|string +var t2: number|string; t = []; // Error t = [1]; // Error @@ -32,8 +32,8 @@ var tt0 = tt[0]; var tt0: number; var tt1 = tt[1]; var tt1: string; -var tt2 = tt[2]; -var tt2: {}; +var tt2 = tt[2]; +var tt2: number | string; tt = tuple2(1, undefined); tt = [1, undefined]; diff --git a/tests/cases/compiler/typeArgInference2.ts b/tests/cases/compiler/typeArgInference2.ts index 523d1eab506..5bf8599996e 100644 --- a/tests/cases/compiler/typeArgInference2.ts +++ b/tests/cases/compiler/typeArgInference2.ts @@ -1,12 +1,12 @@ -interface Item { - name: string; -} - -declare function foo(x?: T, y?: T): T; - -var z1 = foo(null); // any -var z2 = foo(); // Item -var z3 = foo({ name: null }); // { name: any } -var z4 = foo({ name: "abc" }); // { name: string } -var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } -var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // Item \ No newline at end of file +interface Item { + name: string; +} + +declare function foo(x?: T, y?: T): T; + +var z1 = foo(null); // any +var z2 = foo(); // Item +var z3 = foo({ name: null }); // { name: any } +var z4 = foo({ name: "abc" }); // { name: string } +var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } +var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // error \ No newline at end of file diff --git a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts index b4b85573755..41c5a0b8100 100644 --- a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts +++ b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts @@ -1,28 +1,21 @@ // Empty array literal with no contextual type has type Undefined[] var arr1= [[], [1], ['']]; -var arr1: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK var arr2 = [[null], [1], ['']]; -var arr2: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK // Array literal with elements of only EveryType E has type E[] var stringArrArr = [[''], [""]]; -var stringArrArr: string[][]; var stringArr = ['', ""]; -var stringArr: string[]; var numberArr = [0, 0.0, 0x00, 1e1]; -var numberArr: number[]; var boolArr = [false, true, false, true]; -var boolArr: boolean[]; class C { private p; } var classArr = [new C(), new C()]; -var classArr: C[]; // Should be OK var classTypeArray = [C, C, C]; var classTypeArray: Array; // Should OK, not be a parse error @@ -30,7 +23,6 @@ var classTypeArray: Array; // Should OK, not be a parse error // Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[] var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; -var context2: Array<{}>; // Should be OK // Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[] class Base { private p; } diff --git a/tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts b/tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts index 34ef4b3ca8c..feaa3c5a280 100644 --- a/tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts +++ b/tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts @@ -1,21 +1,20 @@ -//Cond ? Expr1 : Expr2, Expr1 and Expr2 have no identical best common type -class X { propertyX: any; propertyX1: number; propertyX2: string }; -class A extends X { propertyA: number }; -class B extends X { propertyB: string }; - -var x: X; -var a: A; -var b: B; - -//Expect to have compiler errors -//Be not contextually typed -true ? a : b; -var result1 = true ? a : b; - -//Be contextually typed and and bct is not identical -var result2: A = true ? a : b; -var result3: B = true ? a : b; - -var result4: (t: X) => number = true ? (m) => m.propertyX1 : (n) => n.propertyX2; -var result5: (t: X) => string = true ? (m) => m.propertyX1 : (n) => n.propertyX2; +//Cond ? Expr1 : Expr2, Expr1 and Expr2 have no identical best common type +class X { propertyX: any; propertyX1: number; propertyX2: string }; +class A extends X { propertyA: number }; +class B extends X { propertyB: string }; + +var x: X; +var a: A; +var b: B; + +// No errors anymore, uses union types +true ? a : b; +var result1 = true ? a : b; + +//Be contextually typed and and bct is not identical, results in errors that union type is not assignable to target +var result2: A = true ? a : b; +var result3: B = true ? a : b; + +var result4: (t: X) => number = true ? (m) => m.propertyX1 : (n) => n.propertyX2; +var result5: (t: X) => string = true ? (m) => m.propertyX1 : (n) => n.propertyX2; var result6: (t: X) => boolean = true ? (m) => m.propertyX1 : (n) => n.propertyX2; \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts index 68ac4cff026..9edf4f5f417 100644 --- a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts +++ b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts @@ -15,8 +15,8 @@ function f2(x: T, y: U, z: V) { var r2 = true ? y : z; // ok - var r2 = true ? z : x; - var r2 = true ? x : z; + var r2a = true ? z : x; + var r2b = true ? x : z; } // Date > U > T @@ -57,18 +57,18 @@ function f4(x: T) { } function f5(x: T) { - var r1 = true ? 1 : x; // error - var r1 = true ? x : 1; // error + var r1 = true ? 1 : x; // ok + var r1 = true ? x : 1; // ok } function f6(x: T) { - var r2 = true ? '' : x; // error - var r2 = true ? x : ''; // error + var r2 = true ? '' : x; // ok + var r2 = true ? x : ''; // ok } function f7(x: T) { - var r3 = true ? true : x; // error - var r3 = true ? x : true; // error + var r3 = true ? true : x; // ok + var r3 = true ? x : true; // ok } function f8(x: T) { @@ -115,11 +115,11 @@ function f15>(x: T) { } function f16(x: T) { - var r13 = true ? E : x; // BUG 831833 - var r13 = true ? x : E; // BUG 831833 + var r13 = true ? E : x; // ok + var r13 = true ? x : E; // ok - var r14 = true ? E.A : x; // BUG 831833 - var r14 = true ? x : E.A; // BUG 831833 + var r14 = true ? E.A : x; // ok + var r14 = true ? x : E.A; // ok } function f17(x: T) { diff --git a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts index 10021cdcc06..96218dce43e 100644 --- a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts +++ b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts @@ -5,11 +5,11 @@ function f(t: T, u: U, v: V) { var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; } \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts index a4e691edbb4..0dc53908ea3 100644 --- a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts +++ b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts @@ -2,15 +2,15 @@ class Foo { foo: number; } function f(t: T, u: U, v: V) { - // error + // ok var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; @@ -22,7 +22,7 @@ function f(t: T, u: U, v: V) { var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // BUG, should be error + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; diff --git a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts index dc3f2917ec1..f63b63432e5 100644 --- a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts +++ b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts @@ -2,53 +2,53 @@ class Foo { foo: T; } function f, U extends Foo, V extends Foo>(t: T, u: U, v: V) { - // error + // ok var r1 = true ? t : u; var r1 = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; - // ok? + // ok var r4 = true ? t : new Foo(); var r4 = true ? new Foo() : t; - // ok? + // ok var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // ok? + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; - // ok? + // ok var r7 = true ? t : new Foo(); var r7 = true ? new Foo() : t; - // ok? + // ok var r8 = true ? u : new Foo(); var r8 = true ? new Foo() : u; - // ok? + // ok var r9 = true ? v : new Foo(); var r9 = true ? new Foo() : v; - // ok? + // ok var r10 = true ? t : new Foo(); var r10 = true ? new Foo() : t; - // ok? + // ok var r11 = true ? u : new Foo(); var r11 = true ? new Foo() : u; - // ok? + // ok var r12 = true ? v : new Foo(); var r12 = true ? new Foo() : v; } diff --git a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts index 601d85704eb..ac8f5642f70 100644 --- a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts +++ b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts @@ -30,4 +30,4 @@ interface S3 extends T3 { // object literal case var a: { Foo: Base; } var b: { Foo?: Derived; } -var r = true ? a : b; // error \ No newline at end of file +var r = true ? a : b; // ok \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts index 3f2e17c6b05..97359cde959 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts @@ -23,14 +23,14 @@ function foo3(x: T, cb: (a: T) => U, y: U) { var r7 = foo3(1, (a: Z) => '', ''); // string -var r8 = foo3(1, function (a) { return '' }, 1); // {} +var r8 = foo3(1, function (a) { return '' }, 1); // error var r9 = foo3(1, (a) => '', ''); // string function other(t: T, u: U) { - var r10 = foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made + var r10 = foo2(1, (x: T) => ''); // error var r10 = foo2(1, (x) => ''); // string - var r11 = foo3(1, (x: T) => '', ''); // string - var r11b = foo3(1, (x: T) => '', 1); // {} - var r12 = foo3(1, function (a) { return '' }, 1); // {} + var r11 = foo3(1, (x: T) => '', ''); // error + var r11b = foo3(1, (x: T) => '', 1); // error + var r12 = foo3(1, function (a) { return '' }, 1); // error } \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts index f313d638bfb..0d02afe9c88 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts @@ -26,7 +26,7 @@ function foo2(x: T, cb: new(a: T) => U) { return new cb(x); } -var r4 = foo2(1, i2); // string, instantiated generic +var r4 = foo2(1, i2); // error var r4b = foo2(1, a); // any var r5 = foo2(1, i); // any var r6 = foo2('', i2); // string @@ -37,5 +37,5 @@ function foo3(x: T, cb: new(a: T) => U, y: U) { var r7 = foo3(null, i, ''); // any var r7b = foo3(null, a, ''); // any -var r8 = foo3(1, i2, 1); // {} +var r8 = foo3(1, i2, 1); // error var r9 = foo3('', i2, ''); // string \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts index 54a7cf7ebc6..c37b2e31333 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts @@ -1,36 +1,73 @@ // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, // the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. -function foo(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; +module onlyT { + function foo(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); + + function other2(x: T) { + var r7 = foo((a: T) => a, (b: T) => b); // T => T + // BUG 835518 + var r9 = r7(new Date()); // should be ok + var r10 = r7(1); // error + } + + function foo2(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + function other3(x: T) { + var r7 = foo2((a: T) => a, (b: T) => b); // error + var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date + } + + enum E { A } + enum F { A } + + function foo3(x: T, a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error } -var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); +module TU { + function foo(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } -function other2(x: T) { - var r7 = foo((a: T) => a, (b: T) => b); // T => T - // BUG 835518 - var r9 = r7(new Date()); // should be ok - var r10 = r7(1); // error -} + var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); -function foo2(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; -} + function other2(x: T) { + var r7 = foo((a: T) => a, (b: T) => b); + var r9 = r7(new Date()); + var r10 = r7(1); + } -function other3(x: T) { - var r7 = foo2((a: T) => a, (b: T) => b); // error - var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date -} + function foo2(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } -enum E { A } -enum F { A } + function other3(x: T) { + var r7 = foo2((a: T) => a, (b: T) => b); + var r7b = foo2((a) => a, (b) => b); + } -function foo3(x: T, a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; -} + enum E { A } + enum F { A } -var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error \ No newline at end of file + function foo3(x: T, a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } + + var r7 = foo3(E.A, (x) => E.A, (x) => F.A); +} \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts index 65f22a3fd3f..82b917efa3e 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts @@ -29,5 +29,5 @@ var r9 = foo2(null, (x) => '', (x) => ''); // any => any var r10 = foo2(null, (x: Object) => '', (x: string) => ''); // Object => Object var x: (a: string) => boolean; -var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // {} => {} -var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // (string => boolean) => {} \ No newline at end of file +var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // error +var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // error \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts index 1e5976b33e5..75b0462b689 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts @@ -2,7 +2,7 @@ function foo(x: { bar: T; baz: T }) { return x; } -var r = foo({ bar: 1, baz: '' }); // T = {} +var r = foo({ bar: 1, baz: '' }); // error var r2 = foo({ bar: 1, baz: 1 }); // T = number var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo var r4 = foo({ bar: 1, baz: '' }); // T = Object \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts index 8bb5d234bb5..527286e6ee2 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts @@ -33,7 +33,7 @@ module GenericParameter { return cb; } - var r8 = foo6(a); // new{} => string; new(x:{}, y?:{}) => string + var r8 = foo6(a); // error var r9 = foo6(b); // new any => string; new(x:any, y?:any) => string function foo7(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }) { diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts index a3b02eaf4e4..f429cd5169d 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts @@ -54,11 +54,11 @@ module WithCandidates { var c3: C3; function other(t: T, u: U) { - var r10 = c.foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made + var r10 = c.foo2(1, (x: T) => ''); // error var r10 = c.foo2(1, (x) => ''); // string - var r11 = c3.foo3(1, (x: T) => '', ''); // string - var r11b = c3.foo3(1, (x: T) => '', 1); // {} - var r12 = c3.foo3(1, function (a) { return '' }, 1); // {} + var r11 = c3.foo3(1, (x: T) => '', ''); // error + var r11b = c3.foo3(1, (x: T) => '', 1); // error + var r12 = c3.foo3(1, function (a) { return '' }, 1); // error } } \ No newline at end of file From f5a9feee9f735c6a198a8b63bfa198346f6cba7e Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 10 Oct 2014 16:41:05 -0700 Subject: [PATCH 15/23] ensure unionProperty symbols have declarations set at creation time --- src/compiler/checker.ts | 8 ++++++++ src/services/services.ts | 15 ++------------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2040ba0d856..5bcf1871f7d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2144,6 +2144,14 @@ module ts { } var symbol = createSymbol(SymbolFlags.UnionProperty | SymbolFlags.Transient, prop.name); symbol.unionType = type; + + symbol.declarations = []; + for (var i = 0; i < types.length; i++) { + var s = getPropertyOfType(types[i], prop.name); + if (s.declarations) + symbol.declarations.push.apply(symbol.declarations, s.declarations); + } + members[prop.name] = symbol; }); var callSignatures = getUnionSignatures(types, SignatureKind.Call); diff --git a/src/services/services.ts b/src/services/services.ts index b6bea438c5a..39575138cc6 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2382,7 +2382,6 @@ module ts { } function getSymbolModifiers(symbol: Symbol): string { - symbol = typeInfoResolver.getRootSymbols(symbol)[0]; return symbol && symbol.declarations && symbol.declarations.length > 0 ? getNodeModifiers(symbol.declarations[0]) : ScriptElementKindModifier.none; @@ -2643,11 +2642,7 @@ module ts { var result: DefinitionInfo[] = []; - // The symbol could be a unionProperty, we need to ensure we are collecting all - // declarations, so use getRootSymbol first. - forEach(typeInfoResolver.getRootSymbols(symbol), s => { - getDefinitionFromSymbol(s, node, result); - }); + getDefinitionFromSymbol(symbol, node, result); return result; } @@ -3162,13 +3157,7 @@ module ts { return [getReferenceEntryFromNode(node)]; } - var declarations = symbol.getDeclarations(); - - // Handle union properties - declarations = []; - forEach(typeInfoResolver.getRootSymbols(symbol), s => { - declarations.push.apply(declarations, s.declarations); - }); + var declarations = symbol.declarations; // The symbol was an internal symbol and does not have a declaration e.g.undefined symbol if (!declarations || !declarations.length) { From 483afea57f0c3f7dc455cc467dfd9e16158d7606 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 10 Oct 2014 16:57:53 -0700 Subject: [PATCH 16/23] Less aggressive subtype reduction in union types --- src/compiler/checker.ts | 48 +++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 180d6ceb6fe..c763f9817e0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2066,7 +2066,7 @@ module ts { } function resolveTupleTypeMembers(type: TupleType) { - var arrayType = resolveObjectTypeMembers(createArrayType(getBestCommonType(type.elementTypes))); + var arrayType = resolveObjectTypeMembers(createArrayType(getUnionType(type.elementTypes))); var members = createTupleTypeMemberSymbols(type.elementTypes); addInheritedMembers(members, arrayType.properties); setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType); @@ -2716,13 +2716,41 @@ module ts { } } - function getUnionType(types: Type[]): Type { + function containsAnyType(types: Type[]) { + for (var i = 0; i < types.length; i++) { + if (types[i].flags & TypeFlags.Any) { + return true; + } + } + return false; + } + + function removeAllButLast(types: Type[], typeToRemove: Type) { + var i = types.length; + while (i > 0 && types.length > 1) { + i--; + if (types[i] === typeToRemove) { + types.splice(i, 1); + } + } + } + + function getUnionType(types: Type[], noSubtypeReduction?: boolean): Type { if (types.length === 0) { return emptyObjectType; } var sortedTypes: Type[] = []; addTypesToSortedSet(sortedTypes, types); - removeSubtypes(sortedTypes); + if (noSubtypeReduction) { + if (containsAnyType(sortedTypes)) { + return anyType; + } + removeAllButLast(sortedTypes, undefinedType); + removeAllButLast(sortedTypes, nullType); + } + else { + removeSubtypes(sortedTypes); + } if (sortedTypes.length === 1) { return sortedTypes[0]; } @@ -2738,7 +2766,7 @@ module ts { function getTypeFromUnionTypeNode(node: UnionTypeNode): Type { var links = getNodeLinks(node); if (!links.resolvedType) { - links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNode)); + links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNode), /*noSubtypeReduction*/ true); } return links.resolvedType; } @@ -2956,7 +2984,7 @@ module ts { return createTupleType(instantiateList((type).elementTypes, mapper, instantiateType)); } if (type.flags & TypeFlags.Union) { - return getUnionType(instantiateList((type).types, mapper, instantiateType)); + return getUnionType(instantiateList((type).types, mapper, instantiateType), /*noSubtypeReduction*/ true); } } return type; @@ -3606,7 +3634,7 @@ module ts { return forEach(types, t => isSupertypeOfEach(t, types) ? t : undefined); } - function getBestCommonType(types: Type[], contextualType?: Type): Type { + function getBestCommonType(types: Type[], contextualType: Type): Type { return contextualType && isSupertypeOfEach(contextualType, types) ? contextualType : getUnionType(types); } function isTypeOfObjectLiteral(type: Type): boolean { @@ -4558,7 +4586,7 @@ module ts { return createTupleType(elementTypes); } var contextualElementType = contextualType && !isInferentialContext(contextualMapper) ? getIndexTypeOfType(contextualType, IndexKind.Number) : undefined; - var elementType = elements.length || contextualElementType ? getBestCommonType(deduplicate(elementTypes), contextualElementType) : undefinedType; + var elementType = elements.length || contextualElementType ? getBestCommonType(elementTypes, contextualElementType) : undefinedType; return createArrayType(elementType); } @@ -5601,7 +5629,7 @@ module ts { case SyntaxKind.AmpersandAmpersandToken: return rightType; case SyntaxKind.BarBarToken: - return getBestCommonType([leftType, rightType], isInferentialContext(contextualMapper) ? undefined : getContextualType(node)); + return getUnionType([leftType, rightType]); case SyntaxKind.EqualsToken: checkAssignmentOperator(rightType); return rightType; @@ -5651,9 +5679,7 @@ module ts { checkExpression(node.condition); var type1 = checkExpression(node.whenTrue, contextualMapper); var type2 = checkExpression(node.whenFalse, contextualMapper); - var contextualType = isInferentialContext(contextualMapper) ? undefined : getContextualType(node); - var resultType = getBestCommonType([type1, type2], contextualType); - return resultType; + return getUnionType([type1, type2]); } function checkExpressionWithContextualType(node: Expression, contextualType: Type, contextualMapper?: TypeMapper): Type { From c9a42c19abff9416222a52bb96c78d3c3c19fb6b Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 10 Oct 2014 17:01:28 -0700 Subject: [PATCH 17/23] Accepting new baselines --- .../reference/aliasUsageInOrExpression.types | 2 +- ...stCommonTypeOfConditionalExpressions.types | 6 ++--- .../conditionalOperatorWithIdenticalBCT.types | 10 ++++---- ...textualTypingOfConditionalExpression.types | 4 ++-- .../contextuallyTypingOrOperator.types | 2 +- .../contextuallyTypingOrOperator2.types | 2 +- .../reference/generatedContextualTyping.types | 24 +++++++++---------- .../genericCallWithObjectTypeArgs2.types | 2 +- ...gicalOrExpressionIsContextuallyTyped.types | 2 +- .../logicalOrOperatorWithTypeParameters.types | 8 +++---- .../returnTypeParameterWithModules.types | 2 +- .../baselines/reference/underscoreTest1.types | 2 +- 12 files changed, 33 insertions(+), 33 deletions(-) diff --git a/tests/baselines/reference/aliasUsageInOrExpression.types b/tests/baselines/reference/aliasUsageInOrExpression.types index fdcf0be4479..c937187f049 100644 --- a/tests/baselines/reference/aliasUsageInOrExpression.types +++ b/tests/baselines/reference/aliasUsageInOrExpression.types @@ -53,7 +53,7 @@ var f: { x: IHasVisualizationModel } = <{ x: IHasVisualizationModel }>null ? { x >f : { x: IHasVisualizationModel; } >x : IHasVisualizationModel >IHasVisualizationModel : IHasVisualizationModel -><{ x: IHasVisualizationModel }>null ? { x: moduleA } : null : { x: IHasVisualizationModel; } +><{ x: IHasVisualizationModel }>null ? { x: moduleA } : null : { x: typeof moduleA; } ><{ x: IHasVisualizationModel }>null : { x: IHasVisualizationModel; } >x : IHasVisualizationModel >IHasVisualizationModel : IHasVisualizationModel diff --git a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types index 18fe6efb8ce..2c3ba8bc7c7 100644 --- a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types +++ b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types @@ -72,7 +72,7 @@ var r7: (x: Object) => void = true ? (x: number) => { } : (x: Object) => { }; >r7 : (x: Object) => void >x : Object >Object : Object ->true ? (x: number) => { } : (x: Object) => { } : (x: Object) => void +>true ? (x: number) => { } : (x: Object) => { } : (x: number) => void >(x: number) => { } : (x: number) => void >x : number >(x: Object) => { } : (x: Object) => void @@ -91,7 +91,7 @@ var r8 = true ? (x: Object) => { } : (x: number) => { }; // returns Object => vo var r10: Base = true ? derived : derived2; // no error since we use the contextual type in BCT >r10 : Base >Base : Base ->true ? derived : derived2 : Base +>true ? derived : derived2 : Derived | Derived2 >derived : Derived >derived2 : Derived2 @@ -112,7 +112,7 @@ function foo5(t: T, u: U): Object { >Object : Object return true ? t : u; // BCT is Object ->true ? t : u : Object +>true ? t : u : T | U >t : T >u : U } diff --git a/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types b/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types index 8ad918936d2..edef88acfc3 100644 --- a/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types +++ b/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types @@ -80,7 +80,7 @@ var result4: (t: A) => any = true ? (m) => m.propertyX : (n) => n.propertyA; >result4 : (t: A) => any >t : A >A : A ->true ? (m) => m.propertyX : (n) => n.propertyA : (t: A) => any +>true ? (m) => m.propertyX : (n) => n.propertyA : (m: A) => any >(m) => m.propertyX : (m: A) => any >m : A >m.propertyX : any @@ -144,7 +144,7 @@ var result8: (t: A) => any = true ? (m) => m.propertyA : (n) => n.propertyX; >result8 : (t: A) => any >t : A >A : A ->true ? (m) => m.propertyA : (n) => n.propertyX : (t: A) => any +>true ? (m) => m.propertyA : (n) => n.propertyX : (n: A) => any >(m) => m.propertyA : (m: A) => number >m : A >m.propertyA : number @@ -161,7 +161,7 @@ var result8: (t: A) => any = true ? (m) => m.propertyA : (n) => n.propertyX; var resultIsX3: X = true ? a : b; >resultIsX3 : X >X : X ->true ? a : b : X +>true ? a : b : A | B >a : A >b : B @@ -169,7 +169,7 @@ var result10: (t: X) => any = true ? (m) => m.propertyX1 : (n) => n.propertyX2; >result10 : (t: X) => any >t : X >X : X ->true ? (m) => m.propertyX1 : (n) => n.propertyX2 : (t: X) => any +>true ? (m) => m.propertyX1 : (n) => n.propertyX2 : { (m: X): number; } | { (n: X): string; } >(m) => m.propertyX1 : (m: X) => number >m : X >m.propertyX1 : number @@ -184,5 +184,5 @@ var result10: (t: X) => any = true ? (m) => m.propertyX1 : (n) => n.propertyX2; //Expr1 and Expr2 are literals var result11: any = true ? 1 : 'string'; >result11 : any ->true ? 1 : 'string' : any +>true ? 1 : 'string' : string | number diff --git a/tests/baselines/reference/contextualTypingOfConditionalExpression.types b/tests/baselines/reference/contextualTypingOfConditionalExpression.types index 6c6f9b04457..2cd2b671b40 100644 --- a/tests/baselines/reference/contextualTypingOfConditionalExpression.types +++ b/tests/baselines/reference/contextualTypingOfConditionalExpression.types @@ -2,7 +2,7 @@ var x: (a: number) => void = true ? (a) => a.toExponential() : (b) => b.toFixed(); >x : (a: number) => void >a : number ->true ? (a) => a.toExponential() : (b) => b.toFixed() : (a: number) => void +>true ? (a) => a.toExponential() : (b) => b.toFixed() : (a: number) => string >(a) => a.toExponential() : (a: number) => string >a : number >a.toExponential() : string @@ -41,7 +41,7 @@ var x2: (a: A) => void = true ? (a) => a.foo : (b) => b.foo; >x2 : (a: A) => void >a : A >A : A ->true ? (a) => a.foo : (b) => b.foo : (a: A) => void +>true ? (a) => a.foo : (b) => b.foo : (a: A) => number >(a) => a.foo : (a: A) => number >a : A >a.foo : number diff --git a/tests/baselines/reference/contextuallyTypingOrOperator.types b/tests/baselines/reference/contextuallyTypingOrOperator.types index 5a20b2b921e..4b47ea763bc 100644 --- a/tests/baselines/reference/contextuallyTypingOrOperator.types +++ b/tests/baselines/reference/contextuallyTypingOrOperator.types @@ -3,7 +3,7 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; >v : { a: (_: string) => number; } >a : (_: string) => number >_ : string ->{ a: s => s.length } || { a: s => 1 } : { a: (_: string) => number; } +>{ a: s => s.length } || { a: s => 1 } : { a: (s: string) => number; } >{ a: s => s.length } : { a: (s: string) => number; } >a : (s: string) => number >s => s.length : (s: string) => number diff --git a/tests/baselines/reference/contextuallyTypingOrOperator2.types b/tests/baselines/reference/contextuallyTypingOrOperator2.types index b46d0c0aedb..c233066d6dc 100644 --- a/tests/baselines/reference/contextuallyTypingOrOperator2.types +++ b/tests/baselines/reference/contextuallyTypingOrOperator2.types @@ -3,7 +3,7 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; >v : { a: (_: string) => number; } >a : (_: string) => number >_ : string ->{ a: s => s.length } || { a: s => 1 } : { a: (_: string) => number; } +>{ a: s => s.length } || { a: s => 1 } : { a: (s: string) => number; } >{ a: s => s.length } : { a: (s: string) => number; } >a : (s: string) => number >s => s.length : (s: string) => number diff --git a/tests/baselines/reference/generatedContextualTyping.types b/tests/baselines/reference/generatedContextualTyping.types index c609c6aec9c..658d4a0bff1 100644 --- a/tests/baselines/reference/generatedContextualTyping.types +++ b/tests/baselines/reference/generatedContextualTyping.types @@ -2616,7 +2616,7 @@ var x267: { [n: number]: Base; } = [d1, d2] || undefined; >x267 : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] || undefined : { [x: number]: Base; } +>[d1, d2] || undefined : Base[] >[d1, d2] : Base[] >d1 : Derived1 >d2 : Derived2 @@ -2699,7 +2699,7 @@ var x275: { [n: number]: Base; } = undefined || [d1, d2]; >x275 : { [x: number]: Base; } >n : number >Base : Base ->undefined || [d1, d2] : { [x: number]: Base; } +>undefined || [d1, d2] : Base[] >undefined : undefined >[d1, d2] : Base[] >d1 : Derived1 @@ -2800,7 +2800,7 @@ var x283: { [n: number]: Base; } = [d1, d2] || [d1, d2]; >x283 : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] || [d1, d2] : { [x: number]: Base; } +>[d1, d2] || [d1, d2] : Base[] >[d1, d2] : Base[] >d1 : Derived1 >d2 : Derived2 @@ -2933,7 +2933,7 @@ var x293: { [n: number]: Base; } = true ? [d1, d2] : [d1, d2]; >x293 : { [x: number]: Base; } >n : number >Base : Base ->true ? [d1, d2] : [d1, d2] : { [x: number]: Base; } +>true ? [d1, d2] : [d1, d2] : Base[] >[d1, d2] : Base[] >d1 : Derived1 >d2 : Derived2 @@ -2961,7 +2961,7 @@ var x295: (s: Base[]) => any = true ? n => { var n: Base[]; return null; } : n = >x295 : (s: Base[]) => any >s : Base[] >Base : Base ->true ? n => { var n: Base[]; return null; } : n => { var n: Base[]; return null; } : (s: Base[]) => any +>true ? n => { var n: Base[]; return null; } : n => { var n: Base[]; return null; } : (n: Base[]) => any >n => { var n: Base[]; return null; } : (n: Base[]) => any >n : Base[] >n : Base[] @@ -2975,7 +2975,7 @@ var x296: Genric = true ? { func: n => { return [d1, d2]; } } : { func: n >x296 : Genric >Genric : Genric >Base : Base ->true ? { func: n => { return [d1, d2]; } } : { func: n => { return [d1, d2]; } } : Genric +>true ? { func: n => { return [d1, d2]; } } : { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } >{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } >func : (n: Base[]) => Array >n => { return [d1, d2]; } : (n: Base[]) => Array @@ -3076,7 +3076,7 @@ var x305: { [n: number]: Base; } = true ? undefined : [d1, d2]; >x305 : { [x: number]: Base; } >n : number >Base : Base ->true ? undefined : [d1, d2] : { [x: number]: Base; } +>true ? undefined : [d1, d2] : Base[] >undefined : undefined >[d1, d2] : Base[] >d1 : Derived1 @@ -3098,7 +3098,7 @@ var x307: (s: Base[]) => any = true ? undefined : n => { var n: Base[]; return n >x307 : (s: Base[]) => any >s : Base[] >Base : Base ->true ? undefined : n => { var n: Base[]; return null; } : (s: Base[]) => any +>true ? undefined : n => { var n: Base[]; return null; } : (n: Base[]) => any >undefined : undefined >n => { var n: Base[]; return null; } : (n: Base[]) => any >n : Base[] @@ -3109,7 +3109,7 @@ var x308: Genric = true ? undefined : { func: n => { return [d1, d2]; } }; >x308 : Genric >Genric : Genric >Base : Base ->true ? undefined : { func: n => { return [d1, d2]; } } : Genric +>true ? undefined : { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } >undefined : undefined >{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } >func : (n: Base[]) => Array @@ -3204,7 +3204,7 @@ var x317: { [n: number]: Base; } = true ? [d1, d2] : undefined; >x317 : { [x: number]: Base; } >n : number >Base : Base ->true ? [d1, d2] : undefined : { [x: number]: Base; } +>true ? [d1, d2] : undefined : Base[] >[d1, d2] : Base[] >d1 : Derived1 >d2 : Derived2 @@ -3226,7 +3226,7 @@ var x319: (s: Base[]) => any = true ? n => { var n: Base[]; return null; } : und >x319 : (s: Base[]) => any >s : Base[] >Base : Base ->true ? n => { var n: Base[]; return null; } : undefined : (s: Base[]) => any +>true ? n => { var n: Base[]; return null; } : undefined : (n: Base[]) => any >n => { var n: Base[]; return null; } : (n: Base[]) => any >n : Base[] >n : Base[] @@ -3237,7 +3237,7 @@ var x320: Genric = true ? { func: n => { return [d1, d2]; } } : undefined; >x320 : Genric >Genric : Genric >Base : Base ->true ? { func: n => { return [d1, d2]; } } : undefined : Genric +>true ? { func: n => { return [d1, d2]; } } : undefined : { func: (n: Base[]) => Array; } >{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } >func : (n: Base[]) => Array >n => { return [d1, d2]; } : (n: Base[]) => Array diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgs2.types b/tests/baselines/reference/genericCallWithObjectTypeArgs2.types index 6c8ed4e468a..aa1eeaf4670 100644 --- a/tests/baselines/reference/genericCallWithObjectTypeArgs2.types +++ b/tests/baselines/reference/genericCallWithObjectTypeArgs2.types @@ -57,7 +57,7 @@ var r = f({ x: new Derived(), y: new Derived2() }); // {}[] var r2 = f({ x: new Base(), y: new Derived2() }); // {}[] >r2 : Base[] ->f({ x: new Base(), y: new Derived2() }) : Base[] +>f({ x: new Base(), y: new Derived2() }) : Array >f : (a: { x: T; y: U; }) => Array >{ x: new Base(), y: new Derived2() } : { x: Base; y: Derived2; } >x : Base diff --git a/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.types b/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.types index d44b220e818..95c9643c29a 100644 --- a/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.types +++ b/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.types @@ -7,7 +7,7 @@ var r: { a: string } = { a: '', b: 123 } || { a: '', b: true }; >r : { a: string; } >a : string ->{ a: '', b: 123 } || { a: '', b: true } : { a: string; } +>{ a: '', b: 123 } || { a: '', b: true } : { a: string; b: number; } | { a: string; b: boolean; } >{ a: '', b: 123 } : { a: string; b: number; } >a : string >b : number diff --git a/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types b/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types index 9a450b87784..4008fbbff50 100644 --- a/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types +++ b/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types @@ -29,7 +29,7 @@ function fn1(t: T, u: U) { var r4: {} = t || u; >r4 : {} ->t || u : {} +>t || u : T | U >t : T >u : U } @@ -74,7 +74,7 @@ function fn2(t: T, u: U, v: V) { var r6: {} = u || v; >r6 : {} ->u || v : {} +>u || v : U | V >u : U >v : V @@ -102,7 +102,7 @@ function fn3r2 : {} ->t || u : {} +>t || u : T | U >t : T >u : U @@ -116,7 +116,7 @@ function fn3r4 : { a: string; } >a : string ->t || u : { a: string; } +>t || u : T | U >t : T >u : U } diff --git a/tests/baselines/reference/returnTypeParameterWithModules.types b/tests/baselines/reference/returnTypeParameterWithModules.types index adcc1b4bcee..4be0efcd2a5 100644 --- a/tests/baselines/reference/returnTypeParameterWithModules.types +++ b/tests/baselines/reference/returnTypeParameterWithModules.types @@ -21,7 +21,7 @@ module M1 { >reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >apply : (thisArg: any, argArray?: any) => any >ar : any ->e ? [f, e] : [f] : any +>e ? [f, e] : [f] : any[] >e : any >[f, e] : any[] >f : any diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index a23eff1f8ea..c73c63aee26 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -309,7 +309,7 @@ _.countBy([1, 2, 3, 4, 5], (num) => num % 2 == 0 ? 'even' : 'odd'); >[1, 2, 3, 4, 5] : number[] >(num) => num % 2 == 0 ? 'even' : 'odd' : (num: number) => string >num : number ->num % 2 == 0 ? 'even' : 'odd' : any +>num % 2 == 0 ? 'even' : 'odd' : string >num % 2 == 0 : boolean >num % 2 : number >num : number From 2ce627c6dd8ac4bce85c87f3f41e3649ca870ddd Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 10 Oct 2014 17:07:13 -0700 Subject: [PATCH 18/23] Handle union properties completions on apparant types --- src/compiler/checker.ts | 2 +- .../completionEntryForUnionProperty2.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionEntryForUnionProperty2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5bcf1871f7d..56dc73237f3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7916,7 +7916,7 @@ module ts { var symbols: Symbol[] = []; var name = symbol.name; forEach(getSymbolLinks(symbol).unionType.types, t => { - symbols.push(getPropertyOfType(t, name)); + symbols.push(getPropertyOfType(getApparentType(t), name)); }); return symbols; } diff --git a/tests/cases/fourslash/completionEntryForUnionProperty2.ts b/tests/cases/fourslash/completionEntryForUnionProperty2.ts new file mode 100644 index 00000000000..fef5e0dfb50 --- /dev/null +++ b/tests/cases/fourslash/completionEntryForUnionProperty2.ts @@ -0,0 +1,19 @@ +/// + +////interface One { +//// commonProperty: number; +//// commonFunction(): number; +////} +//// +////interface Two { +//// commonProperty: string +//// commonFunction(): number; +////} +//// +////var x : One | Two; +//// +////x.commonProperty./**/ + +goTo.marker(); +verify.memberListContains("toString", "() => string", undefined, undefined, "method"); +verify.memberListCount(1); \ No newline at end of file From 4442b45bad79223c3ca6893a1c56eb81d30af23d Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 10 Oct 2014 17:19:43 -0700 Subject: [PATCH 19/23] Add a temporary fix to quick info --- src/services/services.ts | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 39575138cc6..539c154f6b8 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2404,31 +2404,34 @@ module ts { var documentationParts = getSymbolDocumentationDisplayParts(symbol); + // TODO: handle union properties appropriately when merging with master + var symbolFlags = typeInfoResolver.getRootSymbols(symbol)[0].flags; + // Having all this logic here is pretty unclean. Consider moving to the roslyn model // where all symbol display logic is encapsulated into visitors and options. var totalParts: SymbolDisplayPart[] = []; - if (symbol.flags & SymbolFlags.Class) { + if (symbolFlags & SymbolFlags.Class) { totalParts.push(keywordPart(SyntaxKind.ClassKeyword)); totalParts.push(spacePart()); totalParts.push.apply(totalParts, typeInfoResolver.symbolToDisplayParts(symbol, sourceFile)); } - else if (symbol.flags & SymbolFlags.Interface) { + else if (symbolFlags & SymbolFlags.Interface) { totalParts.push(keywordPart(SyntaxKind.InterfaceKeyword)); totalParts.push(spacePart()); totalParts.push.apply(totalParts, typeInfoResolver.symbolToDisplayParts(symbol, sourceFile)); } - else if (symbol.flags & SymbolFlags.Enum) { + else if (symbolFlags & SymbolFlags.Enum) { totalParts.push(keywordPart(SyntaxKind.EnumKeyword)); totalParts.push(spacePart()); totalParts.push.apply(totalParts, typeInfoResolver.symbolToDisplayParts(symbol, sourceFile)); } - else if (symbol.flags & SymbolFlags.Module) { + else if (symbolFlags & SymbolFlags.Module) { totalParts.push(keywordPart(SyntaxKind.ModuleKeyword)); totalParts.push(spacePart()); totalParts.push.apply(totalParts, typeInfoResolver.symbolToDisplayParts(symbol, sourceFile)); } - else if (symbol.flags & SymbolFlags.TypeParameter) { + else if (symbolFlags & SymbolFlags.TypeParameter) { totalParts.push(punctuationPart(SyntaxKind.OpenParenToken)); totalParts.push(new SymbolDisplayPart("type parameter", SymbolDisplayPartKind.text, undefined)); totalParts.push(punctuationPart(SyntaxKind.CloseParenToken)); @@ -2439,11 +2442,11 @@ module ts { totalParts.push(punctuationPart(SyntaxKind.OpenParenToken)); var text: string; - if (symbol.flags & SymbolFlags.Property) { text = "property" } - else if (symbol.flags & SymbolFlags.EnumMember) { text = "enum member" } - else if (symbol.flags & SymbolFlags.Function) { text = "function" } - else if (symbol.flags & SymbolFlags.Variable) { text = "variable" } - else if (symbol.flags & SymbolFlags.Method) { text = "method" } + if (symbolFlags & SymbolFlags.Property) { text = "property" } + else if (symbolFlags & SymbolFlags.EnumMember) { text = "enum member" } + else if (symbolFlags & SymbolFlags.Function) { text = "function" } + else if (symbolFlags & SymbolFlags.Variable) { text = "variable" } + else if (symbolFlags & SymbolFlags.Method) { text = "method" } if (!text) { return undefined; @@ -2457,8 +2460,8 @@ module ts { var type = typeInfoResolver.getTypeOfSymbol(symbol); - if (symbol.flags & SymbolFlags.Property || - symbol.flags & SymbolFlags.Variable) { + if (symbolFlags & SymbolFlags.Property || + symbolFlags & SymbolFlags.Variable) { if (type) { totalParts.push(punctuationPart(SyntaxKind.ColonToken)); @@ -2466,13 +2469,13 @@ module ts { totalParts.push.apply(totalParts, typeInfoResolver.typeToDisplayParts(type, getContainerNode(node))); } } - else if (symbol.flags & SymbolFlags.Function || - symbol.flags & SymbolFlags.Method) { + else if (symbolFlags & SymbolFlags.Function || + symbolFlags & SymbolFlags.Method) { if (type) { totalParts.push.apply(totalParts, typeInfoResolver.typeToDisplayParts(type, getContainerNode(node))); } } - else if (symbol.flags & SymbolFlags.EnumMember) { + else if (symbolFlags & SymbolFlags.EnumMember) { var declaration = symbol.declarations[0]; if (declaration.kind === SyntaxKind.EnumMember) { var constantValue = typeInfoResolver.getEnumMemberValue(declaration); From 83d9aed005502523ac3ef7198d92c51c8f2bb211 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 13 Oct 2014 06:56:15 -0700 Subject: [PATCH 20/23] Correct contextual typing with union types --- src/compiler/checker.ts | 154 ++++++++++++++++++++++++++++------------ 1 file changed, 107 insertions(+), 47 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 38a0cb80797..a14c4200f1d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4480,6 +4480,54 @@ module ts { return undefined; } + // Apply a mapping function to a contextual type and return the resulting type. If the contextual type + // is a union type, the mapping function is applied to each constituent type and a union of the resulting + // types is returned. + function applyToContextualType(type: Type, mapper: (t: Type) => Type): Type { + if (!(type.flags & TypeFlags.Union)) { + return mapper(type); + } + var types = (type).types; + var mappedType: Type; + var mappedTypes: Type[]; + for (var i = 0; i < types.length; i++) { + var t = mapper(types[i]); + if (t) { + if (!mappedType) { + mappedType = t; + } + else if (!mappedTypes) { + mappedTypes = [mappedType, t]; + } + else { + mappedTypes.push(t); + } + } + } + return mappedTypes ? getUnionType(mappedTypes) : mappedType; + } + + function getTypeOfPropertyOfContextualType(type: Type, name: string) { + return applyToContextualType(type, t => { + var prop = getPropertyOfType(t, name); + return prop ? getTypeOfSymbol(prop) : undefined; + }); + } + + function getIndexTypeOfContextualType(type: Type, kind: IndexKind) { + return applyToContextualType(type, t => getIndexTypeOfType(t, kind)); + } + + // Return true if the given contextual type is a tuple-like type + function contextualTypeIsTupleType(type: Type): boolean { + return !!(type.flags & TypeFlags.Union ? forEach((type).types, t => getPropertyOfType(t, "0")) : getPropertyOfType(type, "0")); + } + + // Return true if the given contextual type provides an index signature of the given kind + function contextualTypeHasIndexSignature(type: Type, kind: IndexKind): boolean { + return !!(type.flags & TypeFlags.Union ? forEach((type).types, t => getIndexTypeOfType(t, kind)) : getIndexTypeOfType(type, kind)); + } + // In an object literal contextually typed by a type T, the contextual type of a property assignment is the type of // the matching property in T, if one exists. Otherwise, it is the type of the numeric index signature in T, if one // exists. Otherwise, it is the type of the string index signature in T, if one exists. @@ -4489,11 +4537,9 @@ module ts { var type = getContextualType(objectLiteral); var name = declaration.name.text; if (type && name) { - var prop = getPropertyOfType(type, name); - if (prop) { - return getTypeOfSymbol(prop); - } - return isNumericName(name) && getIndexTypeOfType(type, IndexKind.Number) || getIndexTypeOfType(type, IndexKind.String); + return getTypeOfPropertyOfContextualType(type, name) || + isNumericName(name) && getIndexTypeOfContextualType(type, IndexKind.Number) || + getIndexTypeOfContextualType(type, IndexKind.String); } return undefined; } @@ -4506,11 +4552,7 @@ module ts { var type = getContextualType(arrayLiteral); if (type) { var index = indexOf(arrayLiteral.elements, node); - var prop = getPropertyOfType(type, "" + index); - if (prop) { - return getTypeOfSymbol(prop); - } - return getIndexTypeOfType(type, IndexKind.Number); + return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, IndexKind.Number); } return undefined; } @@ -4528,7 +4570,6 @@ module ts { // We cannot answer semantic questions within a with block, do not proceed any further return undefined; } - if (node.contextualType) { return node.contextualType; } @@ -4558,18 +4599,45 @@ module ts { return undefined; } + // Return the single non-generic signature in the given type, or undefined if none exists + function getNonGenericSignature(type: Type): Signature { + var signatures = getSignaturesOfType(type, SignatureKind.Call); + if (signatures.length !== 1) { + return undefined; + } + var signature = signatures[0]; + if (signature.typeParameters) { + return undefined; + } + return signature; + } + + // Return the contextual signature for a given expression node. A contextual type provides a + // contextual signature if it has a single call signature and if that call signature is non-generic. + // If the contextual type is a union type and each constituent type that has a contextual signature + // provides the same contextual signature, then the union type provides that contextual signature. function getContextualSignature(node: Expression): Signature { var type = getContextualType(node); - if (type) { - var signatures = getSignaturesOfType(type, SignatureKind.Call); - if (signatures.length === 1) { - var signature = signatures[0]; - if (!signature.typeParameters) { - return signature; + if (!type) { + return undefined; + } + if (!(type.flags & TypeFlags.Union)) { + return getNonGenericSignature(type); + } + var result: Signature; + var types = (type).types; + for (var i = 0; i < types.length; i++) { + var signature = getNonGenericSignature(types[i]); + if (signature) { + if (!result) { + result = signature; + } + else if (!compareSignatures(result, signature, /*compareReturnTypes*/ true, isTypeIdenticalTo)) { + return undefined; } } } - return undefined; + return result; } // Presence of a contextual type mapper indicates inferential typing, except the identityMapper object is @@ -4579,24 +4647,16 @@ module ts { } function checkArrayLiteral(node: ArrayLiteral, contextualMapper?: TypeMapper): Type { - var contextualType = getContextualType(node); var elements = node.elements; - var elementTypes: Type[] = []; - var isTupleLiteral: boolean = false; - for (var i = 0; i < elements.length; i++) { - if (contextualType && getPropertyOfType(contextualType, "" + i)) { - isTupleLiteral = true; - } - var element = elements[i]; - var type = element.kind !== SyntaxKind.OmittedExpression ? checkExpression(element, contextualMapper) : undefinedType; - elementTypes.push(type); + if (!elements.length) { + return createArrayType(undefinedType); } - if (isTupleLiteral) { + var elementTypes = map(elements, e => checkExpression(e, contextualMapper)); + var contextualType = getContextualType(node); + if (contextualType && contextualTypeIsTupleType(contextualType)) { return createTupleType(elementTypes); } - var contextualElementType = contextualType && !isInferentialContext(contextualMapper) ? getIndexTypeOfType(contextualType, IndexKind.Number) : undefined; - var elementType = elements.length || contextualElementType ? getBestCommonType(elementTypes, contextualElementType) : undefinedType; - return createArrayType(elementType); + return createArrayType(getUnionType(elementTypes)); } function isNumericName(name: string) { @@ -4607,7 +4667,6 @@ module ts { var members = node.symbol.members; var properties: SymbolTable = {}; var contextualType = getContextualType(node); - for (var id in members) { if (hasProperty(members, id)) { var member = members[id]; @@ -4645,21 +4704,19 @@ module ts { return createAnonymousType(node.symbol, properties, emptyArray, emptyArray, stringIndexType, numberIndexType); function getIndexType(kind: IndexKind) { - if (contextualType) { - var indexType = getIndexTypeOfType(contextualType, kind); - if (indexType) { - var propTypes: Type[] = []; - for (var id in properties) { - if (hasProperty(properties, id)) { - if (kind === IndexKind.String || isNumericName(id)) { - var type = getTypeOfSymbol(properties[id]); - if (!contains(propTypes, type)) propTypes.push(type); - } + if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { + var propTypes: Type[] = []; + for (var id in properties) { + if (hasProperty(properties, id)) { + if (kind === IndexKind.String || isNumericName(id)) { + var type = getTypeOfSymbol(properties[id]); + if (!contains(propTypes, type)) propTypes.push(type); } } - return getBestCommonType(propTypes, isInferentialContext(contextualMapper) ? undefined : indexType); } + return propTypes.length ? getUnionType(propTypes) : undefinedType; } + return undefined; } } @@ -5249,11 +5306,12 @@ module ts { } function getReturnTypeFromBody(func: FunctionDeclaration, contextualMapper?: TypeMapper): Type { + var contextualSignature = getContextualSignature(func); if (func.body.kind !== SyntaxKind.FunctionBlock) { var unwidenedType = checkAndMarkExpression(func.body, contextualMapper); var widenedType = getWidenedType(unwidenedType); - if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && !contextualSignature && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(func, Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeToString(widenedType)); } @@ -5267,7 +5325,7 @@ module ts { if (types.length > 0) { // When return statements are contextually typed we allow the return type to be a union type. Otherwise we require the // return expressions to have a best common supertype. - var commonType = getContextualSignature(func) ? getUnionType(types) : getCommonSupertype(types); + var commonType = contextualSignature ? getUnionType(types) : getCommonSupertype(types); if (!commonType) { error(func, Diagnostics.No_best_common_type_exists_among_return_expressions); @@ -5277,7 +5335,7 @@ module ts { var widenedType = getWidenedType(commonType); // Check and report for noImplicitAny if the best common type implicitly gets widened to an 'any'/arrays-of-'any' type. - if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && !contextualSignature && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { var typeName = typeToString(widenedType); if (func.name) { @@ -5776,6 +5834,8 @@ module ts { return checkBinaryExpression(node, contextualMapper); case SyntaxKind.ConditionalExpression: return checkConditionalExpression(node, contextualMapper); + case SyntaxKind.OmittedExpression: + return undefinedType; } return unknownType; } From a76a4188148f18f8758a3aeb9d657b0c45af07dd Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 13 Oct 2014 06:56:58 -0700 Subject: [PATCH 21/23] Accepting new baselines --- .../reference/aliasUsageInArray.types | 2 +- .../reference/arrayBestCommonTypes.types | 8 +- tests/baselines/reference/arrayConcat2.types | 2 +- tests/baselines/reference/arrayLiteral.types | 2 +- .../arrayLiteralContextualType.types | 4 +- .../arrayLiteralInNonVarArgParameter.types | 2 +- .../reference/arrayLiteralTypeInference.types | 10 +- tests/baselines/reference/arrayLiterals.types | 6 +- .../reference/badOverloadError.types | 2 +- .../contextualTypeArrayReturnType.types | 10 +- .../reference/contextualTyping32.types | 2 +- .../reference/declFileGenericType2.types | 4 +- .../decrementOperatorWithAnyOtherType.types | 2 +- ...rivedTypeDoesNotRequireExtendsClause.types | 2 +- ...denAtObjectLiteralPropertyAssignment.types | 2 +- ...ndingClassFromAliasAndUsageInIndexer.types | 2 +- .../forStatementsMultipleValidDecl.types | 4 +- tests/baselines/reference/functionCall3.types | 2 +- .../reference/functionOverloads42.types | 2 +- .../functionSubtypingOfVarArgs2.types | 2 +- .../reference/generatedContextualTyping.types | 1522 ++++++++--------- tests/baselines/reference/genericArray0.types | 2 +- .../genericBaseClassLiteralProperty2.types | 4 +- .../genericCallWithArrayLiteralArgs.types | 10 +- .../genericTypeArgumentInference1.types | 2 +- ...nericWithIndexerOfTypeParameterType1.types | 2 +- .../heterogeneousArrayLiterals.types | 10 +- .../incrementOperatorWithAnyOtherType.types | 2 +- .../indexSignaturesInferentialTyping.types | 6 +- tests/baselines/reference/indexer.types | 2 +- tests/baselines/reference/indexer2.errors.txt | 20 + tests/baselines/reference/indexer2.types | 21 - .../baselines/reference/indexer2A.errors.txt | 15 +- tests/baselines/reference/indexer3.types | 2 +- tests/baselines/reference/indexerA.types | 2 +- ...inferentialTypingWithFunctionTypeZip.types | 2 +- .../inferentiallyTypingAnEmptyArray.types | 2 +- .../reference/interfaceContextualType.types | 8 +- .../memberVariableDeclarations1.types | 6 +- .../negateOperatorWithAnyOtherType.types | 2 +- ...AnyFunctionExpressionAssignment.errors.txt | 21 - ...licitAnyFunctionExpressionAssignment.types | 24 + .../reference/numericIndexerConstraint4.types | 2 +- tests/baselines/reference/objectIndexer.types | 4 +- ...ectTypesIdentityWithNumericIndexers1.types | 2 +- ...ectTypesIdentityWithNumericIndexers2.types | 2 +- ...ectTypesIdentityWithNumericIndexers3.types | 2 +- ...overloadResolutionOverNonCTObjectLit.types | 2 +- .../sourceMapValidationClasses.types | 2 +- .../baselines/reference/targetTypeTest2.types | 4 +- .../thisInPropertyBoundDeclarations.types | 2 +- .../baselines/reference/tupleTypes.errors.txt | 12 +- ...notationBestCommonTypeInArrayLiteral.types | 2 +- .../undefinedInferentialTyping.types | 2 +- .../baselines/reference/underscoreTest1.types | 22 +- .../validMultipleVariableDeclarations.types | 4 +- 56 files changed, 918 insertions(+), 905 deletions(-) create mode 100644 tests/baselines/reference/indexer2.errors.txt delete mode 100644 tests/baselines/reference/indexer2.types delete mode 100644 tests/baselines/reference/noImplicitAnyFunctionExpressionAssignment.errors.txt create mode 100644 tests/baselines/reference/noImplicitAnyFunctionExpressionAssignment.types diff --git a/tests/baselines/reference/aliasUsageInArray.types b/tests/baselines/reference/aliasUsageInArray.types index df657233f90..2e792d39603 100644 --- a/tests/baselines/reference/aliasUsageInArray.types +++ b/tests/baselines/reference/aliasUsageInArray.types @@ -17,7 +17,7 @@ interface IHasVisualizationModel { var xs: IHasVisualizationModel[] = [moduleA]; >xs : IHasVisualizationModel[] >IHasVisualizationModel : IHasVisualizationModel ->[moduleA] : IHasVisualizationModel[] +>[moduleA] : typeof moduleA[] >moduleA : typeof moduleA var xs2: typeof moduleA[] = [moduleA]; diff --git a/tests/baselines/reference/arrayBestCommonTypes.types b/tests/baselines/reference/arrayBestCommonTypes.types index a2a6921ca4e..c9d39d5c1e8 100644 --- a/tests/baselines/reference/arrayBestCommonTypes.types +++ b/tests/baselines/reference/arrayBestCommonTypes.types @@ -189,7 +189,7 @@ module EmptyTypes { >x : number >y : base >base : base ->[{ x: 7, y: new derived() }, { x: 5, y: new base() }] : { x: number; y: base; }[] +>[{ x: 7, y: new derived() }, { x: 5, y: new base() }] : { x: number; y: derived; }[] >{ x: 7, y: new derived() } : { x: number; y: derived; } >x : number >y : derived @@ -206,7 +206,7 @@ module EmptyTypes { >x : boolean >y : base >base : base ->[{ x: true, y: new derived() }, { x: false, y: new base() }] : { x: boolean; y: base; }[] +>[{ x: true, y: new derived() }, { x: false, y: new base() }] : { x: boolean; y: derived; }[] >{ x: true, y: new derived() } : { x: boolean; y: derived; } >x : boolean >y : derived @@ -223,7 +223,7 @@ module EmptyTypes { >x : string >y : base >base : base ->[{ x: undefined, y: new base() }, { x: '', y: new derived() }] : { x: string; y: base; }[] +>[{ x: undefined, y: new base() }, { x: '', y: new derived() }] : { x: string; y: derived; }[] >{ x: undefined, y: new base() } : { x: undefined; y: base; } >x : undefined >undefined : undefined @@ -557,7 +557,7 @@ module NonEmptyTypes { >x : string >y : base >base : base ->[{ x: undefined, y: new base() }, { x: '', y: new derived() }] : { x: string; y: base; }[] +>[{ x: undefined, y: new base() }, { x: '', y: new derived() }] : Array<{ x: undefined; y: base; } | { x: string; y: derived; }> >{ x: undefined, y: new base() } : { x: undefined; y: base; } >x : undefined >undefined : undefined diff --git a/tests/baselines/reference/arrayConcat2.types b/tests/baselines/reference/arrayConcat2.types index a4036560305..4cd02d31f9d 100644 --- a/tests/baselines/reference/arrayConcat2.types +++ b/tests/baselines/reference/arrayConcat2.types @@ -1,7 +1,7 @@ === tests/cases/compiler/arrayConcat2.ts === var a: string[] = []; >a : string[] ->[] : string[] +>[] : undefined[] a.concat("hello", 'world'); >a.concat("hello", 'world') : string[] diff --git a/tests/baselines/reference/arrayLiteral.types b/tests/baselines/reference/arrayLiteral.types index 1b356773dc7..9378a508228 100644 --- a/tests/baselines/reference/arrayLiteral.types +++ b/tests/baselines/reference/arrayLiteral.types @@ -25,7 +25,7 @@ var y = new Array(); var x2: number[] = []; >x2 : number[] ->[] : number[] +>[] : undefined[] var x2: number[] = new Array(1); >x2 : number[] diff --git a/tests/baselines/reference/arrayLiteralContextualType.types b/tests/baselines/reference/arrayLiteralContextualType.types index 015a428c114..12d08e986f7 100644 --- a/tests/baselines/reference/arrayLiteralContextualType.types +++ b/tests/baselines/reference/arrayLiteralContextualType.types @@ -40,7 +40,7 @@ function bar(animals: { [n: number]: IAnimal }) { } foo([ >foo([ new Giraffe(), new Elephant()]) : void >foo : (animals: IAnimal[]) => void ->[ new Giraffe(), new Elephant()] : IAnimal[] +>[ new Giraffe(), new Elephant()] : Array new Giraffe(), >new Giraffe() : Giraffe @@ -54,7 +54,7 @@ foo([ bar([ >bar([ new Giraffe(), new Elephant()]) : void >bar : (animals: { [x: number]: IAnimal; }) => void ->[ new Giraffe(), new Elephant()] : IAnimal[] +>[ new Giraffe(), new Elephant()] : Array new Giraffe(), >new Giraffe() : Giraffe diff --git a/tests/baselines/reference/arrayLiteralInNonVarArgParameter.types b/tests/baselines/reference/arrayLiteralInNonVarArgParameter.types index c4889e223bb..4743504c33e 100644 --- a/tests/baselines/reference/arrayLiteralInNonVarArgParameter.types +++ b/tests/baselines/reference/arrayLiteralInNonVarArgParameter.types @@ -7,5 +7,5 @@ function panic(val: string[], ...opt: string[]) { } panic([], 'one', 'two'); >panic([], 'one', 'two') : void >panic : (val: string[], ...opt: string[]) => void ->[] : string[] +>[] : undefined[] diff --git a/tests/baselines/reference/arrayLiteralTypeInference.types b/tests/baselines/reference/arrayLiteralTypeInference.types index 5b4d9b7fff8..c80e5e17030 100644 --- a/tests/baselines/reference/arrayLiteralTypeInference.types +++ b/tests/baselines/reference/arrayLiteralTypeInference.types @@ -25,7 +25,7 @@ class ActionB extends Action { var x1: Action[] = [ >x1 : Action[] >Action : Action ->[ { id: 2, trueness: false }, { id: 3, name: "three" }] : Action[] +>[ { id: 2, trueness: false }, { id: 3, name: "three" }] : Array<{ id: number; trueness: boolean; } | { id: number; name: string; }> { id: 2, trueness: false }, >{ id: 2, trueness: false } : { id: number; trueness: boolean; } @@ -42,7 +42,7 @@ var x1: Action[] = [ var x2: Action[] = [ >x2 : Action[] >Action : Action ->[ new ActionA(), new ActionB()] : Action[] +>[ new ActionA(), new ActionB()] : Array new ActionA(), >new ActionA() : ActionA @@ -78,7 +78,7 @@ var z1: { id: number }[] = >id : number [ ->[ { id: 2, trueness: false }, { id: 3, name: "three" } ] : { id: number; }[] +>[ { id: 2, trueness: false }, { id: 3, name: "three" } ] : Array<{ id: number; trueness: boolean; } | { id: number; name: string; }> { id: 2, trueness: false }, >{ id: 2, trueness: false } : { id: number; trueness: boolean; } @@ -97,7 +97,7 @@ var z2: { id: number }[] = >id : number [ ->[ new ActionA(), new ActionB() ] : { id: number; }[] +>[ new ActionA(), new ActionB() ] : Array new ActionA(), >new ActionA() : ActionA @@ -114,7 +114,7 @@ var z3: { id: number }[] = >id : number [ ->[ new Action(), new ActionA(), new ActionB() ] : { id: number; }[] +>[ new Action(), new ActionA(), new ActionB() ] : Action[] new Action(), >new Action() : Action diff --git a/tests/baselines/reference/arrayLiterals.types b/tests/baselines/reference/arrayLiterals.types index d66e9d741a9..8c2fd942c62 100644 --- a/tests/baselines/reference/arrayLiterals.types +++ b/tests/baselines/reference/arrayLiterals.types @@ -65,7 +65,7 @@ var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: ' >n : number >a : string >b : number ->[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : { a: string; b: number; }[] +>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : Array<{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }> >{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; } >a : string >b : number @@ -105,7 +105,7 @@ class Derived2 extends Base { private n }; var context3: Base[] = [new Derived1(), new Derived2()]; >context3 : Base[] >Base : Base ->[new Derived1(), new Derived2()] : Base[] +>[new Derived1(), new Derived2()] : Array >new Derived1() : Derived1 >Derived1 : typeof Derived1 >new Derived2() : Derived2 @@ -115,7 +115,7 @@ var context3: Base[] = [new Derived1(), new Derived2()]; var context4: Base[] = [new Derived1(), new Derived1()]; >context4 : Base[] >Base : Base ->[new Derived1(), new Derived1()] : Base[] +>[new Derived1(), new Derived1()] : Derived1[] >new Derived1() : Derived1 >Derived1 : typeof Derived1 >new Derived1() : Derived1 diff --git a/tests/baselines/reference/badOverloadError.types b/tests/baselines/reference/badOverloadError.types index 837eb5c5c83..ba9d6e76c1c 100644 --- a/tests/baselines/reference/badOverloadError.types +++ b/tests/baselines/reference/badOverloadError.types @@ -6,6 +6,6 @@ function method() { >dictionary : { [x: string]: string; } ><{ [index: string]: string; }>{} : { [x: string]: string; } >index : string ->{} : { [x: string]: string; } +>{} : { [x: string]: undefined; } } diff --git a/tests/baselines/reference/contextualTypeArrayReturnType.types b/tests/baselines/reference/contextualTypeArrayReturnType.types index b0cd03f8510..ceb7aa53f67 100644 --- a/tests/baselines/reference/contextualTypeArrayReturnType.types +++ b/tests/baselines/reference/contextualTypeArrayReturnType.types @@ -26,18 +26,18 @@ interface Transform3D { var style: IBookStyle = { >style : IBookStyle >IBookStyle : IBookStyle ->{ initialLeftPageTransforms: (width: number) => { return [ {'ry': null } ]; }} : { initialLeftPageTransforms: (width: number) => NamedTransform[]; } +>{ initialLeftPageTransforms: (width: number) => { return [ {'ry': null } ]; }} : { initialLeftPageTransforms: (width: number) => { [x: string]: any; 'ry': any; }[]; } initialLeftPageTransforms: (width: number) => { ->initialLeftPageTransforms : (width: number) => NamedTransform[] ->(width: number) => { return [ {'ry': null } ]; } : (width: number) => NamedTransform[] +>initialLeftPageTransforms : (width: number) => { [x: string]: any; 'ry': any; }[] +>(width: number) => { return [ {'ry': null } ]; } : (width: number) => { [x: string]: any; 'ry': any; }[] >width : number return [ ->[ {'ry': null } ] : NamedTransform[] +>[ {'ry': null } ] : { [x: string]: null; 'ry': null; }[] {'ry': null } ->{'ry': null } : { [x: string]: Transform3D; 'ry': null; } +>{'ry': null } : { [x: string]: null; 'ry': null; } ]; } diff --git a/tests/baselines/reference/contextualTyping32.types b/tests/baselines/reference/contextualTyping32.types index a9d41405b93..383615aec3c 100644 --- a/tests/baselines/reference/contextualTyping32.types +++ b/tests/baselines/reference/contextualTyping32.types @@ -5,7 +5,7 @@ function foo(param: {():number; (i:number):number; }[]) { }; foo([function(){ret >i : number >foo([function(){return 1;}, function(){return 4}]) : void >foo : (param: { (): number; (i: number): number; }[]) => void ->[function(){return 1;}, function(){return 4}] : { (): number; (i: number): number; }[] +>[function(){return 1;}, function(){return 4}] : { (): number; }[] >function(){return 1;} : () => number >function(){return 4} : () => number diff --git a/tests/baselines/reference/declFileGenericType2.types b/tests/baselines/reference/declFileGenericType2.types index a6b6546326c..f9345b5ff11 100644 --- a/tests/baselines/reference/declFileGenericType2.types +++ b/tests/baselines/reference/declFileGenericType2.types @@ -131,11 +131,11 @@ module templa.dom.mvc.composite { >super : typeof AbstractElementController this._controllers = []; ->this._controllers = [] : templa.mvc.IController[] +>this._controllers = [] : undefined[] >this._controllers : templa.mvc.IController[] >this : AbstractCompositeElementController >_controllers : templa.mvc.IController[] ->[] : templa.mvc.IController[] +>[] : undefined[] } } } diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherType.types b/tests/baselines/reference/decrementOperatorWithAnyOtherType.types index 4e8387f9066..ab21dd9db5c 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherType.types +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherType.types @@ -9,7 +9,7 @@ var ANY1; var ANY2: any[] = ["", ""]; >ANY2 : any[] ->["", ""] : any[] +>["", ""] : string[] var obj = {x:1,y:null}; >obj : { x: number; y: any; } diff --git a/tests/baselines/reference/derivedTypeDoesNotRequireExtendsClause.types b/tests/baselines/reference/derivedTypeDoesNotRequireExtendsClause.types index 9821ff91123..47b7ed95dc6 100644 --- a/tests/baselines/reference/derivedTypeDoesNotRequireExtendsClause.types +++ b/tests/baselines/reference/derivedTypeDoesNotRequireExtendsClause.types @@ -49,7 +49,7 @@ b = d2; var r: Base[] = [d1, d2]; >r : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived >d2 : Derived2 diff --git a/tests/baselines/reference/doNotWidenAtObjectLiteralPropertyAssignment.types b/tests/baselines/reference/doNotWidenAtObjectLiteralPropertyAssignment.types index 225bca8de63..cd8c03fd6a6 100644 --- a/tests/baselines/reference/doNotWidenAtObjectLiteralPropertyAssignment.types +++ b/tests/baselines/reference/doNotWidenAtObjectLiteralPropertyAssignment.types @@ -21,7 +21,7 @@ interface IIntervalTreeNode { var test: IIntervalTreeNode[] = [{ interval: { begin: 0 }, children: null }]; // was error here because best common type is {} >test : IIntervalTreeNode[] >IIntervalTreeNode : IIntervalTreeNode ->[{ interval: { begin: 0 }, children: null }] : IIntervalTreeNode[] +>[{ interval: { begin: 0 }, children: null }] : { interval: { begin: number; }; children: null; }[] >{ interval: { begin: 0 }, children: null } : { interval: { begin: number; }; children: null; } >interval : { begin: number; } >{ begin: 0 } : { begin: number; } diff --git a/tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types b/tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types index fefa692b509..991d324e822 100644 --- a/tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types +++ b/tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types @@ -25,7 +25,7 @@ var moduleMap: { [key: string]: IHasVisualizationModel } = { >moduleMap : { [x: string]: IHasVisualizationModel; } >key : string >IHasVisualizationModel : IHasVisualizationModel ->{ "moduleA": moduleA, "moduleB": moduleB} : { [x: string]: IHasVisualizationModel; "moduleA": typeof moduleA; "moduleB": typeof moduleB; } +>{ "moduleA": moduleA, "moduleB": moduleB} : { [x: string]: typeof moduleA; "moduleA": typeof moduleA; "moduleB": typeof moduleB; } "moduleA": moduleA, >moduleA : typeof moduleA diff --git a/tests/baselines/reference/forStatementsMultipleValidDecl.types b/tests/baselines/reference/forStatementsMultipleValidDecl.types index 2f3bfd70cea..c2458a306c7 100644 --- a/tests/baselines/reference/forStatementsMultipleValidDecl.types +++ b/tests/baselines/reference/forStatementsMultipleValidDecl.types @@ -109,11 +109,11 @@ for (var a = ['a', 'b']; ;) { } for (var a = []; ;) { } >a : string[] >[] : string[] ->[] : string[] +>[] : undefined[] for (var a: string[] = []; ;) { } >a : string[] ->[] : string[] +>[] : undefined[] for (var a = new Array(); ;) { } >a : string[] diff --git a/tests/baselines/reference/functionCall3.types b/tests/baselines/reference/functionCall3.types index a9b8e46069c..ea47de3e6d9 100644 --- a/tests/baselines/reference/functionCall3.types +++ b/tests/baselines/reference/functionCall3.types @@ -1,7 +1,7 @@ === tests/cases/compiler/functionCall3.ts === function foo():any[]{return [1];} >foo : () => any[] ->[1] : any[] +>[1] : number[] var x = foo(); >x : any[] diff --git a/tests/baselines/reference/functionOverloads42.types b/tests/baselines/reference/functionOverloads42.types index dec6a041440..6641a28c87a 100644 --- a/tests/baselines/reference/functionOverloads42.types +++ b/tests/baselines/reference/functionOverloads42.types @@ -19,7 +19,7 @@ var x = foo([{a:'s'}]); >x : number >foo([{a:'s'}]) : number >foo : { (bar: { a: number; }[]): string; (bar: { a: any; }[]): number; } ->[{a:'s'}] : { a: any; }[] +>[{a:'s'}] : { a: string; }[] >{a:'s'} : { a: string; } >a : string diff --git a/tests/baselines/reference/functionSubtypingOfVarArgs2.types b/tests/baselines/reference/functionSubtypingOfVarArgs2.types index 2fef933594d..2f81898c7de 100644 --- a/tests/baselines/reference/functionSubtypingOfVarArgs2.types +++ b/tests/baselines/reference/functionSubtypingOfVarArgs2.types @@ -5,7 +5,7 @@ class EventBase { private _listeners: { (...args: any[]): void; }[] = []; >_listeners : { (...args: any[]): void; }[] >args : any[] ->[] : { (...args: any[]): void; }[] +>[] : undefined[] add(listener: (...args: any[]) => void): void { >add : (listener: (...args: any[]) => void) => void diff --git a/tests/baselines/reference/generatedContextualTyping.types b/tests/baselines/reference/generatedContextualTyping.types index 658d4a0bff1..78fc6f6cfef 100644 --- a/tests/baselines/reference/generatedContextualTyping.types +++ b/tests/baselines/reference/generatedContextualTyping.types @@ -34,57 +34,57 @@ var b = new Base(), d1 = new Derived1(), d2 = new Derived2(); var x1: () => Base[] = () => [d1, d2]; >x1 : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x2: () => Base[] = function() { return [d1, d2] }; >x2 : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x3: () => Base[] = function named() { return [d1, d2] }; >x3 : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x4: { (): Base[]; } = () => [d1, d2]; >x4 : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x5: { (): Base[]; } = function() { return [d1, d2] }; >x5 : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x6: { (): Base[]; } = function named() { return [d1, d2] }; >x6 : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x7: Base[] = [d1, d2]; >x7 : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -92,7 +92,7 @@ var x8: Array = [d1, d2]; >x8 : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -100,7 +100,7 @@ var x9: { [n: number]: Base; } = [d1, d2]; >x9 : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -108,9 +108,9 @@ var x10: {n: Base[]; } = { n: [d1, d2] }; >x10 : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -139,8 +139,8 @@ class x13 { member: () => Base[] = () => [d1, d2] } >x13 : x13 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -148,8 +148,8 @@ class x14 { member: () => Base[] = function() { return [d1, d2] } } >x14 : x14 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -157,9 +157,9 @@ class x15 { member: () => Base[] = function named() { return [d1, d2] } } >x15 : x15 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -167,8 +167,8 @@ class x16 { member: { (): Base[]; } = () => [d1, d2] } >x16 : x16 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -176,8 +176,8 @@ class x17 { member: { (): Base[]; } = function() { return [d1, d2] } } >x17 : x17 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -185,9 +185,9 @@ class x18 { member: { (): Base[]; } = function named() { return [d1, d2] } } >x18 : x18 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -195,7 +195,7 @@ class x19 { member: Base[] = [d1, d2] } >x19 : x19 >member : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -204,7 +204,7 @@ class x20 { member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -213,7 +213,7 @@ class x21 { member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -222,9 +222,9 @@ class x22 { member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -255,8 +255,8 @@ class x25 { private member: () => Base[] = () => [d1, d2] } >x25 : x25 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -264,8 +264,8 @@ class x26 { private member: () => Base[] = function() { return [d1, d2] } } >x26 : x26 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -273,9 +273,9 @@ class x27 { private member: () => Base[] = function named() { return [d1, d2] } >x27 : x27 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -283,8 +283,8 @@ class x28 { private member: { (): Base[]; } = () => [d1, d2] } >x28 : x28 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -292,8 +292,8 @@ class x29 { private member: { (): Base[]; } = function() { return [d1, d2] } } >x29 : x29 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -301,9 +301,9 @@ class x30 { private member: { (): Base[]; } = function named() { return [d1, d2] >x30 : x30 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -311,7 +311,7 @@ class x31 { private member: Base[] = [d1, d2] } >x31 : x31 >member : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -320,7 +320,7 @@ class x32 { private member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -329,7 +329,7 @@ class x33 { private member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -338,9 +338,9 @@ class x34 { private member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -371,8 +371,8 @@ class x37 { public member: () => Base[] = () => [d1, d2] } >x37 : x37 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -380,8 +380,8 @@ class x38 { public member: () => Base[] = function() { return [d1, d2] } } >x38 : x38 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -389,9 +389,9 @@ class x39 { public member: () => Base[] = function named() { return [d1, d2] } } >x39 : x39 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -399,8 +399,8 @@ class x40 { public member: { (): Base[]; } = () => [d1, d2] } >x40 : x40 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -408,8 +408,8 @@ class x41 { public member: { (): Base[]; } = function() { return [d1, d2] } } >x41 : x41 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -417,9 +417,9 @@ class x42 { public member: { (): Base[]; } = function named() { return [d1, d2] >x42 : x42 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -427,7 +427,7 @@ class x43 { public member: Base[] = [d1, d2] } >x43 : x43 >member : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -436,7 +436,7 @@ class x44 { public member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -445,7 +445,7 @@ class x45 { public member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -454,9 +454,9 @@ class x46 { public member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -487,8 +487,8 @@ class x49 { static member: () => Base[] = () => [d1, d2] } >x49 : x49 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -496,8 +496,8 @@ class x50 { static member: () => Base[] = function() { return [d1, d2] } } >x50 : x50 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -505,9 +505,9 @@ class x51 { static member: () => Base[] = function named() { return [d1, d2] } } >x51 : x51 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -515,8 +515,8 @@ class x52 { static member: { (): Base[]; } = () => [d1, d2] } >x52 : x52 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -524,8 +524,8 @@ class x53 { static member: { (): Base[]; } = function() { return [d1, d2] } } >x53 : x53 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -533,9 +533,9 @@ class x54 { static member: { (): Base[]; } = function named() { return [d1, d2] >x54 : x54 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -543,7 +543,7 @@ class x55 { static member: Base[] = [d1, d2] } >x55 : x55 >member : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -552,7 +552,7 @@ class x56 { static member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -561,7 +561,7 @@ class x57 { static member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -570,9 +570,9 @@ class x58 { static member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -603,8 +603,8 @@ class x61 { private static member: () => Base[] = () => [d1, d2] } >x61 : x61 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -612,8 +612,8 @@ class x62 { private static member: () => Base[] = function() { return [d1, d2] } >x62 : x62 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -621,9 +621,9 @@ class x63 { private static member: () => Base[] = function named() { return [d1, >x63 : x63 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -631,8 +631,8 @@ class x64 { private static member: { (): Base[]; } = () => [d1, d2] } >x64 : x64 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -640,8 +640,8 @@ class x65 { private static member: { (): Base[]; } = function() { return [d1, d2 >x65 : x65 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -649,9 +649,9 @@ class x66 { private static member: { (): Base[]; } = function named() { return [ >x66 : x66 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -659,7 +659,7 @@ class x67 { private static member: Base[] = [d1, d2] } >x67 : x67 >member : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -668,7 +668,7 @@ class x68 { private static member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -677,7 +677,7 @@ class x69 { private static member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -686,9 +686,9 @@ class x70 { private static member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -719,8 +719,8 @@ class x73 { public static member: () => Base[] = () => [d1, d2] } >x73 : x73 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -728,8 +728,8 @@ class x74 { public static member: () => Base[] = function() { return [d1, d2] } >x74 : x74 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -737,9 +737,9 @@ class x75 { public static member: () => Base[] = function named() { return [d1, >x75 : x75 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -747,8 +747,8 @@ class x76 { public static member: { (): Base[]; } = () => [d1, d2] } >x76 : x76 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -756,8 +756,8 @@ class x77 { public static member: { (): Base[]; } = function() { return [d1, d2] >x77 : x77 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -765,9 +765,9 @@ class x78 { public static member: { (): Base[]; } = function named() { return [d >x78 : x78 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -775,7 +775,7 @@ class x79 { public static member: Base[] = [d1, d2] } >x79 : x79 >member : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -784,7 +784,7 @@ class x80 { public static member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -793,7 +793,7 @@ class x81 { public static member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -802,9 +802,9 @@ class x82 { public static member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -835,8 +835,8 @@ class x85 { constructor(parm: () => Base[] = () => [d1, d2]) { } } >x85 : x85 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -844,8 +844,8 @@ class x86 { constructor(parm: () => Base[] = function() { return [d1, d2] }) { } >x86 : x86 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -853,9 +853,9 @@ class x87 { constructor(parm: () => Base[] = function named() { return [d1, d2] >x87 : x87 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -863,8 +863,8 @@ class x88 { constructor(parm: { (): Base[]; } = () => [d1, d2]) { } } >x88 : x88 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -872,8 +872,8 @@ class x89 { constructor(parm: { (): Base[]; } = function() { return [d1, d2] }) >x89 : x89 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -881,9 +881,9 @@ class x90 { constructor(parm: { (): Base[]; } = function named() { return [d1, d >x90 : x90 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -891,7 +891,7 @@ class x91 { constructor(parm: Base[] = [d1, d2]) { } } >x91 : x91 >parm : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -900,7 +900,7 @@ class x92 { constructor(parm: Array = [d1, d2]) { } } >parm : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -909,7 +909,7 @@ class x93 { constructor(parm: { [n: number]: Base; } = [d1, d2]) { } } >parm : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -918,9 +918,9 @@ class x94 { constructor(parm: {n: Base[]; } = { n: [d1, d2] }) { } } >parm : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -951,8 +951,8 @@ class x97 { constructor(public parm: () => Base[] = () => [d1, d2]) { } } >x97 : x97 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -960,8 +960,8 @@ class x98 { constructor(public parm: () => Base[] = function() { return [d1, d2] >x98 : x98 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -969,9 +969,9 @@ class x99 { constructor(public parm: () => Base[] = function named() { return [d >x99 : x99 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -979,8 +979,8 @@ class x100 { constructor(public parm: { (): Base[]; } = () => [d1, d2]) { } } >x100 : x100 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -988,8 +988,8 @@ class x101 { constructor(public parm: { (): Base[]; } = function() { return [d1, >x101 : x101 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -997,9 +997,9 @@ class x102 { constructor(public parm: { (): Base[]; } = function named() { retur >x102 : x102 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1007,7 +1007,7 @@ class x103 { constructor(public parm: Base[] = [d1, d2]) { } } >x103 : x103 >parm : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1016,7 +1016,7 @@ class x104 { constructor(public parm: Array = [d1, d2]) { } } >parm : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1025,7 +1025,7 @@ class x105 { constructor(public parm: { [n: number]: Base; } = [d1, d2]) { } } >parm : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1034,9 +1034,9 @@ class x106 { constructor(public parm: {n: Base[]; } = { n: [d1, d2] }) { } } >parm : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1067,8 +1067,8 @@ class x109 { constructor(private parm: () => Base[] = () => [d1, d2]) { } } >x109 : x109 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1076,8 +1076,8 @@ class x110 { constructor(private parm: () => Base[] = function() { return [d1, d >x110 : x110 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1085,9 +1085,9 @@ class x111 { constructor(private parm: () => Base[] = function named() { return >x111 : x111 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1095,8 +1095,8 @@ class x112 { constructor(private parm: { (): Base[]; } = () => [d1, d2]) { } } >x112 : x112 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1104,8 +1104,8 @@ class x113 { constructor(private parm: { (): Base[]; } = function() { return [d1 >x113 : x113 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1113,9 +1113,9 @@ class x114 { constructor(private parm: { (): Base[]; } = function named() { retu >x114 : x114 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1123,7 +1123,7 @@ class x115 { constructor(private parm: Base[] = [d1, d2]) { } } >x115 : x115 >parm : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1132,7 +1132,7 @@ class x116 { constructor(private parm: Array = [d1, d2]) { } } >parm : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1141,7 +1141,7 @@ class x117 { constructor(private parm: { [n: number]: Base; } = [d1, d2]) { } } >parm : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1150,9 +1150,9 @@ class x118 { constructor(private parm: {n: Base[]; } = { n: [d1, d2] }) { } } >parm : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1183,8 +1183,8 @@ function x121(parm: () => Base[] = () => [d1, d2]) { } >x121 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1192,8 +1192,8 @@ function x122(parm: () => Base[] = function() { return [d1, d2] }) { } >x122 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1201,9 +1201,9 @@ function x123(parm: () => Base[] = function named() { return [d1, d2] }) { } >x123 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1211,8 +1211,8 @@ function x124(parm: { (): Base[]; } = () => [d1, d2]) { } >x124 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1220,8 +1220,8 @@ function x125(parm: { (): Base[]; } = function() { return [d1, d2] }) { } >x125 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1229,9 +1229,9 @@ function x126(parm: { (): Base[]; } = function named() { return [d1, d2] }) { } >x126 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1239,7 +1239,7 @@ function x127(parm: Base[] = [d1, d2]) { } >x127 : (parm?: Base[]) => void >parm : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1248,7 +1248,7 @@ function x128(parm: Array = [d1, d2]) { } >parm : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1257,7 +1257,7 @@ function x129(parm: { [n: number]: Base; } = [d1, d2]) { } >parm : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1266,9 +1266,9 @@ function x130(parm: {n: Base[]; } = { n: [d1, d2] }) { } >parm : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1298,57 +1298,57 @@ function x132(parm: Genric = { func: n => { return [d1, d2]; } }) { } function x133(): () => Base[] { return () => [d1, d2]; } >x133 : () => () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 function x134(): () => Base[] { return function() { return [d1, d2] }; } >x134 : () => () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 function x135(): () => Base[] { return function named() { return [d1, d2] }; } >x135 : () => () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 function x136(): { (): Base[]; } { return () => [d1, d2]; } >x136 : () => () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 function x137(): { (): Base[]; } { return function() { return [d1, d2] }; } >x137 : () => () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 function x138(): { (): Base[]; } { return function named() { return [d1, d2] }; } >x138 : () => () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 function x139(): Base[] { return [d1, d2]; } >x139 : () => Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1356,7 +1356,7 @@ function x140(): Array { return [d1, d2]; } >x140 : () => Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1364,7 +1364,7 @@ function x141(): { [n: number]: Base; } { return [d1, d2]; } >x141 : () => { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1372,9 +1372,9 @@ function x142(): {n: Base[]; } { return { n: [d1, d2] }; } >x142 : () => { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1402,86 +1402,86 @@ function x144(): Genric { return { func: n => { return [d1, d2]; } }; } function x145(): () => Base[] { return () => [d1, d2]; return () => [d1, d2]; } >x145 : () => () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 function x146(): () => Base[] { return function() { return [d1, d2] }; return function() { return [d1, d2] }; } >x146 : () => () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 function x147(): () => Base[] { return function named() { return [d1, d2] }; return function named() { return [d1, d2] }; } >x147 : () => () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 function x148(): { (): Base[]; } { return () => [d1, d2]; return () => [d1, d2]; } >x148 : () => () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 function x149(): { (): Base[]; } { return function() { return [d1, d2] }; return function() { return [d1, d2] }; } >x149 : () => () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 function x150(): { (): Base[]; } { return function named() { return [d1, d2] }; return function named() { return [d1, d2] }; } >x150 : () => () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 function x151(): Base[] { return [d1, d2]; return [d1, d2]; } >x151 : () => Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1489,10 +1489,10 @@ function x152(): Array { return [d1, d2]; return [d1, d2]; } >x152 : () => Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1500,10 +1500,10 @@ function x153(): { [n: number]: Base; } { return [d1, d2]; return [d1, d2]; } >x153 : () => { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1511,14 +1511,14 @@ function x154(): {n: Base[]; } { return { n: [d1, d2] }; return { n: [d1, d2] } >x154 : () => { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1557,64 +1557,64 @@ function x156(): Genric { return { func: n => { return [d1, d2]; } }; retu var x157: () => () => Base[] = () => { return () => [d1, d2]; }; >x157 : () => () => Base[] >Base : Base ->() => { return () => [d1, d2]; } : () => () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => { return () => [d1, d2]; } : () => () => Array +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x158: () => () => Base[] = () => { return function() { return [d1, d2] }; }; >x158 : () => () => Base[] >Base : Base ->() => { return function() { return [d1, d2] }; } : () => () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>() => { return function() { return [d1, d2] }; } : () => () => Array +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x159: () => () => Base[] = () => { return function named() { return [d1, d2] }; }; >x159 : () => () => Base[] >Base : Base ->() => { return function named() { return [d1, d2] }; } : () => () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>() => { return function named() { return [d1, d2] }; } : () => () => Array +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x160: () => { (): Base[]; } = () => { return () => [d1, d2]; }; >x160 : () => () => Base[] >Base : Base ->() => { return () => [d1, d2]; } : () => () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => { return () => [d1, d2]; } : () => () => Array +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x161: () => { (): Base[]; } = () => { return function() { return [d1, d2] }; }; >x161 : () => () => Base[] >Base : Base ->() => { return function() { return [d1, d2] }; } : () => () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>() => { return function() { return [d1, d2] }; } : () => () => Array +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x162: () => { (): Base[]; } = () => { return function named() { return [d1, d2] }; }; >x162 : () => () => Base[] >Base : Base ->() => { return function named() { return [d1, d2] }; } : () => () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>() => { return function named() { return [d1, d2] }; } : () => () => Array +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x163: () => Base[] = () => { return [d1, d2]; }; >x163 : () => Base[] >Base : Base ->() => { return [d1, d2]; } : () => Base[] ->[d1, d2] : Base[] +>() => { return [d1, d2]; } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1622,8 +1622,8 @@ var x164: () => Array = () => { return [d1, d2]; }; >x164 : () => Base[] >Array : T[] >Base : Base ->() => { return [d1, d2]; } : () => Base[] ->[d1, d2] : Base[] +>() => { return [d1, d2]; } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1631,8 +1631,8 @@ var x165: () => { [n: number]: Base; } = () => { return [d1, d2]; }; >x165 : () => { [x: number]: Base; } >n : number >Base : Base ->() => { return [d1, d2]; } : () => Base[] ->[d1, d2] : Base[] +>() => { return [d1, d2]; } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1640,10 +1640,10 @@ var x166: () => {n: Base[]; } = () => { return { n: [d1, d2] }; }; >x166 : () => { n: Base[]; } >n : Base[] >Base : Base ->() => { return { n: [d1, d2] }; } : () => { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>() => { return { n: [d1, d2] }; } : () => { n: Array; } +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1673,64 +1673,64 @@ var x168: () => Genric = () => { return { func: n => { return [d1, d2]; } var x169: () => () => Base[] = function() { return () => [d1, d2]; }; >x169 : () => () => Base[] >Base : Base ->function() { return () => [d1, d2]; } : () => () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>function() { return () => [d1, d2]; } : () => () => Array +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x170: () => () => Base[] = function() { return function() { return [d1, d2] }; }; >x170 : () => () => Base[] >Base : Base ->function() { return function() { return [d1, d2] }; } : () => () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return function() { return [d1, d2] }; } : () => () => Array +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x171: () => () => Base[] = function() { return function named() { return [d1, d2] }; }; >x171 : () => () => Base[] >Base : Base ->function() { return function named() { return [d1, d2] }; } : () => () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function() { return function named() { return [d1, d2] }; } : () => () => Array +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x172: () => { (): Base[]; } = function() { return () => [d1, d2]; }; >x172 : () => () => Base[] >Base : Base ->function() { return () => [d1, d2]; } : () => () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>function() { return () => [d1, d2]; } : () => () => Array +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x173: () => { (): Base[]; } = function() { return function() { return [d1, d2] }; }; >x173 : () => () => Base[] >Base : Base ->function() { return function() { return [d1, d2] }; } : () => () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return function() { return [d1, d2] }; } : () => () => Array +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x174: () => { (): Base[]; } = function() { return function named() { return [d1, d2] }; }; >x174 : () => () => Base[] >Base : Base ->function() { return function named() { return [d1, d2] }; } : () => () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function() { return function named() { return [d1, d2] }; } : () => () => Array +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x175: () => Base[] = function() { return [d1, d2]; }; >x175 : () => Base[] >Base : Base ->function() { return [d1, d2]; } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2]; } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1738,8 +1738,8 @@ var x176: () => Array = function() { return [d1, d2]; }; >x176 : () => Base[] >Array : T[] >Base : Base ->function() { return [d1, d2]; } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2]; } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1747,8 +1747,8 @@ var x177: () => { [n: number]: Base; } = function() { return [d1, d2]; }; >x177 : () => { [x: number]: Base; } >n : number >Base : Base ->function() { return [d1, d2]; } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2]; } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1756,10 +1756,10 @@ var x178: () => {n: Base[]; } = function() { return { n: [d1, d2] }; }; >x178 : () => { n: Base[]; } >n : Base[] >Base : Base ->function() { return { n: [d1, d2] }; } : () => { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>function() { return { n: [d1, d2] }; } : () => { n: Array; } +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1790,8 +1790,8 @@ module x181 { var t: () => Base[] = () => [d1, d2]; } >x181 : typeof x181 >t : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1799,8 +1799,8 @@ module x182 { var t: () => Base[] = function() { return [d1, d2] }; } >x182 : typeof x182 >t : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1808,9 +1808,9 @@ module x183 { var t: () => Base[] = function named() { return [d1, d2] }; } >x183 : typeof x183 >t : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1818,8 +1818,8 @@ module x184 { var t: { (): Base[]; } = () => [d1, d2]; } >x184 : typeof x184 >t : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1827,8 +1827,8 @@ module x185 { var t: { (): Base[]; } = function() { return [d1, d2] }; } >x185 : typeof x185 >t : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1836,9 +1836,9 @@ module x186 { var t: { (): Base[]; } = function named() { return [d1, d2] }; } >x186 : typeof x186 >t : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1846,7 +1846,7 @@ module x187 { var t: Base[] = [d1, d2]; } >x187 : typeof x187 >t : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1855,7 +1855,7 @@ module x188 { var t: Array = [d1, d2]; } >t : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1864,7 +1864,7 @@ module x189 { var t: { [n: number]: Base; } = [d1, d2]; } >t : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1873,9 +1873,9 @@ module x190 { var t: {n: Base[]; } = { n: [d1, d2] }; } >t : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1906,8 +1906,8 @@ module x193 { export var t: () => Base[] = () => [d1, d2]; } >x193 : typeof x193 >t : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1915,8 +1915,8 @@ module x194 { export var t: () => Base[] = function() { return [d1, d2] }; } >x194 : typeof x194 >t : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1924,9 +1924,9 @@ module x195 { export var t: () => Base[] = function named() { return [d1, d2] }; >x195 : typeof x195 >t : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1934,8 +1934,8 @@ module x196 { export var t: { (): Base[]; } = () => [d1, d2]; } >x196 : typeof x196 >t : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1943,8 +1943,8 @@ module x197 { export var t: { (): Base[]; } = function() { return [d1, d2] }; } >x197 : typeof x197 >t : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1952,9 +1952,9 @@ module x198 { export var t: { (): Base[]; } = function named() { return [d1, d2] >x198 : typeof x198 >t : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1962,7 +1962,7 @@ module x199 { export var t: Base[] = [d1, d2]; } >x199 : typeof x199 >t : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1971,7 +1971,7 @@ module x200 { export var t: Array = [d1, d2]; } >t : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1980,7 +1980,7 @@ module x201 { export var t: { [n: number]: Base; } = [d1, d2]; } >t : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -1989,9 +1989,9 @@ module x202 { export var t: {n: Base[]; } = { n: [d1, d2] }; } >t : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2022,8 +2022,8 @@ var x206 = <() => Base[]>function() { return [d1, d2] }; >x206 : () => Base[] ><() => Base[]>function() { return [d1, d2] } : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2031,9 +2031,9 @@ var x207 = <() => Base[]>function named() { return [d1, d2] }; >x207 : () => Base[] ><() => Base[]>function named() { return [d1, d2] } : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2041,8 +2041,8 @@ var x209 = <{ (): Base[]; }>function() { return [d1, d2] }; >x209 : () => Base[] ><{ (): Base[]; }>function() { return [d1, d2] } : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2050,9 +2050,9 @@ var x210 = <{ (): Base[]; }>function named() { return [d1, d2] }; >x210 : () => Base[] ><{ (): Base[]; }>function named() { return [d1, d2] } : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2060,7 +2060,7 @@ var x211 = [d1, d2]; >x211 : Base[] >[d1, d2] : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2069,7 +2069,7 @@ var x212 = >[d1, d2]; >>[d1, d2] : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2078,7 +2078,7 @@ var x213 = <{ [n: number]: Base; }>[d1, d2]; ><{ [n: number]: Base; }>[d1, d2] : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2087,9 +2087,9 @@ var x214 = <{n: Base[]; } >{ n: [d1, d2] }; ><{n: Base[]; } >{ n: [d1, d2] } : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2113,8 +2113,8 @@ var x217 = (<() => Base[]>undefined) || function() { return [d1, d2] }; ><() => Base[]>undefined : () => Base[] >Base : Base >undefined : undefined ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2125,9 +2125,9 @@ var x218 = (<() => Base[]>undefined) || function named() { return [d1, d2] }; ><() => Base[]>undefined : () => Base[] >Base : Base >undefined : undefined ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2138,8 +2138,8 @@ var x219 = (<{ (): Base[]; }>undefined) || function() { return [d1, d2] }; ><{ (): Base[]; }>undefined : () => Base[] >Base : Base >undefined : undefined ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2150,9 +2150,9 @@ var x220 = (<{ (): Base[]; }>undefined) || function named() { return [d1, d2] }; ><{ (): Base[]; }>undefined : () => Base[] >Base : Base >undefined : undefined ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2163,7 +2163,7 @@ var x221 = (undefined) || [d1, d2]; >undefined : Base[] >Base : Base >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2175,7 +2175,7 @@ var x222 = (>undefined) || [d1, d2]; >Array : T[] >Base : Base >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2187,7 +2187,7 @@ var x223 = (<{ [n: number]: Base; }>undefined) || [d1, d2]; >n : number >Base : Base >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2199,80 +2199,80 @@ var x224 = (<{n: Base[]; } >undefined) || { n: [d1, d2] }; >n : Base[] >Base : Base >undefined : undefined ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x225: () => Base[]; x225 = () => [d1, d2]; >x225 : () => Base[] >Base : Base ->x225 = () => [d1, d2] : () => Base[] +>x225 = () => [d1, d2] : () => Array >x225 : () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x226: () => Base[]; x226 = function() { return [d1, d2] }; >x226 : () => Base[] >Base : Base ->x226 = function() { return [d1, d2] } : () => Base[] +>x226 = function() { return [d1, d2] } : () => Array >x226 : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x227: () => Base[]; x227 = function named() { return [d1, d2] }; >x227 : () => Base[] >Base : Base ->x227 = function named() { return [d1, d2] } : () => Base[] +>x227 = function named() { return [d1, d2] } : () => Array >x227 : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x228: { (): Base[]; }; x228 = () => [d1, d2]; >x228 : () => Base[] >Base : Base ->x228 = () => [d1, d2] : () => Base[] +>x228 = () => [d1, d2] : () => Array >x228 : () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x229: { (): Base[]; }; x229 = function() { return [d1, d2] }; >x229 : () => Base[] >Base : Base ->x229 = function() { return [d1, d2] } : () => Base[] +>x229 = function() { return [d1, d2] } : () => Array >x229 : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x230: { (): Base[]; }; x230 = function named() { return [d1, d2] }; >x230 : () => Base[] >Base : Base ->x230 = function named() { return [d1, d2] } : () => Base[] +>x230 = function named() { return [d1, d2] } : () => Array >x230 : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x231: Base[]; x231 = [d1, d2]; >x231 : Base[] >Base : Base ->x231 = [d1, d2] : Base[] +>x231 = [d1, d2] : Array >x231 : Base[] ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2280,9 +2280,9 @@ var x232: Array; x232 = [d1, d2]; >x232 : Base[] >Array : T[] >Base : Base ->x232 = [d1, d2] : Base[] +>x232 = [d1, d2] : Array >x232 : Base[] ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2290,9 +2290,9 @@ var x233: { [n: number]: Base; }; x233 = [d1, d2]; >x233 : { [x: number]: Base; } >n : number >Base : Base ->x233 = [d1, d2] : Base[] +>x233 = [d1, d2] : Array >x233 : { [x: number]: Base; } ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2300,11 +2300,11 @@ var x234: {n: Base[]; } ; x234 = { n: [d1, d2] }; >x234 : { n: Base[]; } >n : Base[] >Base : Base ->x234 = { n: [d1, d2] } : { n: Base[]; } +>x234 = { n: [d1, d2] } : { n: Array; } >x234 : { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2337,10 +2337,10 @@ var x237: { n: () => Base[]; } = { n: () => [d1, d2] }; >x237 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: () => [d1, d2] } : { n: () => Base[]; } ->n : () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>{ n: () => [d1, d2] } : { n: () => Array; } +>n : () => Array +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2348,10 +2348,10 @@ var x238: { n: () => Base[]; } = { n: function() { return [d1, d2] } }; >x238 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: function() { return [d1, d2] } } : { n: () => Base[]; } ->n : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>{ n: function() { return [d1, d2] } } : { n: () => Array; } +>n : () => Array +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2359,11 +2359,11 @@ var x239: { n: () => Base[]; } = { n: function named() { return [d1, d2] } }; >x239 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: function named() { return [d1, d2] } } : { n: () => Base[]; } ->n : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>{ n: function named() { return [d1, d2] } } : { n: () => Array; } +>n : () => Array +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2371,10 +2371,10 @@ var x240: { n: { (): Base[]; }; } = { n: () => [d1, d2] }; >x240 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: () => [d1, d2] } : { n: () => Base[]; } ->n : () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>{ n: () => [d1, d2] } : { n: () => Array; } +>n : () => Array +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2382,10 +2382,10 @@ var x241: { n: { (): Base[]; }; } = { n: function() { return [d1, d2] } }; >x241 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: function() { return [d1, d2] } } : { n: () => Base[]; } ->n : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>{ n: function() { return [d1, d2] } } : { n: () => Array; } +>n : () => Array +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2393,11 +2393,11 @@ var x242: { n: { (): Base[]; }; } = { n: function named() { return [d1, d2] } }; >x242 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: function named() { return [d1, d2] } } : { n: () => Base[]; } ->n : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>{ n: function named() { return [d1, d2] } } : { n: () => Array; } +>n : () => Array +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2405,9 +2405,9 @@ var x243: { n: Base[]; } = { n: [d1, d2] }; >x243 : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2416,9 +2416,9 @@ var x244: { n: Array; } = { n: [d1, d2] }; >n : Base[] >Array : T[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2427,9 +2427,9 @@ var x245: { n: { [n: number]: Base; }; } = { n: [d1, d2] }; >n : { [x: number]: Base; } >n : number >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2438,11 +2438,11 @@ var x246: { n: {n: Base[]; } ; } = { n: { n: [d1, d2] } }; >n : { n: Base[]; } >n : Base[] >Base : Base ->{ n: { n: [d1, d2] } } : { n: { n: Base[]; }; } ->n : { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: { n: [d1, d2] } } : { n: { n: Array; }; } +>n : { n: Array; } +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2476,36 +2476,36 @@ var x248: { n: Genric; } = { n: { func: n => { return [d1, d2]; } } }; var x252: { (): Base[]; }[] = [() => [d1, d2]]; >x252 : { (): Base[]; }[] >Base : Base ->[() => [d1, d2]] : { (): Base[]; }[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>[() => [d1, d2]] : { (): Array; }[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x253: { (): Base[]; }[] = [function() { return [d1, d2] }]; >x253 : { (): Base[]; }[] >Base : Base ->[function() { return [d1, d2] }] : { (): Base[]; }[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>[function() { return [d1, d2] }] : { (): Array; }[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x254: { (): Base[]; }[] = [function named() { return [d1, d2] }]; >x254 : { (): Base[]; }[] >Base : Base ->[function named() { return [d1, d2] }] : { (): Base[]; }[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>[function named() { return [d1, d2] }] : { (): Array; }[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x255: Base[][] = [[d1, d2]]; >x255 : Base[][] >Base : Base ->[[d1, d2]] : Base[][] ->[d1, d2] : Base[] +>[[d1, d2]] : Array[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2513,8 +2513,8 @@ var x256: Array[] = [[d1, d2]]; >x256 : Base[][] >Array : T[] >Base : Base ->[[d1, d2]] : Base[][] ->[d1, d2] : Base[] +>[[d1, d2]] : Array[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2522,8 +2522,8 @@ var x257: { [n: number]: Base; }[] = [[d1, d2]]; >x257 : { [x: number]: Base; }[] >n : number >Base : Base ->[[d1, d2]] : { [x: number]: Base; }[] ->[d1, d2] : Base[] +>[[d1, d2]] : Array[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2531,10 +2531,10 @@ var x258: {n: Base[]; } [] = [{ n: [d1, d2] }]; >x258 : { n: Base[]; }[] >n : Base[] >Base : Base ->[{ n: [d1, d2] }] : { n: Base[]; }[] ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>[{ n: [d1, d2] }] : { n: Array; }[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2542,7 +2542,7 @@ var x260: Genric[] = [{ func: n => { return [d1, d2]; } }]; >x260 : Genric[] >Genric : Genric >Base : Base ->[{ func: n => { return [d1, d2]; } }] : Genric[] +>[{ func: n => { return [d1, d2]; } }] : { func: (n: Base[]) => Array; }[] >{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } >func : (n: Base[]) => Array >n => { return [d1, d2]; } : (n: Base[]) => Array @@ -2554,9 +2554,9 @@ var x260: Genric[] = [{ func: n => { return [d1, d2]; } }]; var x261: () => Base[] = function() { return [d1, d2] } || undefined; >x261 : () => Base[] >Base : Base ->function() { return [d1, d2] } || undefined : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } || undefined : () => Array +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2564,10 +2564,10 @@ var x261: () => Base[] = function() { return [d1, d2] } || undefined; var x262: () => Base[] = function named() { return [d1, d2] } || undefined; >x262 : () => Base[] >Base : Base ->function named() { return [d1, d2] } || undefined : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } || undefined : () => Array +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2575,9 +2575,9 @@ var x262: () => Base[] = function named() { return [d1, d2] } || undefined; var x263: { (): Base[]; } = function() { return [d1, d2] } || undefined; >x263 : () => Base[] >Base : Base ->function() { return [d1, d2] } || undefined : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } || undefined : () => Array +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2585,10 +2585,10 @@ var x263: { (): Base[]; } = function() { return [d1, d2] } || undefined; var x264: { (): Base[]; } = function named() { return [d1, d2] } || undefined; >x264 : () => Base[] >Base : Base ->function named() { return [d1, d2] } || undefined : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } || undefined : () => Array +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2596,8 +2596,8 @@ var x264: { (): Base[]; } = function named() { return [d1, d2] } || undefined; var x265: Base[] = [d1, d2] || undefined; >x265 : Base[] >Base : Base ->[d1, d2] || undefined : Base[] ->[d1, d2] : Base[] +>[d1, d2] || undefined : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2606,8 +2606,8 @@ var x266: Array = [d1, d2] || undefined; >x266 : Base[] >Array : T[] >Base : Base ->[d1, d2] || undefined : Base[] ->[d1, d2] : Base[] +>[d1, d2] || undefined : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2616,8 +2616,8 @@ var x267: { [n: number]: Base; } = [d1, d2] || undefined; >x267 : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] || undefined : Base[] ->[d1, d2] : Base[] +>[d1, d2] || undefined : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2626,10 +2626,10 @@ var x268: {n: Base[]; } = { n: [d1, d2] } || undefined; >x268 : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } || undefined : { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } || undefined : { n: Array; } +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2637,51 +2637,51 @@ var x268: {n: Base[]; } = { n: [d1, d2] } || undefined; var x269: () => Base[] = undefined || function() { return [d1, d2] }; >x269 : () => Base[] >Base : Base ->undefined || function() { return [d1, d2] } : () => Base[] +>undefined || function() { return [d1, d2] } : () => Array >undefined : undefined ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x270: () => Base[] = undefined || function named() { return [d1, d2] }; >x270 : () => Base[] >Base : Base ->undefined || function named() { return [d1, d2] } : () => Base[] +>undefined || function named() { return [d1, d2] } : () => Array >undefined : undefined ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x271: { (): Base[]; } = undefined || function() { return [d1, d2] }; >x271 : () => Base[] >Base : Base ->undefined || function() { return [d1, d2] } : () => Base[] +>undefined || function() { return [d1, d2] } : () => Array >undefined : undefined ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x272: { (): Base[]; } = undefined || function named() { return [d1, d2] }; >x272 : () => Base[] >Base : Base ->undefined || function named() { return [d1, d2] } : () => Base[] +>undefined || function named() { return [d1, d2] } : () => Array >undefined : undefined ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x273: Base[] = undefined || [d1, d2]; >x273 : Base[] >Base : Base ->undefined || [d1, d2] : Base[] +>undefined || [d1, d2] : Array >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2689,9 +2689,9 @@ var x274: Array = undefined || [d1, d2]; >x274 : Base[] >Array : T[] >Base : Base ->undefined || [d1, d2] : Base[] +>undefined || [d1, d2] : Array >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2699,9 +2699,9 @@ var x275: { [n: number]: Base; } = undefined || [d1, d2]; >x275 : { [x: number]: Base; } >n : number >Base : Base ->undefined || [d1, d2] : Base[] +>undefined || [d1, d2] : Array >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2709,78 +2709,78 @@ var x276: {n: Base[]; } = undefined || { n: [d1, d2] }; >x276 : { n: Base[]; } >n : Base[] >Base : Base ->undefined || { n: [d1, d2] } : { n: Base[]; } +>undefined || { n: [d1, d2] } : { n: Array; } >undefined : undefined ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x277: () => Base[] = function() { return [d1, d2] } || function() { return [d1, d2] }; >x277 : () => Base[] >Base : Base ->function() { return [d1, d2] } || function() { return [d1, d2] } : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } || function() { return [d1, d2] } : () => Array +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x278: () => Base[] = function named() { return [d1, d2] } || function named() { return [d1, d2] }; >x278 : () => Base[] >Base : Base ->function named() { return [d1, d2] } || function named() { return [d1, d2] } : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } || function named() { return [d1, d2] } : () => Array +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x279: { (): Base[]; } = function() { return [d1, d2] } || function() { return [d1, d2] }; >x279 : () => Base[] >Base : Base ->function() { return [d1, d2] } || function() { return [d1, d2] } : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } || function() { return [d1, d2] } : () => Array +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x280: { (): Base[]; } = function named() { return [d1, d2] } || function named() { return [d1, d2] }; >x280 : () => Base[] >Base : Base ->function named() { return [d1, d2] } || function named() { return [d1, d2] } : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } || function named() { return [d1, d2] } : () => Array +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x281: Base[] = [d1, d2] || [d1, d2]; >x281 : Base[] >Base : Base ->[d1, d2] || [d1, d2] : Base[] ->[d1, d2] : Base[] +>[d1, d2] || [d1, d2] : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2788,11 +2788,11 @@ var x282: Array = [d1, d2] || [d1, d2]; >x282 : Base[] >Array : T[] >Base : Base ->[d1, d2] || [d1, d2] : Base[] ->[d1, d2] : Base[] +>[d1, d2] || [d1, d2] : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2800,11 +2800,11 @@ var x283: { [n: number]: Base; } = [d1, d2] || [d1, d2]; >x283 : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] || [d1, d2] : Base[] ->[d1, d2] : Base[] +>[d1, d2] || [d1, d2] : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2812,108 +2812,108 @@ var x284: {n: Base[]; } = { n: [d1, d2] } || { n: [d1, d2] }; >x284 : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } || { n: [d1, d2] } : { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } || { n: [d1, d2] } : { n: Array; } +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x285: () => Base[] = true ? () => [d1, d2] : () => [d1, d2]; >x285 : () => Base[] >Base : Base ->true ? () => [d1, d2] : () => [d1, d2] : () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>true ? () => [d1, d2] : () => [d1, d2] : () => Array +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x286: () => Base[] = true ? function() { return [d1, d2] } : function() { return [d1, d2] }; >x286 : () => Base[] >Base : Base ->true ? function() { return [d1, d2] } : function() { return [d1, d2] } : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>true ? function() { return [d1, d2] } : function() { return [d1, d2] } : () => Array +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x287: () => Base[] = true ? function named() { return [d1, d2] } : function named() { return [d1, d2] }; >x287 : () => Base[] >Base : Base ->true ? function named() { return [d1, d2] } : function named() { return [d1, d2] } : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>true ? function named() { return [d1, d2] } : function named() { return [d1, d2] } : () => Array +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x288: { (): Base[]; } = true ? () => [d1, d2] : () => [d1, d2]; >x288 : () => Base[] >Base : Base ->true ? () => [d1, d2] : () => [d1, d2] : () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>true ? () => [d1, d2] : () => [d1, d2] : () => Array +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x289: { (): Base[]; } = true ? function() { return [d1, d2] } : function() { return [d1, d2] }; >x289 : () => Base[] >Base : Base ->true ? function() { return [d1, d2] } : function() { return [d1, d2] } : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>true ? function() { return [d1, d2] } : function() { return [d1, d2] } : () => Array +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x290: { (): Base[]; } = true ? function named() { return [d1, d2] } : function named() { return [d1, d2] }; >x290 : () => Base[] >Base : Base ->true ? function named() { return [d1, d2] } : function named() { return [d1, d2] } : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>true ? function named() { return [d1, d2] } : function named() { return [d1, d2] } : () => Array +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x291: Base[] = true ? [d1, d2] : [d1, d2]; >x291 : Base[] >Base : Base ->true ? [d1, d2] : [d1, d2] : Base[] ->[d1, d2] : Base[] +>true ? [d1, d2] : [d1, d2] : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2921,11 +2921,11 @@ var x292: Array = true ? [d1, d2] : [d1, d2]; >x292 : Base[] >Array : T[] >Base : Base ->true ? [d1, d2] : [d1, d2] : Base[] ->[d1, d2] : Base[] +>true ? [d1, d2] : [d1, d2] : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2933,11 +2933,11 @@ var x293: { [n: number]: Base; } = true ? [d1, d2] : [d1, d2]; >x293 : { [x: number]: Base; } >n : number >Base : Base ->true ? [d1, d2] : [d1, d2] : Base[] ->[d1, d2] : Base[] +>true ? [d1, d2] : [d1, d2] : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2945,15 +2945,15 @@ var x294: {n: Base[]; } = true ? { n: [d1, d2] } : { n: [d1, d2] }; >x294 : { n: Base[]; } >n : Base[] >Base : Base ->true ? { n: [d1, d2] } : { n: [d1, d2] } : { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>true ? { n: [d1, d2] } : { n: [d1, d2] } : { n: Array; } +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -2994,71 +2994,71 @@ var x296: Genric = true ? { func: n => { return [d1, d2]; } } : { func: n var x297: () => Base[] = true ? undefined : () => [d1, d2]; >x297 : () => Base[] >Base : Base ->true ? undefined : () => [d1, d2] : () => Base[] +>true ? undefined : () => [d1, d2] : () => Array >undefined : undefined ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x298: () => Base[] = true ? undefined : function() { return [d1, d2] }; >x298 : () => Base[] >Base : Base ->true ? undefined : function() { return [d1, d2] } : () => Base[] +>true ? undefined : function() { return [d1, d2] } : () => Array >undefined : undefined ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x299: () => Base[] = true ? undefined : function named() { return [d1, d2] }; >x299 : () => Base[] >Base : Base ->true ? undefined : function named() { return [d1, d2] } : () => Base[] +>true ? undefined : function named() { return [d1, d2] } : () => Array >undefined : undefined ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x300: { (): Base[]; } = true ? undefined : () => [d1, d2]; >x300 : () => Base[] >Base : Base ->true ? undefined : () => [d1, d2] : () => Base[] +>true ? undefined : () => [d1, d2] : () => Array >undefined : undefined ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x301: { (): Base[]; } = true ? undefined : function() { return [d1, d2] }; >x301 : () => Base[] >Base : Base ->true ? undefined : function() { return [d1, d2] } : () => Base[] +>true ? undefined : function() { return [d1, d2] } : () => Array >undefined : undefined ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x302: { (): Base[]; } = true ? undefined : function named() { return [d1, d2] }; >x302 : () => Base[] >Base : Base ->true ? undefined : function named() { return [d1, d2] } : () => Base[] +>true ? undefined : function named() { return [d1, d2] } : () => Array >undefined : undefined ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 var x303: Base[] = true ? undefined : [d1, d2]; >x303 : Base[] >Base : Base ->true ? undefined : [d1, d2] : Base[] +>true ? undefined : [d1, d2] : Array >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3066,9 +3066,9 @@ var x304: Array = true ? undefined : [d1, d2]; >x304 : Base[] >Array : T[] >Base : Base ->true ? undefined : [d1, d2] : Base[] +>true ? undefined : [d1, d2] : Array >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3076,9 +3076,9 @@ var x305: { [n: number]: Base; } = true ? undefined : [d1, d2]; >x305 : { [x: number]: Base; } >n : number >Base : Base ->true ? undefined : [d1, d2] : Base[] +>true ? undefined : [d1, d2] : Array >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3086,11 +3086,11 @@ var x306: {n: Base[]; } = true ? undefined : { n: [d1, d2] }; >x306 : { n: Base[]; } >n : Base[] >Base : Base ->true ? undefined : { n: [d1, d2] } : { n: Base[]; } +>true ? undefined : { n: [d1, d2] } : { n: Array; } >undefined : undefined ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3122,9 +3122,9 @@ var x308: Genric = true ? undefined : { func: n => { return [d1, d2]; } }; var x309: () => Base[] = true ? () => [d1, d2] : undefined; >x309 : () => Base[] >Base : Base ->true ? () => [d1, d2] : undefined : () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>true ? () => [d1, d2] : undefined : () => Array +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3132,9 +3132,9 @@ var x309: () => Base[] = true ? () => [d1, d2] : undefined; var x310: () => Base[] = true ? function() { return [d1, d2] } : undefined; >x310 : () => Base[] >Base : Base ->true ? function() { return [d1, d2] } : undefined : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>true ? function() { return [d1, d2] } : undefined : () => Array +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3142,10 +3142,10 @@ var x310: () => Base[] = true ? function() { return [d1, d2] } : undefined; var x311: () => Base[] = true ? function named() { return [d1, d2] } : undefined; >x311 : () => Base[] >Base : Base ->true ? function named() { return [d1, d2] } : undefined : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>true ? function named() { return [d1, d2] } : undefined : () => Array +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3153,9 +3153,9 @@ var x311: () => Base[] = true ? function named() { return [d1, d2] } : undefined var x312: { (): Base[]; } = true ? () => [d1, d2] : undefined; >x312 : () => Base[] >Base : Base ->true ? () => [d1, d2] : undefined : () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>true ? () => [d1, d2] : undefined : () => Array +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3163,9 +3163,9 @@ var x312: { (): Base[]; } = true ? () => [d1, d2] : undefined; var x313: { (): Base[]; } = true ? function() { return [d1, d2] } : undefined; >x313 : () => Base[] >Base : Base ->true ? function() { return [d1, d2] } : undefined : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>true ? function() { return [d1, d2] } : undefined : () => Array +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3173,10 +3173,10 @@ var x313: { (): Base[]; } = true ? function() { return [d1, d2] } : undefined; var x314: { (): Base[]; } = true ? function named() { return [d1, d2] } : undefined; >x314 : () => Base[] >Base : Base ->true ? function named() { return [d1, d2] } : undefined : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>true ? function named() { return [d1, d2] } : undefined : () => Array +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3184,8 +3184,8 @@ var x314: { (): Base[]; } = true ? function named() { return [d1, d2] } : undefi var x315: Base[] = true ? [d1, d2] : undefined; >x315 : Base[] >Base : Base ->true ? [d1, d2] : undefined : Base[] ->[d1, d2] : Base[] +>true ? [d1, d2] : undefined : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3194,8 +3194,8 @@ var x316: Array = true ? [d1, d2] : undefined; >x316 : Base[] >Array : T[] >Base : Base ->true ? [d1, d2] : undefined : Base[] ->[d1, d2] : Base[] +>true ? [d1, d2] : undefined : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3204,8 +3204,8 @@ var x317: { [n: number]: Base; } = true ? [d1, d2] : undefined; >x317 : { [x: number]: Base; } >n : number >Base : Base ->true ? [d1, d2] : undefined : Base[] ->[d1, d2] : Base[] +>true ? [d1, d2] : undefined : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3214,10 +3214,10 @@ var x318: {n: Base[]; } = true ? { n: [d1, d2] } : undefined; >x318 : { n: Base[]; } >n : Base[] >Base : Base ->true ? { n: [d1, d2] } : undefined : { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>true ? { n: [d1, d2] } : undefined : { n: Array; } +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3253,8 +3253,8 @@ function x321(n: () => Base[]) { }; x321(() => [d1, d2]); >Base : Base >x321(() => [d1, d2]) : void >x321 : (n: () => Base[]) => void ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3264,8 +3264,8 @@ function x322(n: () => Base[]) { }; x322(function() { return [d1, d2] }); >Base : Base >x322(function() { return [d1, d2] }) : void >x322 : (n: () => Base[]) => void ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3275,9 +3275,9 @@ function x323(n: () => Base[]) { }; x323(function named() { return [d1, d2] }); >Base : Base >x323(function named() { return [d1, d2] }) : void >x323 : (n: () => Base[]) => void ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3287,8 +3287,8 @@ function x324(n: { (): Base[]; }) { }; x324(() => [d1, d2]); >Base : Base >x324(() => [d1, d2]) : void >x324 : (n: () => Base[]) => void ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3298,8 +3298,8 @@ function x325(n: { (): Base[]; }) { }; x325(function() { return [d1, d2] }); >Base : Base >x325(function() { return [d1, d2] }) : void >x325 : (n: () => Base[]) => void ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3309,9 +3309,9 @@ function x326(n: { (): Base[]; }) { }; x326(function named() { return [d1, d2] } >Base : Base >x326(function named() { return [d1, d2] }) : void >x326 : (n: () => Base[]) => void ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3321,7 +3321,7 @@ function x327(n: Base[]) { }; x327([d1, d2]); >Base : Base >x327([d1, d2]) : void >x327 : (n: Base[]) => void ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3332,7 +3332,7 @@ function x328(n: Array) { }; x328([d1, d2]); >Base : Base >x328([d1, d2]) : void >x328 : (n: Base[]) => void ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3343,7 +3343,7 @@ function x329(n: { [n: number]: Base; }) { }; x329([d1, d2]); >Base : Base >x329([d1, d2]) : void >x329 : (n: { [x: number]: Base; }) => void ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3354,9 +3354,9 @@ function x330(n: {n: Base[]; } ) { }; x330({ n: [d1, d2] }); >Base : Base >x330({ n: [d1, d2] }) : void >x330 : (n: { n: Base[]; }) => void ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3395,8 +3395,8 @@ var x333 = (n: () => Base[]) => n; x333(() => [d1, d2]); >n : () => Base[] >x333(() => [d1, d2]) : () => Base[] >x333 : (n: () => Base[]) => () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3408,8 +3408,8 @@ var x334 = (n: () => Base[]) => n; x334(function() { return [d1, d2] }); >n : () => Base[] >x334(function() { return [d1, d2] }) : () => Base[] >x334 : (n: () => Base[]) => () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3421,9 +3421,9 @@ var x335 = (n: () => Base[]) => n; x335(function named() { return [d1, d2] }); >n : () => Base[] >x335(function named() { return [d1, d2] }) : () => Base[] >x335 : (n: () => Base[]) => () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3435,8 +3435,8 @@ var x336 = (n: { (): Base[]; }) => n; x336(() => [d1, d2]); >n : () => Base[] >x336(() => [d1, d2]) : () => Base[] >x336 : (n: () => Base[]) => () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3448,8 +3448,8 @@ var x337 = (n: { (): Base[]; }) => n; x337(function() { return [d1, d2] }); >n : () => Base[] >x337(function() { return [d1, d2] }) : () => Base[] >x337 : (n: () => Base[]) => () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3461,9 +3461,9 @@ var x338 = (n: { (): Base[]; }) => n; x338(function named() { return [d1, d2] }) >n : () => Base[] >x338(function named() { return [d1, d2] }) : () => Base[] >x338 : (n: () => Base[]) => () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3475,7 +3475,7 @@ var x339 = (n: Base[]) => n; x339([d1, d2]); >n : Base[] >x339([d1, d2]) : Base[] >x339 : (n: Base[]) => Base[] ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3488,7 +3488,7 @@ var x340 = (n: Array) => n; x340([d1, d2]); >n : Base[] >x340([d1, d2]) : Base[] >x340 : (n: Base[]) => Base[] ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3501,7 +3501,7 @@ var x341 = (n: { [n: number]: Base; }) => n; x341([d1, d2]); >n : { [x: number]: Base; } >x341([d1, d2]) : { [x: number]: Base; } >x341 : (n: { [x: number]: Base; }) => { [x: number]: Base; } ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3514,9 +3514,9 @@ var x342 = (n: {n: Base[]; } ) => n; x342({ n: [d1, d2] }); >n : { n: Base[]; } >x342({ n: [d1, d2] }) : { n: Base[]; } >x342 : (n: { n: Base[]; }) => { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3558,8 +3558,8 @@ var x345 = function(n: () => Base[]) { }; x345(() => [d1, d2]); >Base : Base >x345(() => [d1, d2]) : void >x345 : (n: () => Base[]) => void ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3570,8 +3570,8 @@ var x346 = function(n: () => Base[]) { }; x346(function() { return [d1, d2] }); >Base : Base >x346(function() { return [d1, d2] }) : void >x346 : (n: () => Base[]) => void ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3582,9 +3582,9 @@ var x347 = function(n: () => Base[]) { }; x347(function named() { return [d1, d2 >Base : Base >x347(function named() { return [d1, d2] }) : void >x347 : (n: () => Base[]) => void ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3595,8 +3595,8 @@ var x348 = function(n: { (): Base[]; }) { }; x348(() => [d1, d2]); >Base : Base >x348(() => [d1, d2]) : void >x348 : (n: () => Base[]) => void ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3607,8 +3607,8 @@ var x349 = function(n: { (): Base[]; }) { }; x349(function() { return [d1, d2] } >Base : Base >x349(function() { return [d1, d2] }) : void >x349 : (n: () => Base[]) => void ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3619,9 +3619,9 @@ var x350 = function(n: { (): Base[]; }) { }; x350(function named() { return [d1, >Base : Base >x350(function named() { return [d1, d2] }) : void >x350 : (n: () => Base[]) => void ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => Array +>named : () => Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3632,7 +3632,7 @@ var x351 = function(n: Base[]) { }; x351([d1, d2]); >Base : Base >x351([d1, d2]) : void >x351 : (n: Base[]) => void ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3644,7 +3644,7 @@ var x352 = function(n: Array) { }; x352([d1, d2]); >Base : Base >x352([d1, d2]) : void >x352 : (n: Base[]) => void ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3656,7 +3656,7 @@ var x353 = function(n: { [n: number]: Base; }) { }; x353([d1, d2]); >Base : Base >x353([d1, d2]) : void >x353 : (n: { [x: number]: Base; }) => void ->[d1, d2] : Base[] +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 @@ -3668,9 +3668,9 @@ var x354 = function(n: {n: Base[]; } ) { }; x354({ n: [d1, d2] }); >Base : Base >x354({ n: [d1, d2] }) : void >x354 : (n: { n: Base[]; }) => void ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: Array; } +>n : Array +>[d1, d2] : Array >d1 : Derived1 >d2 : Derived2 diff --git a/tests/baselines/reference/genericArray0.types b/tests/baselines/reference/genericArray0.types index 80a9d5199bd..bf0155bb9ba 100644 --- a/tests/baselines/reference/genericArray0.types +++ b/tests/baselines/reference/genericArray0.types @@ -16,6 +16,6 @@ function map() { var ys: U[] = []; >ys : U[] >U : U ->[] : U[] +>[] : undefined[] } diff --git a/tests/baselines/reference/genericBaseClassLiteralProperty2.types b/tests/baselines/reference/genericBaseClassLiteralProperty2.types index b2d156e3c16..9caa45b8b8f 100644 --- a/tests/baselines/reference/genericBaseClassLiteralProperty2.types +++ b/tests/baselines/reference/genericBaseClassLiteralProperty2.types @@ -14,11 +14,11 @@ class BaseCollection2 { constructor() { this._itemsByKey = {}; ->this._itemsByKey = {} : { [x: string]: TItem; } +>this._itemsByKey = {} : { [x: string]: undefined; } >this._itemsByKey : { [x: string]: TItem; } >this : BaseCollection2 >_itemsByKey : { [x: string]: TItem; } ->{} : { [x: string]: TItem; } +>{} : { [x: string]: undefined; } } } diff --git a/tests/baselines/reference/genericCallWithArrayLiteralArgs.types b/tests/baselines/reference/genericCallWithArrayLiteralArgs.types index a6a75f9bd13..84082a68ebd 100644 --- a/tests/baselines/reference/genericCallWithArrayLiteralArgs.types +++ b/tests/baselines/reference/genericCallWithArrayLiteralArgs.types @@ -25,19 +25,19 @@ var ra = foo([1, 2]); // any[] >ra : any[] >foo([1, 2]) : any[] >foo : (t: T) => T ->[1, 2] : any[] +>[1, 2] : number[] var r2 = foo([]); // any[] >r2 : any[] >foo([]) : any[] >foo : (t: T) => T ->[] : any[] +>[] : undefined[] var r3 = foo([]); // number[] >r3 : number[] >foo([]) : number[] >foo : (t: T) => T ->[] : number[] +>[] : undefined[] var r4 = foo([1, '']); // {}[] >r4 : Array @@ -49,12 +49,12 @@ var r5 = foo([1, '']); // any[] >r5 : any[] >foo([1, '']) : any[] >foo : (t: T) => T ->[1, ''] : any[] +>[1, ''] : Array var r6 = foo([1, '']); // Object[] >r6 : Object[] >foo([1, '']) : Object[] >foo : (t: T) => T >Object : Object ->[1, ''] : Object[] +>[1, ''] : Array diff --git a/tests/baselines/reference/genericTypeArgumentInference1.types b/tests/baselines/reference/genericTypeArgumentInference1.types index c7d932befb8..be7a3e9226d 100644 --- a/tests/baselines/reference/genericTypeArgumentInference1.types +++ b/tests/baselines/reference/genericTypeArgumentInference1.types @@ -69,7 +69,7 @@ var r3 = _.all([], _.identity); >_.all : (list: T[], iterator?: Underscore.Iterator, context?: any) => T >_ : Underscore.Static >all : (list: T[], iterator?: Underscore.Iterator, context?: any) => T ->[] : any[] +>[] : undefined[] >_.identity : (value: T) => T >_ : Underscore.Static >identity : (value: T) => T diff --git a/tests/baselines/reference/genericWithIndexerOfTypeParameterType1.types b/tests/baselines/reference/genericWithIndexerOfTypeParameterType1.types index 05697f1e1f9..f0cab6e7467 100644 --- a/tests/baselines/reference/genericWithIndexerOfTypeParameterType1.types +++ b/tests/baselines/reference/genericWithIndexerOfTypeParameterType1.types @@ -8,7 +8,7 @@ class LazyArray { ><{ [objectId: string]: T; }>{} : { [x: string]: T; } >objectId : string >T : T ->{} : { [x: string]: T; } +>{} : { [x: string]: undefined; } array() { >array : () => { [x: string]: T; } diff --git a/tests/baselines/reference/heterogeneousArrayLiterals.types b/tests/baselines/reference/heterogeneousArrayLiterals.types index 882fe1e8295..c236fe7ff6d 100644 --- a/tests/baselines/reference/heterogeneousArrayLiterals.types +++ b/tests/baselines/reference/heterogeneousArrayLiterals.types @@ -212,24 +212,24 @@ module WithContextualType { var a: Base[] = [derived, derived2]; >a : Base[] >Base : Base ->[derived, derived2] : Base[] +>[derived, derived2] : Array >derived : Derived >derived2 : Derived2 var b: Derived[] = [null]; >b : Derived[] >Derived : Derived ->[null] : Derived[] +>[null] : null[] var c: Derived[] = []; >c : Derived[] >Derived : Derived ->[] : Derived[] +>[] : undefined[] var d: { (): Base }[] = [() => derived, () => derived2]; >d : { (): Base; }[] >Base : Base ->[() => derived, () => derived2] : { (): Base; }[] +>[() => derived, () => derived2] : Array<{ (): Derived; } | { (): Derived2; }> >() => derived : () => Derived >derived : Derived >() => derived2 : () => Derived2 @@ -512,7 +512,7 @@ function foo4(t: T, u: U) { var k: Base[] = [t, u]; >k : Base[] >Base : Base ->[t, u] : Base[] +>[t, u] : Array >t : T >u : U } diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherType.types b/tests/baselines/reference/incrementOperatorWithAnyOtherType.types index 165c166941c..930c87274d0 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherType.types +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherType.types @@ -9,7 +9,7 @@ var ANY1; var ANY2: any[] = ["", ""]; >ANY2 : any[] ->["", ""] : any[] +>["", ""] : string[] var obj = {x:1,y:null}; >obj : { x: number; y: any; } diff --git a/tests/baselines/reference/indexSignaturesInferentialTyping.types b/tests/baselines/reference/indexSignaturesInferentialTyping.types index 3c16db3a2bf..4054ccca227 100644 --- a/tests/baselines/reference/indexSignaturesInferentialTyping.types +++ b/tests/baselines/reference/indexSignaturesInferentialTyping.types @@ -24,10 +24,10 @@ var x1 = foo({ 0: 0, 1: 1 }); // type should be number >{ 0: 0, 1: 1 } : { [x: number]: number; 0: number; 1: number; } var x2 = foo({ zero: 0, one: 1 }); ->x2 : {} ->foo({ zero: 0, one: 1 }) : {} +>x2 : any +>foo({ zero: 0, one: 1 }) : any >foo : (items: { [x: number]: T; }) => T ->{ zero: 0, one: 1 } : { [x: number]: {}; zero: number; one: number; } +>{ zero: 0, one: 1 } : { [x: number]: undefined; zero: number; one: number; } >zero : number >one : number diff --git a/tests/baselines/reference/indexer.types b/tests/baselines/reference/indexer.types index 236113cfaa8..9987fdde0b1 100644 --- a/tests/baselines/reference/indexer.types +++ b/tests/baselines/reference/indexer.types @@ -17,7 +17,7 @@ interface JQuery { var jq:JQuery={ 0: { id : "a" }, 1: { id : "b" } }; >jq : JQuery >JQuery : JQuery ->{ 0: { id : "a" }, 1: { id : "b" } } : { [x: number]: JQueryElement; 0: { id: string; }; 1: { id: string; }; } +>{ 0: { id : "a" }, 1: { id : "b" } } : { [x: number]: { id: string; }; 0: { id: string; }; 1: { id: string; }; } >{ id : "a" } : { id: string; } >id : string >{ id : "b" } : { id: string; } diff --git a/tests/baselines/reference/indexer2.errors.txt b/tests/baselines/reference/indexer2.errors.txt new file mode 100644 index 00000000000..9587bb6bb75 --- /dev/null +++ b/tests/baselines/reference/indexer2.errors.txt @@ -0,0 +1,20 @@ +tests/cases/compiler/indexer2.ts(6,25): error TS2353: Neither type '{ [x: number]: undefined; }' nor type 'IDirectChildrenMap' is assignable to the other: + Types of property 'hasOwnProperty' are incompatible: + Type '(v: string) => boolean' is not assignable to type '(objectId: number) => boolean': + Types of parameters 'v' and 'objectId' are incompatible: + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/compiler/indexer2.ts (1 errors) ==== + interface IHeapObjectProperty {} + interface IDirectChildrenMap { + hasOwnProperty(objectId: number) : boolean; + [objectId: number] : IHeapObjectProperty[]; + } + var directChildrenMap = {}; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2353: Neither type '{ [x: number]: undefined; }' nor type 'IDirectChildrenMap' is assignable to the other: +!!! error TS2353: Types of property 'hasOwnProperty' are incompatible: +!!! error TS2353: Type '(v: string) => boolean' is not assignable to type '(objectId: number) => boolean': +!!! error TS2353: Types of parameters 'v' and 'objectId' are incompatible: +!!! error TS2353: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/indexer2.types b/tests/baselines/reference/indexer2.types deleted file mode 100644 index 498ade679a8..00000000000 --- a/tests/baselines/reference/indexer2.types +++ /dev/null @@ -1,21 +0,0 @@ -=== tests/cases/compiler/indexer2.ts === -interface IHeapObjectProperty {} ->IHeapObjectProperty : IHeapObjectProperty - -interface IDirectChildrenMap { ->IDirectChildrenMap : IDirectChildrenMap - - hasOwnProperty(objectId: number) : boolean; ->hasOwnProperty : (objectId: number) => boolean ->objectId : number - - [objectId: number] : IHeapObjectProperty[]; ->objectId : number ->IHeapObjectProperty : IHeapObjectProperty -} -var directChildrenMap = {}; ->directChildrenMap : IDirectChildrenMap ->{} : IDirectChildrenMap ->IDirectChildrenMap : IDirectChildrenMap ->{} : { [x: number]: IHeapObjectProperty[]; } - diff --git a/tests/baselines/reference/indexer2A.errors.txt b/tests/baselines/reference/indexer2A.errors.txt index adf90fb743f..548ed5e565b 100644 --- a/tests/baselines/reference/indexer2A.errors.txt +++ b/tests/baselines/reference/indexer2A.errors.txt @@ -1,7 +1,12 @@ tests/cases/compiler/indexer2A.ts(4,5): error TS2391: Function implementation is missing or not immediately following the declaration. +tests/cases/compiler/indexer2A.ts(7,25): error TS2353: Neither type '{ [x: number]: undefined; }' nor type 'IDirectChildrenMap' is assignable to the other: + Types of property 'hasOwnProperty' are incompatible: + Type '(v: string) => boolean' is not assignable to type '(objectId: number) => boolean': + Types of parameters 'v' and 'objectId' are incompatible: + Type 'string' is not assignable to type 'number'. -==== tests/cases/compiler/indexer2A.ts (1 errors) ==== +==== tests/cases/compiler/indexer2A.ts (2 errors) ==== class IHeapObjectProperty { } class IDirectChildrenMap { // Decided to enforce a semicolon after declarations @@ -10,4 +15,10 @@ tests/cases/compiler/indexer2A.ts(4,5): error TS2391: Function implementation is !!! error TS2391: Function implementation is missing or not immediately following the declaration. [objectId: number]: IHeapObjectProperty[] } - var directChildrenMap = {}; \ No newline at end of file + var directChildrenMap = {}; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2353: Neither type '{ [x: number]: undefined; }' nor type 'IDirectChildrenMap' is assignable to the other: +!!! error TS2353: Types of property 'hasOwnProperty' are incompatible: +!!! error TS2353: Type '(v: string) => boolean' is not assignable to type '(objectId: number) => boolean': +!!! error TS2353: Types of parameters 'v' and 'objectId' are incompatible: +!!! error TS2353: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/indexer3.types b/tests/baselines/reference/indexer3.types index 2b23ac85885..7f660ab6aa9 100644 --- a/tests/baselines/reference/indexer3.types +++ b/tests/baselines/reference/indexer3.types @@ -3,7 +3,7 @@ var dateMap: { [x: string]: Date; } = {} >dateMap : { [x: string]: Date; } >x : string >Date : Date ->{} : { [x: string]: Date; } +>{} : { [x: string]: undefined; } var r: Date = dateMap["hello"] // result type includes indexer using BCT >r : Date diff --git a/tests/baselines/reference/indexerA.types b/tests/baselines/reference/indexerA.types index 7b409ecedc0..39f7372c839 100644 --- a/tests/baselines/reference/indexerA.types +++ b/tests/baselines/reference/indexerA.types @@ -17,7 +17,7 @@ class JQuery { var jq:JQuery={ 0: { id : "a" }, 1: { id : "b" } }; >jq : JQuery >JQuery : JQuery ->{ 0: { id : "a" }, 1: { id : "b" } } : { [x: number]: JQueryElement; 0: { id: string; }; 1: { id: string; }; } +>{ 0: { id : "a" }, 1: { id : "b" } } : { [x: number]: { id: string; }; 0: { id: string; }; 1: { id: string; }; } >{ id : "a" } : { id: string; } >id : string >{ id : "b" } : { id: string; } diff --git a/tests/baselines/reference/inferentialTypingWithFunctionTypeZip.types b/tests/baselines/reference/inferentialTypingWithFunctionTypeZip.types index 11e017d6661..53a9dff0b48 100644 --- a/tests/baselines/reference/inferentialTypingWithFunctionTypeZip.types +++ b/tests/baselines/reference/inferentialTypingWithFunctionTypeZip.types @@ -34,7 +34,7 @@ var result = zipWith([1, 2], ['a', 'b'], pair); >zipWith([1, 2], ['a', 'b'], pair) : { x: number; y: {}; }[] >zipWith : (a: T[], b: S[], f: (x: T) => (y: S) => U) => U[] >[1, 2] : number[] ->['a', 'b'] : {}[] +>['a', 'b'] : string[] >pair : (x: T) => (y: S) => { x: T; y: S; } var i = result[0].x; // number diff --git a/tests/baselines/reference/inferentiallyTypingAnEmptyArray.types b/tests/baselines/reference/inferentiallyTypingAnEmptyArray.types index c8f51c985e6..451280ee16f 100644 --- a/tests/baselines/reference/inferentiallyTypingAnEmptyArray.types +++ b/tests/baselines/reference/inferentiallyTypingAnEmptyArray.types @@ -25,6 +25,6 @@ foo([]).bar; >foo([]).bar : any >foo([]) : any >foo : (arr: T[]) => T ->[] : any[] +>[] : undefined[] >bar : any diff --git a/tests/baselines/reference/interfaceContextualType.types b/tests/baselines/reference/interfaceContextualType.types index 88ba9dcbc24..3078ecfdfa4 100644 --- a/tests/baselines/reference/interfaceContextualType.types +++ b/tests/baselines/reference/interfaceContextualType.types @@ -27,11 +27,11 @@ class Bug { >ok : () => void this.values = {}; ->this.values = {} : { [x: string]: IOptions; } +>this.values = {} : { [x: string]: undefined; } >this.values : IMap >this : Bug >values : IMap ->{} : { [x: string]: IOptions; } +>{} : { [x: string]: undefined; } this.values['comments'] = { italic: true }; >this.values['comments'] = { italic: true } : { italic: boolean; } @@ -46,11 +46,11 @@ class Bug { >shouldBeOK : () => void this.values = { ->this.values = { comments: { italic: true } } : { [x: string]: IOptions; comments: { italic: boolean; }; } +>this.values = { comments: { italic: true } } : { [x: string]: { italic: boolean; }; comments: { italic: boolean; }; } >this.values : IMap >this : Bug >values : IMap ->{ comments: { italic: true } } : { [x: string]: IOptions; comments: { italic: boolean; }; } +>{ comments: { italic: true } } : { [x: string]: { italic: boolean; }; comments: { italic: boolean; }; } comments: { italic: true } >comments : { italic: boolean; } diff --git a/tests/baselines/reference/memberVariableDeclarations1.types b/tests/baselines/reference/memberVariableDeclarations1.types index 10ec78d69dc..4dd68cdeb35 100644 --- a/tests/baselines/reference/memberVariableDeclarations1.types +++ b/tests/baselines/reference/memberVariableDeclarations1.types @@ -20,7 +20,7 @@ class Employee { public reports: Employee[] = []; >reports : Employee[] >Employee : Employee ->[] : Employee[] +>[] : undefined[] } class Employee2 { @@ -57,11 +57,11 @@ class Employee2 { >manager : Employee this.reports = []; ->this.reports = [] : Employee[] +>this.reports = [] : undefined[] >this.reports : Employee[] >this : Employee2 >reports : Employee[] ->[] : Employee[] +>[] : undefined[] } } diff --git a/tests/baselines/reference/negateOperatorWithAnyOtherType.types b/tests/baselines/reference/negateOperatorWithAnyOtherType.types index 8785ab073b2..85a2d9c9233 100644 --- a/tests/baselines/reference/negateOperatorWithAnyOtherType.types +++ b/tests/baselines/reference/negateOperatorWithAnyOtherType.types @@ -9,7 +9,7 @@ var ANY1; var ANY2: any[] = ["", ""]; >ANY2 : any[] ->["", ""] : any[] +>["", ""] : string[] var obj: () => {} >obj : () => {} diff --git a/tests/baselines/reference/noImplicitAnyFunctionExpressionAssignment.errors.txt b/tests/baselines/reference/noImplicitAnyFunctionExpressionAssignment.errors.txt deleted file mode 100644 index d53f12fd504..00000000000 --- a/tests/baselines/reference/noImplicitAnyFunctionExpressionAssignment.errors.txt +++ /dev/null @@ -1,21 +0,0 @@ -tests/cases/compiler/noImplicitAnyFunctionExpressionAssignment.ts(2,27): error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. -tests/cases/compiler/noImplicitAnyFunctionExpressionAssignment.ts(6,28): error TS7010: 'f', which lacks return-type annotation, implicitly has an 'any' return type. - - -==== tests/cases/compiler/noImplicitAnyFunctionExpressionAssignment.ts (2 errors) ==== - - var x: (a: any) => void = function (x: T) { - ~~~~~~~~~~~~~~~~~~~~ - return null; - ~~~~~~~~~~~~~~~~ - }; - ~ -!!! error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. - - var x2: (a: any) => void = function f(x: T) { - ~~~~~~~~~~~~~~~~~~~~~ - return null; - ~~~~~~~~~~~~~~~~ - }; - ~ -!!! error TS7010: 'f', which lacks return-type annotation, implicitly has an 'any' return type. \ No newline at end of file diff --git a/tests/baselines/reference/noImplicitAnyFunctionExpressionAssignment.types b/tests/baselines/reference/noImplicitAnyFunctionExpressionAssignment.types new file mode 100644 index 00000000000..b07252dac6d --- /dev/null +++ b/tests/baselines/reference/noImplicitAnyFunctionExpressionAssignment.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/noImplicitAnyFunctionExpressionAssignment.ts === + +var x: (a: any) => void = function (x: T) { +>x : (a: any) => void +>a : any +>function (x: T) { return null;} : (x: T) => any +>T : T +>x : T +>T : T + + return null; +}; + +var x2: (a: any) => void = function f(x: T) { +>x2 : (a: any) => void +>a : any +>function f(x: T) { return null;} : (x: T) => any +>f : (x: T) => any +>T : T +>x : T +>T : T + + return null; +}; diff --git a/tests/baselines/reference/numericIndexerConstraint4.types b/tests/baselines/reference/numericIndexerConstraint4.types index f0004e52b45..78b57d4179e 100644 --- a/tests/baselines/reference/numericIndexerConstraint4.types +++ b/tests/baselines/reference/numericIndexerConstraint4.types @@ -22,7 +22,7 @@ var x: { >A : A } = { data: new B() } ->{ data: new B() } : { [x: number]: A; data: B; } +>{ data: new B() } : { [x: number]: undefined; data: B; } >data : B >new B() : B >B : typeof B diff --git a/tests/baselines/reference/objectIndexer.types b/tests/baselines/reference/objectIndexer.types index a2a7f99cf5d..7b42ea51b56 100644 --- a/tests/baselines/reference/objectIndexer.types +++ b/tests/baselines/reference/objectIndexer.types @@ -23,11 +23,11 @@ class Emitter { constructor () { this.listeners = {}; ->this.listeners = {} : { [x: string]: Callback; } +>this.listeners = {} : { [x: string]: undefined; } >this.listeners : IMap >this : Emitter >listeners : IMap ->{} : { [x: string]: Callback; } +>{} : { [x: string]: undefined; } } } diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types index ab83b0c78f0..a0603ae0777 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types @@ -50,7 +50,7 @@ var a: { var b: { [x: number]: string; } = { foo: '' }; >b : { [x: number]: string; } >x : number ->{ foo: '' } : { [x: number]: string; foo: string; } +>{ foo: '' } : { [x: number]: undefined; foo: string; } >foo : string function foo1(x: A); diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types index cd8f19b2b7e..9e4ccb5c43b 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types @@ -64,7 +64,7 @@ var b: { [x: number]: Derived; } = { foo: null }; >b : { [x: number]: Derived; } >x : number >Derived : Derived ->{ foo: null } : { [x: number]: Derived; foo: Derived; } +>{ foo: null } : { [x: number]: undefined; foo: Derived; } >foo : Derived >null : Derived >Derived : Derived diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types index 6a73749fc84..3553f5f7252 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types @@ -50,7 +50,7 @@ var a: { var b: { [x: number]: string; } = { foo: '' }; >b : { [x: number]: string; } >x : number ->{ foo: '' } : { [x: number]: string; foo: string; } +>{ foo: '' } : { [x: number]: undefined; foo: string; } >foo : string function foo1(x: A); diff --git a/tests/baselines/reference/overloadResolutionOverNonCTObjectLit.types b/tests/baselines/reference/overloadResolutionOverNonCTObjectLit.types index 846190010b4..7ad68cefa4f 100644 --- a/tests/baselines/reference/overloadResolutionOverNonCTObjectLit.types +++ b/tests/baselines/reference/overloadResolutionOverNonCTObjectLit.types @@ -37,7 +37,7 @@ module Bugs { var tokens:IToken[]= []; >tokens : IToken[] >IToken : IToken ->[] : IToken[] +>[] : undefined[] tokens.push({ startIndex: 1, type: '', bracket: 3 }); >tokens.push({ startIndex: 1, type: '', bracket: 3 }) : number diff --git a/tests/baselines/reference/sourceMapValidationClasses.types b/tests/baselines/reference/sourceMapValidationClasses.types index d53cdcb9974..4f391c86f65 100644 --- a/tests/baselines/reference/sourceMapValidationClasses.types +++ b/tests/baselines/reference/sourceMapValidationClasses.types @@ -56,7 +56,7 @@ module Foo.Bar { var greeters: Greeter[] = []; /* inline block comment */ >greeters : Greeter[] >Greeter : Greeter ->[] : Greeter[] +>[] : undefined[] greeters[0] = new Greeter(greeting); >greeters[0] = new Greeter(greeting) : Greeter diff --git a/tests/baselines/reference/targetTypeTest2.types b/tests/baselines/reference/targetTypeTest2.types index 795dd7036f7..f40d68d075a 100644 --- a/tests/baselines/reference/targetTypeTest2.types +++ b/tests/baselines/reference/targetTypeTest2.types @@ -4,7 +4,7 @@ var a : any[] = [1,2,"3"]; >a : any[] ->[1,2,"3"] : any[] +>[1,2,"3"] : Array function func1(stuff:any[]) { return stuff; } @@ -21,7 +21,7 @@ function func2(stuff1:string, stuff2:number, stuff3:number) { return func1([stuff1, stuff2, stuff3]); >func1([stuff1, stuff2, stuff3]) : any[] >func1 : (stuff: any[]) => any[] ->[stuff1, stuff2, stuff3] : any[] +>[stuff1, stuff2, stuff3] : Array >stuff1 : string >stuff2 : number >stuff3 : number diff --git a/tests/baselines/reference/thisInPropertyBoundDeclarations.types b/tests/baselines/reference/thisInPropertyBoundDeclarations.types index 1ccebef5eaa..899aa41a684 100644 --- a/tests/baselines/reference/thisInPropertyBoundDeclarations.types +++ b/tests/baselines/reference/thisInPropertyBoundDeclarations.types @@ -8,7 +8,7 @@ class Bug { private static func: Function[] = [ >func : Function[] >Function : Function ->[ (that: Bug, name: string) => { that.foo(name); } ] : Function[] +>[ (that: Bug, name: string) => { that.foo(name); } ] : { (that: Bug, name: string): void; }[] (that: Bug, name: string) => { >(that: Bug, name: string) => { that.foo(name); } : (that: Bug, name: string) => void diff --git a/tests/baselines/reference/tupleTypes.errors.txt b/tests/baselines/reference/tupleTypes.errors.txt index 824148bc2e2..8bf6cca4855 100644 --- a/tests/baselines/reference/tupleTypes.errors.txt +++ b/tests/baselines/reference/tupleTypes.errors.txt @@ -1,12 +1,12 @@ tests/cases/compiler/tupleTypes.ts(1,9): error TS1122: A tuple type element list cannot be empty. -tests/cases/compiler/tupleTypes.ts(14,1): error TS2322: Type 'Array' is not assignable to type '[number, string]': - Property '0' is missing in type 'Array'. +tests/cases/compiler/tupleTypes.ts(14,1): error TS2322: Type 'undefined[]' is not assignable to type '[number, string]': + Property '0' is missing in type 'undefined[]'. tests/cases/compiler/tupleTypes.ts(15,1): error TS2322: Type '[number]' is not assignable to type '[number, string]': Property '1' is missing in type '[number]'. tests/cases/compiler/tupleTypes.ts(17,1): error TS2322: Type '[string, number]' is not assignable to type '[number, string]': Types of property '0' are incompatible: Type 'string' is not assignable to type 'number'. -tests/cases/compiler/tupleTypes.ts(41,1): error TS2323: Type 'Array' is not assignable to type '[number, string]'. +tests/cases/compiler/tupleTypes.ts(41,1): error TS2323: Type 'undefined[]' is not assignable to type '[number, string]'. tests/cases/compiler/tupleTypes.ts(47,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]': Types of property 'pop' are incompatible: Type '() => string | number' is not assignable to type '() => number': @@ -42,8 +42,8 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n t = []; // Error ~ -!!! error TS2322: Type 'Array' is not assignable to type '[number, string]': -!!! error TS2322: Property '0' is missing in type 'Array'. +!!! error TS2322: Type 'undefined[]' is not assignable to type '[number, string]': +!!! error TS2322: Property '0' is missing in type 'undefined[]'. t = [1]; // Error ~ !!! error TS2322: Type '[number]' is not assignable to type '[number, string]': @@ -79,7 +79,7 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n tt = [undefined, undefined]; tt = []; // Error ~~ -!!! error TS2323: Type 'Array' is not assignable to type '[number, string]'. +!!! error TS2323: Type 'undefined[]' is not assignable to type '[number, string]'. var a: number[]; var a1: [number, string]; diff --git a/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types b/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types index 584ae0dcb3c..1cee9140a01 100644 --- a/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types +++ b/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types @@ -23,7 +23,7 @@ interface IMenuItem { var menuData: IMenuItem[] = [ >menuData : IMenuItem[] >IMenuItem : IMenuItem ->[ { "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" }, { "id": "productName", "type": "default", "link": "", "text": "Product Name" }] : IMenuItem[] +>[ { "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" }, { "id": "productName", "type": "default", "link": "", "text": "Product Name" }] : Array<{ "id": string; "type": string; "link": string; "icon": string; } | { "id": string; "type": string; "link": string; "text": string; }> { >{ "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" } : { "id": string; "type": string; "link": string; "icon": string; } diff --git a/tests/baselines/reference/undefinedInferentialTyping.types b/tests/baselines/reference/undefinedInferentialTyping.types index b5741e4d40f..61737ac6b6c 100644 --- a/tests/baselines/reference/undefinedInferentialTyping.types +++ b/tests/baselines/reference/undefinedInferentialTyping.types @@ -15,5 +15,5 @@ var a = f([], 3); // should be number >a : number >f([], 3) : number >f : (arr: T[], elemnt: T) => T ->[] : number[] +>[] : undefined[] diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index c73c63aee26..5337a4971d1 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -104,7 +104,7 @@ var flat = _.reduceRight(list, (a, b) => a.concat(b), []); >a : number[] >concat : { (...items: U[]): number[]; (...items: number[]): number[]; } >b : number[] ->[] : number[] +>[] : undefined[] var even = _.find([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0); >even : number @@ -200,7 +200,7 @@ _.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); >_.invoke : { (list: any[], methodName: string, ...args: any[]): any[]; (list: Dictionary, methodName: string, ...args: any[]): any[]; } >_ : Underscore.Static >invoke : { (list: any[], methodName: string, ...args: any[]): any[]; (list: Dictionary, methodName: string, ...args: any[]): any[]; } ->[[5, 1, 7], [3, 2, 1]] : any[] +>[[5, 1, 7], [3, 2, 1]] : number[][] >[5, 1, 7] : number[] >[3, 2, 1] : number[] @@ -375,14 +375,14 @@ _.flatten([1, 2, 3, 4]); >_.flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } >_ : Underscore.Static >flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } ->[1, 2, 3, 4] : any[] +>[1, 2, 3, 4] : number[] _.flatten([1, [2]]); >_.flatten([1, [2]]) : {}[] >_.flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } >_ : Underscore.Static >flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } ->[1, [2]] : any[] +>[1, [2]] : Array >[2] : number[] // typescript doesn't like the elements being different @@ -391,7 +391,7 @@ _.flatten([1, [2], [3, [[4]]]]); >_.flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } >_ : Underscore.Static >flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } ->[1, [2], [3, [[4]]]] : any[] +>[1, [2], [3, [[4]]]] : Array> >[2] : number[] >[3, [[4]]] : Array >[[4]] : number[][] @@ -402,7 +402,7 @@ _.flatten([1, [2], [3, [[4]]]], true); >_.flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } >_ : Underscore.Static >flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } ->[1, [2], [3, [[4]]]] : any[] +>[1, [2], [3, [[4]]]] : Array> >[2] : number[] >[3, [[4]]] : Array >[[4]] : number[][] @@ -463,17 +463,17 @@ _.object(['moe', 'larry', 'curly'], [30, 40, 50]); >_ : Underscore.Static >object : { (list: any[][]): any; (keys: string[], values: any[]): any; } >['moe', 'larry', 'curly'] : string[] ->[30, 40, 50] : any[] +>[30, 40, 50] : number[] _.object([['moe', 30], ['larry', 40], ['curly', 50]]); >_.object([['moe', 30], ['larry', 40], ['curly', 50]]) : any >_.object : { (list: any[][]): any; (keys: string[], values: any[]): any; } >_ : Underscore.Static >object : { (list: any[][]): any; (keys: string[], values: any[]): any; } ->[['moe', 30], ['larry', 40], ['curly', 50]] : any[][] ->['moe', 30] : any[] ->['larry', 40] : any[] ->['curly', 50] : any[] +>[['moe', 30], ['larry', 40], ['curly', 50]] : Array[] +>['moe', 30] : Array +>['larry', 40] : Array +>['curly', 50] : Array _.indexOf([1, 2, 3], 2); >_.indexOf([1, 2, 3], 2) : number diff --git a/tests/baselines/reference/validMultipleVariableDeclarations.types b/tests/baselines/reference/validMultipleVariableDeclarations.types index 89d3702a702..4bbd46bab2b 100644 --- a/tests/baselines/reference/validMultipleVariableDeclarations.types +++ b/tests/baselines/reference/validMultipleVariableDeclarations.types @@ -117,11 +117,11 @@ var a = ['a', 'b'] var a = []; >a : string[] >[] : string[] ->[] : string[] +>[] : undefined[] var a: string[] = []; >a : string[] ->[] : string[] +>[] : undefined[] var a = new Array(); >a : string[] From 869ee41694e755e8923b964f7318307e1fe326d4 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 13 Oct 2014 11:26:08 -0700 Subject: [PATCH 22/23] Addressing CR feedback --- src/compiler/checker.ts | 1 - src/compiler/types.ts | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a14c4200f1d..fcd1736f839 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3813,7 +3813,6 @@ module ts { } } else if (target.flags & TypeFlags.Union) { - // Target is a union type var targetTypes = (target).types; var startCount = context.inferenceCount; var typeParameterCount = 0; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 99b6825281c..fa5612510e2 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -972,10 +972,10 @@ module ts { } export interface InferenceContext { - typeParameters: TypeParameter[]; - inferenceCount: number; - inferences: Type[][]; - inferredTypes: Type[]; + typeParameters: TypeParameter[]; // Type parameters for which inferences are made + inferenceCount: number; // Incremented for every inference made (whether new or not) + inferences: Type[][]; // Inferences made for each type parameter + inferredTypes: Type[]; // Inferred type for each type parameter } export interface DiagnosticMessage { From 4f4f59a78165dfec2cfcb57cd823009840597315 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 13 Oct 2014 14:06:16 -0700 Subject: [PATCH 23/23] Merge changes from master in services.ts --- src/compiler/checker.ts | 1 - src/compiler/types.ts | 1 - src/services/services.ts | 68 +++++++------------ .../bestCommonTypeObjectLiterals1.ts | 13 +++- .../completionEntryForUnionProperty.ts | 4 +- .../completionEntryForUnionProperty2.ts | 2 +- .../contextualTypingOfArrayLiterals1.ts | 4 +- .../genericTypeArgumentInference1.ts | 6 +- .../genericTypeArgumentInference2.ts | 4 +- .../fourslash/quickinfoForUnionProperty.ts | 6 +- 10 files changed, 49 insertions(+), 60 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a3edc699821..5544253b944 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -94,7 +94,6 @@ module ts { symbolToString: symbolToString, writeSymbol: writeSymbol, getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType, - getRootSymbol: getRootSymbol, getRootSymbols: getRootSymbols, getContextualType: getContextualType, getFullyQualifiedName: getFullyQualifiedName, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5534c908d70..3b25f6b4a6b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -653,7 +653,6 @@ module ts { writeSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void; getFullyQualifiedName(symbol: Symbol): string; getAugmentedPropertiesOfApparentType(type: Type): Symbol[]; - getRootSymbol(symbol: Symbol): Symbol; getRootSymbols(symbol: Symbol): Symbol[]; getContextualType(node: Node): Type; getResolvedSignature(node: CallExpression, candidatesOutArray?: Signature[]): Signature; diff --git a/src/services/services.ts b/src/services/services.ts index 13f6b390d4b..96aff32cb74 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2259,9 +2259,13 @@ module ts { return undefined; } + // TODO(drosen): Right now we just permit *all* semantic meanings when calling 'getSymbolKind' + // which is permissible given that it is backwards compatible; but really we should consider + // passing the meaning for the node so that we don't report that a suggestion for a value is an interface. + // We COULD also just do what 'getSymbolModifiers' does, which is to use the first declaration. return { name: displayName, - kind: getSymbolKind(symbol), + kind: getSymbolKind(symbol, SemanticMeaning.All), kindModifiers: getSymbolModifiers(symbol) }; } @@ -2613,7 +2617,7 @@ module ts { // which is permissible given that it is backwards compatible; but really we should consider // passing the meaning for the node so that we don't report that a suggestion for a value is an interface. // We COULD also just do what 'getSymbolModifiers' does, which is to use the first declaration. - var displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getSourceFile(filename), session.location, session.typeChecker, session.location); + var displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getSourceFile(filename), session.location, session.typeChecker, session.location, SemanticMeaning.All); return { name: entryName, kind: displayPartsDocumentationsAndSymbolKind.symbolKind, @@ -2656,15 +2660,19 @@ module ts { } } - // TODO(drosen): use contextual SemanticMeaning. - function getSymbolKind(symbol: Symbol): string { + function getSymbolKind(symbol: Symbol, meaningAtLocation: SemanticMeaning): string { var flags = typeInfoResolver.getRootSymbols(symbol)[0].getFlags(); if (flags & SymbolFlags.Class) return ScriptElementKind.classElement; if (flags & SymbolFlags.Enum) return ScriptElementKind.enumElement; - if (flags & SymbolFlags.Interface) return ScriptElementKind.interfaceElement; - if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement; - + + // The following should only apply if encountered at a type position, + // and need to have precedence over other meanings if this is the case. + if (meaningAtLocation & SemanticMeaning.Type) { + if (flags & SymbolFlags.Interface) return ScriptElementKind.interfaceElement; + if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement; + } + var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags); if (result === ScriptElementKind.unknown) { if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement; @@ -2737,15 +2745,13 @@ module ts { : ScriptElementKindModifier.none; } - // TODO(drosen): use contextual SemanticMeaning. - function getSymbolDisplayPartsDocumentationAndSymbolKind(symbol: Symbol, - sourceFile: SourceFile, - enclosingDeclaration: Node, - typeResolver: TypeChecker, - location: Node) { + function getSymbolDisplayPartsDocumentationAndSymbolKind(symbol: Symbol, sourceFile: SourceFile, enclosingDeclaration: Node, + typeResolver: TypeChecker, location: Node, + // TODO(drosen): Currently completion entry details passes the SemanticMeaning.All instead of using semanticMeaning of location + semanticMeaning = getMeaningFromLocation(location)) { var displayParts: SymbolDisplayPart[] = []; var documentation: SymbolDisplayPart[]; - var symbolFlags = typeResolver.getRootSymbol(symbol).flags; + var symbolFlags = typeResolver.getRootSymbols(symbol)[0].flags; var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags); var hasAddedSymbolInfo: boolean; // Class at constructor site need to be shown as constructor apart from property,method, vars @@ -2847,14 +2853,13 @@ module ts { } } } - if (symbolFlags & SymbolFlags.Class && !hasAddedSymbolInfo) { displayParts.push(keywordPart(SyntaxKind.ClassKeyword)); displayParts.push(spacePart()); displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments)); writeTypeParametersOfSymbol(symbol, sourceFile); } - if (symbolFlags & SymbolFlags.Interface) { + if ((symbolFlags & SymbolFlags.Interface) && (semanticMeaning & SemanticMeaning.Type)) { addNewLineIfDisplayPartsExist(); displayParts.push(keywordPart(SyntaxKind.InterfaceKeyword)); displayParts.push(spacePart()); @@ -2873,7 +2878,7 @@ module ts { displayParts.push(spacePart()); displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile)); } - if (symbolFlags & SymbolFlags.TypeParameter) { + if ((symbolFlags & SymbolFlags.TypeParameter) && (semanticMeaning & SemanticMeaning.Type)) { addNewLineIfDisplayPartsExist(); displayParts.push(punctuationPart(SyntaxKind.OpenParenToken)); displayParts.push(textPart("type parameter")); @@ -2953,7 +2958,7 @@ module ts { } } else { - symbolKind = getSymbolKind(symbol); + symbolKind = getSymbolKind(symbol, semanticMeaning); } } @@ -3015,7 +3020,6 @@ module ts { var symbol = typeInfoResolver.getSymbolInfo(node); if (!symbol) { - // Try getting just type at this position and show switch (node.kind) { case SyntaxKind.Identifier: @@ -3107,25 +3111,6 @@ module ts { return false; } - function getDefinitionFromSymbol(symbol: Symbol, location: Node, result: DefinitionInfo[]): void { - var declarations = symbol.getDeclarations(); - if (declarations) { - var symbolName = typeInfoResolver.symbolToString(symbol); // Do not get scoped name, just the name of the symbol - var symbolKind = getSymbolKind(symbol); - var containerSymbol = symbol.parent; - var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, location) : ""; - var containerKind = containerSymbol ? getSymbolKind(symbol) : ""; - - if (!tryAddConstructSignature(symbol, location, symbolKind, symbolName, containerName, result) && - !tryAddCallSignature(symbol, location, symbolKind, symbolName, containerName, result)) { - // Just add all the declarations. - forEach(declarations, declaration => { - result.push(getDefinitionInfo(declaration, symbolKind, symbolName, containerName)); - }); - } - } - } - synchronizeHostData(); filename = TypeScript.switchToForwardSlashes(filename); @@ -3173,7 +3158,7 @@ module ts { var declarations = symbol.getDeclarations(); var symbolName = typeInfoResolver.symbolToString(symbol); // Do not get scoped name, just the name of the symbol - var symbolKind = getSymbolKind(symbol); + var symbolKind = getSymbolKind(symbol, getMeaningFromLocation(node)); var containerSymbol = symbol.parent; var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, node) : ""; @@ -4703,7 +4688,6 @@ module ts { function classifySymbol(symbol: Symbol, meaningAtPosition: SemanticMeaning) { var flags = symbol.getFlags(); - // TODO(drosen): use meaningAtPosition. if (flags & SymbolFlags.Class) { return ClassificationTypeNames.className; } @@ -4721,8 +4705,6 @@ module ts { else if (flags & SymbolFlags.Module) { return ClassificationTypeNames.moduleName; } - - return undefined; } function processNode(node: Node) { @@ -5192,7 +5174,7 @@ module ts { // Only allow a symbol to be renamed if it actually has at least one declaration. if (symbol && symbol.getDeclarations() && symbol.getDeclarations().length > 0) { - var kind = getSymbolKind(symbol); + var kind = getSymbolKind(symbol, getMeaningFromLocation(node)); if (kind) { return getRenameInfo(symbol.name, typeInfoResolver.getFullyQualifiedName(symbol), kind, getSymbolModifiers(symbol), diff --git a/tests/cases/fourslash/bestCommonTypeObjectLiterals1.ts b/tests/cases/fourslash/bestCommonTypeObjectLiterals1.ts index 1632fff5df8..917ed526d69 100644 --- a/tests/cases/fourslash/bestCommonTypeObjectLiterals1.ts +++ b/tests/cases/fourslash/bestCommonTypeObjectLiterals1.ts @@ -28,10 +28,19 @@ goTo.marker('2'); verify.quickInfoIs('(var) c1: {\n name: string;\n age: number;\n}[]'); goTo.marker('3'); -verify.quickInfoIs('(var) c2: {}[]'); +verify.quickInfoIs('(var) c2: Array<{\n\ + name: string;\n\ + age: number;\n\ + address: string;\n\ +} | {\n\ + name: string;\n\ + age: number;\n\ + dob: Date;\n\ +}>'); goTo.marker('4'); verify.quickInfoIs('(var) c2a: {\n name: string;\n age: number;\n}[]'); goTo.marker('5'); -verify.quickInfoIs('(var) c3: I[]'); \ No newline at end of file +verify.quickInfoIs('(var) c3: I[]'); + diff --git a/tests/cases/fourslash/completionEntryForUnionProperty.ts b/tests/cases/fourslash/completionEntryForUnionProperty.ts index 6d5a3627a9c..bc0f9405a1b 100644 --- a/tests/cases/fourslash/completionEntryForUnionProperty.ts +++ b/tests/cases/fourslash/completionEntryForUnionProperty.ts @@ -15,6 +15,6 @@ ////x./**/ goTo.marker(); -verify.memberListContains("commonProperty", "string | number", undefined, undefined, "property"); -verify.memberListContains("commonFunction", "() => number", undefined, undefined, "method"); +verify.memberListContains("commonProperty", "(property) commonProperty: string | number"); +verify.memberListContains("commonFunction", "(method) commonFunction(): number"); verify.memberListCount(2); \ No newline at end of file diff --git a/tests/cases/fourslash/completionEntryForUnionProperty2.ts b/tests/cases/fourslash/completionEntryForUnionProperty2.ts index fef5e0dfb50..b32e6d05345 100644 --- a/tests/cases/fourslash/completionEntryForUnionProperty2.ts +++ b/tests/cases/fourslash/completionEntryForUnionProperty2.ts @@ -15,5 +15,5 @@ ////x.commonProperty./**/ goTo.marker(); -verify.memberListContains("toString", "() => string", undefined, undefined, "method"); +verify.memberListContains("toString", "(method) toString(): string"); verify.memberListCount(1); \ No newline at end of file diff --git a/tests/cases/fourslash/contextualTypingOfArrayLiterals1.ts b/tests/cases/fourslash/contextualTypingOfArrayLiterals1.ts index 9e59d21c53b..128f801300b 100644 --- a/tests/cases/fourslash/contextualTypingOfArrayLiterals1.ts +++ b/tests/cases/fourslash/contextualTypingOfArrayLiterals1.ts @@ -43,7 +43,7 @@ goTo.marker('4'); verify.quickInfoIs('(var) r4: C'); goTo.marker('5'); -verify.quickInfoIs('(var) x5: {\n name: string;\n age: number;\n}[]'); +verify.quickInfoIs('(var) x5: C[]'); goTo.marker('6'); -verify.quickInfoIs('(var) r5: {\n name: string;\n age: number;\n}'); \ No newline at end of file +verify.quickInfoIs('(var) r5: C'); \ No newline at end of file diff --git a/tests/cases/fourslash/genericTypeArgumentInference1.ts b/tests/cases/fourslash/genericTypeArgumentInference1.ts index 96d603b939c..eadec7ad0ce 100644 --- a/tests/cases/fourslash/genericTypeArgumentInference1.ts +++ b/tests/cases/fourslash/genericTypeArgumentInference1.ts @@ -18,9 +18,9 @@ ////var /*4*/r4 = _./*41*/all([true], _.identity); goTo.marker('1'); -verify.quickInfoIs('(var) r: {}'); +verify.quickInfoIs('(var) r: string | number | boolean'); goTo.marker('11'); -verify.quickInfoIs('(method) Underscore.Static.all<{}>(list: {}[], iterator?: Underscore.Iterator<{}, boolean>, context?: any): {}'); +verify.quickInfoIs('(method) Underscore.Static.all(list: Array, iterator?: Underscore.Iterator, context?: any): string | number | boolean'); goTo.marker('2'); verify.quickInfoIs('(var) r2: boolean'); @@ -37,4 +37,4 @@ verify.quickInfoIs('(var) r4: any'); goTo.marker('41'); verify.quickInfoIs('(method) Underscore.Static.all(list: any[], iterator?: Underscore.Iterator, context?: any): any'); -verify.numberOfErrorsInCurrentFile(0); +verify.numberOfErrorsInCurrentFile(0); \ No newline at end of file diff --git a/tests/cases/fourslash/genericTypeArgumentInference2.ts b/tests/cases/fourslash/genericTypeArgumentInference2.ts index 0ae5114b133..a660675c51e 100644 --- a/tests/cases/fourslash/genericTypeArgumentInference2.ts +++ b/tests/cases/fourslash/genericTypeArgumentInference2.ts @@ -18,9 +18,9 @@ ////var /*4*/r4 = _./*41*/all([true], _.identity); goTo.marker('1'); -verify.quickInfoIs('(var) r: {}'); +verify.quickInfoIs('(var) r: string | number | boolean'); goTo.marker('11'); -verify.quickInfoIs('(method) Underscore.Static.all<{}>(list: {}[], iterator?: Underscore.Iterator<{}, boolean>, context?: any): {}'); +verify.quickInfoIs('(method) Underscore.Static.all(list: Array, iterator?: Underscore.Iterator, context?: any): string | number | boolean'); goTo.marker('2'); verify.quickInfoIs('(var) r2: boolean'); diff --git a/tests/cases/fourslash/quickinfoForUnionProperty.ts b/tests/cases/fourslash/quickinfoForUnionProperty.ts index 665d03f9435..b5c7dc0a01c 100644 --- a/tests/cases/fourslash/quickinfoForUnionProperty.ts +++ b/tests/cases/fourslash/quickinfoForUnionProperty.ts @@ -17,11 +17,11 @@ goTo.marker("1"); -verify.quickInfoIs("One | Two", "", "x", "var"); +verify.quickInfoIs('(var) x: One | Two'); goTo.marker("2"); -verify.quickInfoIs("string | number", "", "commonProperty", "property"); +verify.quickInfoIs('(property) commonProperty: string | number'); goTo.marker("3"); -verify.quickInfoIs("() => number", "", "commonFunction", "method"); +verify.quickInfoIs('(method) commonFunction(): number');