diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0ca8f26513097..b53ec9febb0a5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6901,7 +6901,7 @@ namespace ts { function getConstraintOfIndexedAccess(type: IndexedAccessType) { const objectType = getBaseConstraintOfType(type.objectType) || type.objectType; const indexType = getBaseConstraintOfType(type.indexType) || type.indexType; - const constraint = !isGenericObjectType(objectType) && !isGenericIndexType(indexType) ? getIndexedAccessType(objectType, indexType) : undefined; + const constraint = !isGenericObjectType(objectType) && !isGenericIndexType(indexType) ? getIndexedAccessType(objectType, indexType, /*accessNode*/ undefined, errorType) : undefined; return constraint && constraint !== errorType ? constraint : undefined; } @@ -7064,7 +7064,7 @@ namespace ts { if (t.flags & TypeFlags.IndexedAccess) { const baseObjectType = getBaseConstraint((t).objectType); const baseIndexType = getBaseConstraint((t).indexType); - const baseIndexedAccess = baseObjectType && baseIndexType ? getIndexedAccessType(baseObjectType, baseIndexType) : undefined; + const baseIndexedAccess = baseObjectType && baseIndexType ? getIndexedAccessType(baseObjectType, baseIndexType, /*accessNode*/ undefined, errorType) : undefined; return baseIndexedAccess && baseIndexedAccess !== errorType ? getBaseConstraint(baseIndexedAccess) : undefined; } if (t.flags & TypeFlags.Conditional) { @@ -9149,7 +9149,7 @@ namespace ts { return false; } - function getPropertyTypeForIndexType(objectType: Type, indexType: Type, accessNode: ElementAccessExpression | IndexedAccessTypeNode | undefined, cacheSymbol: boolean) { + function getPropertyTypeForIndexType(objectType: Type, indexType: Type, accessNode: ElementAccessExpression | IndexedAccessTypeNode | undefined, cacheSymbol: boolean, missingType: Type) { const accessExpression = accessNode && accessNode.kind === SyntaxKind.ElementAccessExpression ? accessNode : undefined; const propName = isTypeUsableAsLateBoundName(indexType) ? getLateBoundNameFromType(indexType) : accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ? @@ -9162,7 +9162,7 @@ namespace ts { markPropertyAsReferenced(prop, accessExpression, /*isThisAccess*/ accessExpression.expression.kind === SyntaxKind.ThisKeyword); if (isAssignmentTarget(accessExpression) && (isReferenceToReadonlyEntity(accessExpression, prop) || isReferenceThroughNamespaceImport(accessExpression))) { error(accessExpression.argumentExpression, Diagnostics.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, symbolToString(prop)); - return errorType; + return missingType; } if (cacheSymbol) { getNodeLinks(accessNode!).resolvedSymbol = prop; @@ -9221,7 +9221,7 @@ namespace ts { } } } - return anyType; + return missingType; } } if (isJSLiteralType(objectType)) { @@ -9239,7 +9239,10 @@ namespace ts { error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType)); } } - return errorType; + if (isTypeAny(indexType)) { + return indexType; + } + return missingType; } function isGenericObjectType(type: Type): boolean { @@ -9250,22 +9253,6 @@ namespace ts { return maybeTypeOfKind(type, TypeFlags.InstantiableNonPrimitive | TypeFlags.Index); } - // Return true if the given type is a non-generic object type with a string index signature and no - // other members. - function isStringIndexOnlyType(type: Type): boolean { - if (type.flags & TypeFlags.Object && !isGenericMappedType(type)) { - const t = resolveStructuredTypeMembers(type); - return t.properties.length === 0 && - t.callSignatures.length === 0 && t.constructSignatures.length === 0 && - !!t.stringIndexInfo && !t.numberIndexInfo; - } - return false; - } - - function isMappedTypeToNever(type: Type): boolean { - return !!(getObjectFlags(type) & ObjectFlags.Mapped) && getTemplateTypeFromMappedType(type as MappedType) === neverType; - } - function getSimplifiedType(type: Type): Type { return type.flags & TypeFlags.IndexedAccess ? getSimplifiedIndexedAccessType(type) : type; } @@ -9280,35 +9267,12 @@ namespace ts { // We recursively simplify the object type as it may in turn be an indexed access type. For example, with // '{ [P in T]: { [Q in U]: number } }[T][U]' we want to first simplify the inner indexed access type. const objectType = getSimplifiedType(type.objectType); - if (objectType.flags & TypeFlags.Intersection && isGenericObjectType(objectType)) { - // Given an indexed access type T[K], if T is an intersection containing one or more generic types and one or - // more object types with only a string index signature, e.g. '(U & V & { [x: string]: D })[K]', return a - // transformed type of the form '(U & V)[K] | D'. This allows us to properly reason about higher order indexed - // access types with default property values as expressed by D. - if (some((objectType).types, isStringIndexOnlyType)) { - const regularTypes: Type[] = []; - const stringIndexTypes: Type[] = []; - for (const t of (objectType).types) { - if (isStringIndexOnlyType(t)) { - stringIndexTypes.push(getIndexTypeOfType(t, IndexKind.String)!); - } - else { - regularTypes.push(t); - } - } - return type.simplified = getUnionType([ - getSimplifiedType(getIndexedAccessType(getIntersectionType(regularTypes), type.indexType)), - getIntersectionType(stringIndexTypes) - ]); - } - // Given an indexed access type T[K], if T is an intersection containing one or more generic types and one or - // more mapped types with a template type `never`, '(U & V & { [P in T]: never })[K]', return a - // transformed type that removes the never-mapped type: '(U & V)[K]'. This mirrors what would happen - // eventually anyway, but it easier to reason about. - if (some((objectType).types, isMappedTypeToNever)) { - const nonNeverTypes = filter((objectType).types, t => !isMappedTypeToNever(t)); - return type.simplified = getSimplifiedType(getIndexedAccessType(getIntersectionType(nonNeverTypes), type.indexType)); - } + const indexType = getSimplifiedType(type.indexType); + if (objectType.flags & TypeFlags.Union) { + return type.simplified = mapType(objectType, t => getSimplifiedType(getIndexedAccessType(t, indexType))); + } + if (objectType.flags & TypeFlags.Intersection) { + return type.simplified = getIntersectionType(map((objectType as IntersectionType).types, t => getSimplifiedType(getIndexedAccessType(t, indexType)))); } // If the object type is a mapped type { [P in K]: E }, where K is generic, instantiate E using a mapper // that substitutes the index type for P. For example, for an index access { [P in K]: Box }[X], we @@ -9332,7 +9296,7 @@ namespace ts { return instantiateType(getTemplateTypeFromMappedType(objectType), templateMapper); } - function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode): Type { + function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode, missingType = accessNode ? errorType : unknownType): Type { if (objectType === wildcardType || indexType === wildcardType) { return wildcardType; } @@ -9360,15 +9324,15 @@ namespace ts { if (indexType.flags & TypeFlags.Union && !(indexType.flags & TypeFlags.Boolean)) { const propTypes: Type[] = []; for (const t of (indexType).types) { - const propType = getPropertyTypeForIndexType(apparentObjectType, t, accessNode, /*cacheSymbol*/ false); - if (propType === errorType) { - return errorType; + const propType = getPropertyTypeForIndexType(apparentObjectType, t, accessNode, /*cacheSymbol*/ false, missingType); + if (propType === missingType) { + return missingType; } propTypes.push(propType); } return getUnionType(propTypes); } - return getPropertyTypeForIndexType(apparentObjectType, indexType, accessNode, /*cacheSymbol*/ true); + return getPropertyTypeForIndexType(apparentObjectType, indexType, accessNode, /*cacheSymbol*/ true, missingType); } function getTypeFromIndexedAccessTypeNode(node: IndexedAccessTypeNode) { @@ -10532,8 +10496,12 @@ namespace ts { return false; } + function isOrHasGenericConditional(type: Type): boolean { + return !!(type.flags & TypeFlags.Conditional || (type.flags & TypeFlags.Intersection && some((type as IntersectionType).types, isOrHasGenericConditional))); + } + function elaborateError(node: Expression | undefined, source: Type, target: Type): boolean { - if (!node) return false; + if (!node || isOrHasGenericConditional(target)) return false; switch (node.kind) { case SyntaxKind.JsxExpression: case SyntaxKind.ParenthesizedExpression: @@ -10566,9 +10534,9 @@ namespace ts { let reportedError = false; for (let status = iterator.next(); !status.done; status = iterator.next()) { const { errorNode: prop, innerExpression: next, nameType, errorMessage } = status.value; - const sourcePropType = getIndexedAccessType(source, nameType); - const targetPropType = getIndexedAccessType(target, nameType); - if (!isTypeAssignableTo(sourcePropType, targetPropType)) { + const sourcePropType = getIndexedAccessType(source, nameType, /*accessNode*/ undefined, errorType); + const targetPropType = getIndexedAccessType(target, nameType, /*accessNode*/ undefined, errorType); + if (sourcePropType !== errorType && targetPropType !== errorType && !isTypeAssignableTo(sourcePropType, targetPropType)) { const elaborated = next && elaborateError(next, sourcePropType, targetPropType); if (elaborated) { reportedError = true; @@ -11287,7 +11255,7 @@ namespace ts { function isIdenticalTo(source: Type, target: Type): Ternary { let result: Ternary; const flags = source.flags & target.flags; - if (flags & TypeFlags.Object) { + if (flags & TypeFlags.Object || flags & TypeFlags.IndexedAccess || flags & TypeFlags.Conditional || flags & TypeFlags.Index || flags & TypeFlags.Substitution) { return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false); } if (flags & (TypeFlags.Union | TypeFlags.Intersection)) { @@ -11297,32 +11265,6 @@ namespace ts { } } } - if (flags & TypeFlags.Index) { - return isRelatedTo((source).type, (target).type, /*reportErrors*/ false); - } - if (flags & TypeFlags.IndexedAccess) { - if (result = isRelatedTo((source).objectType, (target).objectType, /*reportErrors*/ false)) { - if (result &= isRelatedTo((source).indexType, (target).indexType, /*reportErrors*/ false)) { - return result; - } - } - } - if (flags & TypeFlags.Conditional) { - if ((source).root.isDistributive === (target).root.isDistributive) { - if (result = isRelatedTo((source).checkType, (target).checkType, /*reportErrors*/ false)) { - if (result &= isRelatedTo((source).extendsType, (target).extendsType, /*reportErrors*/ false)) { - if (result &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), /*reportErrors*/ false)) { - if (result &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), /*reportErrors*/ false)) { - return result; - } - } - } - } - } - } - if (flags & TypeFlags.Substitution) { - return isRelatedTo((source).substitute, (target).substitute, /*reportErrors*/ false); - } return Ternary.False; } @@ -11634,6 +11576,37 @@ namespace ts { } function structuredTypeRelatedTo(source: Type, target: Type, reportErrors: boolean): Ternary { + const flags = source.flags & target.flags; + if (relation === identityRelation && !(flags & TypeFlags.Object)) { + if (flags & TypeFlags.Index) { + return isRelatedTo((source).type, (target).type, /*reportErrors*/ false); + } + let result = Ternary.False; + if (flags & TypeFlags.IndexedAccess) { + if (result = isRelatedTo((source).objectType, (target).objectType, /*reportErrors*/ false)) { + if (result &= isRelatedTo((source).indexType, (target).indexType, /*reportErrors*/ false)) { + return result; + } + } + } + if (flags & TypeFlags.Conditional) { + if ((source).root.isDistributive === (target).root.isDistributive) { + if (result = isRelatedTo((source).checkType, (target).checkType, /*reportErrors*/ false)) { + if (result &= isRelatedTo((source).extendsType, (target).extendsType, /*reportErrors*/ false)) { + if (result &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), /*reportErrors*/ false)) { + if (result &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), /*reportErrors*/ false)) { + return result; + } + } + } + } + } + } + if (flags & TypeFlags.Substitution) { + return isRelatedTo((source).substitute, (target).substitute, /*reportErrors*/ false); + } + return Ternary.False; + } let result: Ternary; let originalErrorInfo: DiagnosticMessageChain | undefined; const saveErrorInfo = errorInfo; @@ -14149,10 +14122,10 @@ namespace ts { getInitialTypeOfBindingElement(node); } - function getInitialOrAssignedType(node: VariableDeclaration | BindingElement | Expression) { - return node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement ? + function getInitialOrAssignedType(node: VariableDeclaration | BindingElement | Expression, reference: Node) { + return getConstraintForLocation(node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement ? getInitialType(node) : - getAssignedType(node); + getAssignedType(node), reference); } function isEmptyArrayAssignment(node: VariableDeclaration | BindingElement | Expression) { @@ -14538,11 +14511,11 @@ namespace ts { if (isEmptyArrayAssignment(node)) { return getEvolvingArrayType(neverType); } - const assignedType = getBaseTypeOfLiteralType(getInitialOrAssignedType(node)); + const assignedType = getBaseTypeOfLiteralType(getInitialOrAssignedType(node, reference)); return isTypeAssignableTo(assignedType, declaredType) ? assignedType : anyArrayType; } if (declaredType.flags & TypeFlags.Union) { - return getAssignmentReducedType(declaredType, getInitialOrAssignedType(node)); + return getAssignmentReducedType(declaredType, getInitialOrAssignedType(node, reference)); } return declaredType; } diff --git a/tests/baselines/reference/assignmentCompatForEnums.types b/tests/baselines/reference/assignmentCompatForEnums.types index 8d2fdf0a8b3bd..6ad83f3d75e8a 100644 --- a/tests/baselines/reference/assignmentCompatForEnums.types +++ b/tests/baselines/reference/assignmentCompatForEnums.types @@ -23,7 +23,7 @@ function foo() { var x: TokenType = list['one']; >x : TokenType ->list['one'] : any +>list['one'] : error >list : {} >'one' : "one" } diff --git a/tests/baselines/reference/augmentedTypeBracketAccessIndexSignature.types b/tests/baselines/reference/augmentedTypeBracketAccessIndexSignature.types index eb23cfaa9e6a1..62e04728b390d 100644 --- a/tests/baselines/reference/augmentedTypeBracketAccessIndexSignature.types +++ b/tests/baselines/reference/augmentedTypeBracketAccessIndexSignature.types @@ -16,14 +16,14 @@ interface Function { } var a = {}[0]; // Should be Foo ->a : any ->{}[0] : any +>a : error +>{}[0] : error >{} : {} >0 : 0 var b = (() => { })[0]; // Should be Bar ->b : any ->(() => { })[0] : any +>b : error +>(() => { })[0] : error >(() => { }) : () => void >() => { } : () => void >0 : 0 diff --git a/tests/baselines/reference/augmentedTypeBracketNamedPropertyAccess.types b/tests/baselines/reference/augmentedTypeBracketNamedPropertyAccess.types index eb90adefde2de..8129150648594 100644 --- a/tests/baselines/reference/augmentedTypeBracketNamedPropertyAccess.types +++ b/tests/baselines/reference/augmentedTypeBracketNamedPropertyAccess.types @@ -22,8 +22,8 @@ var r1 = o['data']; // Should be number >'data' : "data" var r2 = o['functionData']; // Should be any (no property found) ->r2 : any ->o['functionData'] : any +>r2 : error +>o['functionData'] : error >o : {} >'functionData' : "functionData" diff --git a/tests/baselines/reference/binaryIntegerLiteral.types b/tests/baselines/reference/binaryIntegerLiteral.types index 070ae22d79661..1e2fc019e5f14 100644 --- a/tests/baselines/reference/binaryIntegerLiteral.types +++ b/tests/baselines/reference/binaryIntegerLiteral.types @@ -79,7 +79,7 @@ obj1["26"]; // string >"26" : "26" obj1["0b11010"]; // any ->obj1["0b11010"] : any +>obj1["0b11010"] : error >obj1 : { 0b11010: string; a: number; bin1: number; b: number; 0B111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; } >"0b11010" : "0b11010" @@ -119,7 +119,7 @@ obj2["26"]; // string >"26" : "26" obj2["0B11010"]; // any ->obj2["0B11010"] : any +>obj2["0B11010"] : error >obj2 : { 0B11010: string; a: number; bin2: number; b: number; 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; } >"0B11010" : "0B11010" @@ -149,7 +149,7 @@ obj2["9.671406556917009e+24"]; // boolean >"9.671406556917009e+24" : "9.671406556917009e+24" obj2["Infinity"]; // any ->obj2["Infinity"] : any +>obj2["Infinity"] : error >obj2 : { 0B11010: string; a: number; bin2: number; b: number; 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; } >"Infinity" : "Infinity" diff --git a/tests/baselines/reference/binaryIntegerLiteralES6.types b/tests/baselines/reference/binaryIntegerLiteralES6.types index fe9f65a1f7163..78de8bd9fbc7e 100644 --- a/tests/baselines/reference/binaryIntegerLiteralES6.types +++ b/tests/baselines/reference/binaryIntegerLiteralES6.types @@ -79,7 +79,7 @@ obj1["26"]; // string >"26" : "26" obj1["0b11010"]; // any ->obj1["0b11010"] : any +>obj1["0b11010"] : error >obj1 : { 0b11010: string; a: number; bin1: number; b: number; 0B111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; } >"0b11010" : "0b11010" @@ -119,7 +119,7 @@ obj2["26"]; // string >"26" : "26" obj2["0B11010"]; // any ->obj2["0B11010"] : any +>obj2["0B11010"] : error >obj2 : { 0B11010: string; a: number; bin2: number; b: number; 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; } >"0B11010" : "0B11010" @@ -149,7 +149,7 @@ obj2["9.671406556917009e+24"]; // boolean >"9.671406556917009e+24" : "9.671406556917009e+24" obj2["Infinity"]; // any ->obj2["Infinity"] : any +>obj2["Infinity"] : error >obj2 : { 0B11010: string; a: number; bin2: number; b: number; 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: boolean; } >"Infinity" : "Infinity" diff --git a/tests/baselines/reference/circularlySimplifyingConditionalTypesNoCrash.js b/tests/baselines/reference/circularlySimplifyingConditionalTypesNoCrash.js new file mode 100644 index 0000000000000..724a8f8dbeadb --- /dev/null +++ b/tests/baselines/reference/circularlySimplifyingConditionalTypesNoCrash.js @@ -0,0 +1,55 @@ +//// [circularlySimplifyingConditionalTypesNoCrash.ts] +type Omit = Pick>; + +type Shared< // Circularly self constraining type, defered thanks to mapping + InjectedProps, + DecorationTargetProps extends Shared + > = { + [P in Extract]: InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : never; + }; + +interface ComponentClass

{ + defaultProps?: Partial

; // Inference target is also mapped _and_ optional +} + +interface InferableComponentEnhancerWithProps { +

>( + component: ComponentClass

+ ): ComponentClass> & TNeedsProps> & { WrappedComponent: ComponentClass

} +} // Then intersected with and indexed via Omit and & + +interface Connect { // Then strictly compared with another signature in its context + ( + mapStateToProps: unknown, + ): InferableComponentEnhancerWithProps; + + ( + mapStateToProps: null | undefined, + mapDispatchToProps: unknown, + mergeProps: null | undefined, + options: unknown + ): InferableComponentEnhancerWithProps; +} + +declare var connect: Connect; + +const myStoreConnect: Connect = function( + mapStateToProps?: any, + mapDispatchToProps?: any, + mergeProps?: any, + options: unknown = {}, +) { + return connect( + mapStateToProps, + mapDispatchToProps, + mergeProps, + options, + ); +}; + +//// [circularlySimplifyingConditionalTypesNoCrash.js] +"use strict"; +var myStoreConnect = function (mapStateToProps, mapDispatchToProps, mergeProps, options) { + if (options === void 0) { options = {}; } + return connect(mapStateToProps, mapDispatchToProps, mergeProps, options); +}; diff --git a/tests/baselines/reference/circularlySimplifyingConditionalTypesNoCrash.symbols b/tests/baselines/reference/circularlySimplifyingConditionalTypesNoCrash.symbols new file mode 100644 index 0000000000000..97abdadf2b39e --- /dev/null +++ b/tests/baselines/reference/circularlySimplifyingConditionalTypesNoCrash.symbols @@ -0,0 +1,154 @@ +=== tests/cases/compiler/circularlySimplifyingConditionalTypesNoCrash.ts === +type Omit = Pick>; +>Omit : Symbol(Omit, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 0)) +>T : Symbol(T, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 10)) +>K : Symbol(K, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 12)) +>T : Symbol(T, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 10)) +>Pick : Symbol(Pick, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 10)) +>Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 10)) +>K : Symbol(K, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 12)) + +type Shared< // Circularly self constraining type, defered thanks to mapping +>Shared : Symbol(Shared, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 63)) + + InjectedProps, +>InjectedProps : Symbol(InjectedProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 2, 12)) + + DecorationTargetProps extends Shared +>DecorationTargetProps : Symbol(DecorationTargetProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 3, 18)) +>Shared : Symbol(Shared, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 63)) +>InjectedProps : Symbol(InjectedProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 2, 12)) +>DecorationTargetProps : Symbol(DecorationTargetProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 3, 18)) + + > = { + [P in Extract]: InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : never; +>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 6, 9)) +>Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --)) +>InjectedProps : Symbol(InjectedProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 2, 12)) +>DecorationTargetProps : Symbol(DecorationTargetProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 3, 18)) +>InjectedProps : Symbol(InjectedProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 2, 12)) +>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 6, 9)) +>DecorationTargetProps : Symbol(DecorationTargetProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 3, 18)) +>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 6, 9)) +>DecorationTargetProps : Symbol(DecorationTargetProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 3, 18)) +>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 6, 9)) + + }; + +interface ComponentClass

{ +>ComponentClass : Symbol(ComponentClass, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 7, 6)) +>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 9, 25)) + + defaultProps?: Partial

; // Inference target is also mapped _and_ optional +>defaultProps : Symbol(ComponentClass.defaultProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 9, 29)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 9, 25)) +} + +interface InferableComponentEnhancerWithProps { +>InferableComponentEnhancerWithProps : Symbol(InferableComponentEnhancerWithProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 11, 1)) +>TInjectedProps : Symbol(TInjectedProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 13, 46)) +>TNeedsProps : Symbol(TNeedsProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 13, 61)) + +

>( +>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 14, 5)) +>Shared : Symbol(Shared, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 63)) +>TInjectedProps : Symbol(TInjectedProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 13, 46)) +>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 14, 5)) + + component: ComponentClass

+>component : Symbol(component, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 14, 42)) +>ComponentClass : Symbol(ComponentClass, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 7, 6)) +>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 14, 5)) + + ): ComponentClass> & TNeedsProps> & { WrappedComponent: ComponentClass

} +>ComponentClass : Symbol(ComponentClass, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 7, 6)) +>Omit : Symbol(Omit, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 0)) +>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 14, 5)) +>Shared : Symbol(Shared, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 0, 63)) +>TInjectedProps : Symbol(TInjectedProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 13, 46)) +>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 14, 5)) +>TNeedsProps : Symbol(TNeedsProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 13, 61)) +>WrappedComponent : Symbol(WrappedComponent, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 16, 81)) +>ComponentClass : Symbol(ComponentClass, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 7, 6)) +>P : Symbol(P, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 14, 5)) + +} // Then intersected with and indexed via Omit and & + +interface Connect { // Then strictly compared with another signature in its context +>Connect : Symbol(Connect, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 17, 1)) + + ( +>TStateProps : Symbol(TStateProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 20, 5)) +>TOwnProps : Symbol(TOwnProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 20, 17)) + + mapStateToProps: unknown, +>mapStateToProps : Symbol(mapStateToProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 20, 29)) + + ): InferableComponentEnhancerWithProps; +>InferableComponentEnhancerWithProps : Symbol(InferableComponentEnhancerWithProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 11, 1)) +>TStateProps : Symbol(TStateProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 20, 5)) +>TOwnProps : Symbol(TOwnProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 20, 17)) + + ( +>TDispatchProps : Symbol(TDispatchProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 24, 5)) +>TOwnProps : Symbol(TOwnProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 24, 20)) + + mapStateToProps: null | undefined, +>mapStateToProps : Symbol(mapStateToProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 24, 32)) + + mapDispatchToProps: unknown, +>mapDispatchToProps : Symbol(mapDispatchToProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 25, 42)) + + mergeProps: null | undefined, +>mergeProps : Symbol(mergeProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 26, 36)) + + options: unknown +>options : Symbol(options, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 27, 37)) + + ): InferableComponentEnhancerWithProps; +>InferableComponentEnhancerWithProps : Symbol(InferableComponentEnhancerWithProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 11, 1)) +>TDispatchProps : Symbol(TDispatchProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 24, 5)) +>TOwnProps : Symbol(TOwnProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 24, 20)) +} + +declare var connect: Connect; +>connect : Symbol(connect, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 32, 11)) +>Connect : Symbol(Connect, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 17, 1)) + +const myStoreConnect: Connect = function( +>myStoreConnect : Symbol(myStoreConnect, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 34, 5)) +>Connect : Symbol(Connect, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 17, 1)) + + mapStateToProps?: any, +>mapStateToProps : Symbol(mapStateToProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 34, 41)) + + mapDispatchToProps?: any, +>mapDispatchToProps : Symbol(mapDispatchToProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 35, 26)) + + mergeProps?: any, +>mergeProps : Symbol(mergeProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 36, 29)) + + options: unknown = {}, +>options : Symbol(options, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 37, 21)) + +) { + return connect( +>connect : Symbol(connect, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 32, 11)) + + mapStateToProps, +>mapStateToProps : Symbol(mapStateToProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 34, 41)) + + mapDispatchToProps, +>mapDispatchToProps : Symbol(mapDispatchToProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 35, 26)) + + mergeProps, +>mergeProps : Symbol(mergeProps, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 36, 29)) + + options, +>options : Symbol(options, Decl(circularlySimplifyingConditionalTypesNoCrash.ts, 37, 21)) + + ); +}; diff --git a/tests/baselines/reference/circularlySimplifyingConditionalTypesNoCrash.types b/tests/baselines/reference/circularlySimplifyingConditionalTypesNoCrash.types new file mode 100644 index 0000000000000..4a3a1fdbe53aa --- /dev/null +++ b/tests/baselines/reference/circularlySimplifyingConditionalTypesNoCrash.types @@ -0,0 +1,92 @@ +=== tests/cases/compiler/circularlySimplifyingConditionalTypesNoCrash.ts === +type Omit = Pick>; +>Omit : Pick> + +type Shared< // Circularly self constraining type, defered thanks to mapping +>Shared : Shared + + InjectedProps, + DecorationTargetProps extends Shared + > = { + [P in Extract]: InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : never; + }; + +interface ComponentClass

{ + defaultProps?: Partial

; // Inference target is also mapped _and_ optional +>defaultProps : Partial

| undefined +} + +interface InferableComponentEnhancerWithProps { +

>( + component: ComponentClass

+>component : ComponentClass

+ + ): ComponentClass> & TNeedsProps> & { WrappedComponent: ComponentClass

} +>WrappedComponent : ComponentClass

+ +} // Then intersected with and indexed via Omit and & + +interface Connect { // Then strictly compared with another signature in its context + ( + mapStateToProps: unknown, +>mapStateToProps : unknown + + ): InferableComponentEnhancerWithProps; + + ( + mapStateToProps: null | undefined, +>mapStateToProps : null | undefined +>null : null + + mapDispatchToProps: unknown, +>mapDispatchToProps : unknown + + mergeProps: null | undefined, +>mergeProps : null | undefined +>null : null + + options: unknown +>options : unknown + + ): InferableComponentEnhancerWithProps; +} + +declare var connect: Connect; +>connect : Connect + +const myStoreConnect: Connect = function( +>myStoreConnect : Connect +>function( mapStateToProps?: any, mapDispatchToProps?: any, mergeProps?: any, options: unknown = {},) { return connect( mapStateToProps, mapDispatchToProps, mergeProps, options, );} : (mapStateToProps?: any, mapDispatchToProps?: any, mergeProps?: any, options?: unknown) => InferableComponentEnhancerWithProps<{}, {}> + + mapStateToProps?: any, +>mapStateToProps : any + + mapDispatchToProps?: any, +>mapDispatchToProps : any + + mergeProps?: any, +>mergeProps : any + + options: unknown = {}, +>options : unknown +>{} : {} + +) { + return connect( +>connect( mapStateToProps, mapDispatchToProps, mergeProps, options, ) : InferableComponentEnhancerWithProps<{}, {}> +>connect : Connect + + mapStateToProps, +>mapStateToProps : any + + mapDispatchToProps, +>mapDispatchToProps : any + + mergeProps, +>mergeProps : any + + options, +>options : unknown + + ); +}; diff --git a/tests/baselines/reference/conditionalTypesExcessProperties.errors.txt b/tests/baselines/reference/conditionalTypesExcessProperties.errors.txt index a01cb8c8986b7..54e8c8742a759 100644 --- a/tests/baselines/reference/conditionalTypesExcessProperties.errors.txt +++ b/tests/baselines/reference/conditionalTypesExcessProperties.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/types/conditional/conditionalTypesExcessProperties.ts(8,5): error TS2322: Type '{ test: string; arg: A; }' is not assignable to type 'Something'. Type '{ test: string; arg: A; }' is not assignable to type 'A extends object ? { arg: A; } : { arg?: undefined; }'. -tests/cases/conformance/types/conditional/conditionalTypesExcessProperties.ts(9,33): error TS2322: Type 'A' is not assignable to type 'Something["arr"]'. - Type 'object' is not assignable to type 'Something["arr"]'. +tests/cases/conformance/types/conditional/conditionalTypesExcessProperties.ts(9,33): error TS2322: Type '{ test: string; arg: A; arr: A; }' is not assignable to type 'Something'. + Object literal may only specify known properties, and 'arr' does not exist in type 'Something'. ==== tests/cases/conformance/types/conditional/conditionalTypesExcessProperties.ts (2 errors) ==== @@ -17,8 +17,8 @@ tests/cases/conformance/types/conditional/conditionalTypesExcessProperties.ts(9, !!! error TS2322: Type '{ test: string; arg: A; }' is not assignable to type 'Something'. !!! error TS2322: Type '{ test: string; arg: A; }' is not assignable to type 'A extends object ? { arg: A; } : { arg?: undefined; }'. sa = { test: 'bye', arg: a, arr: a } // excess - ~~~ -!!! error TS2322: Type 'A' is not assignable to type 'Something["arr"]'. -!!! error TS2322: Type 'object' is not assignable to type 'Something["arr"]'. + ~~~~~~ +!!! error TS2322: Type '{ test: string; arg: A; arr: A; }' is not assignable to type 'Something'. +!!! error TS2322: Object literal may only specify known properties, and 'arr' does not exist in type 'Something'. } \ No newline at end of file diff --git a/tests/baselines/reference/defaultIndexProps2.types b/tests/baselines/reference/defaultIndexProps2.types index a50e4af450e56..28c49de3f8915 100644 --- a/tests/baselines/reference/defaultIndexProps2.types +++ b/tests/baselines/reference/defaultIndexProps2.types @@ -23,7 +23,7 @@ var o = {v:"Yo2"}; // WScript.Echo(o[0]); 1[0]; ->1[0] : any +>1[0] : error >1 : 1 >0 : 0 diff --git a/tests/baselines/reference/deferredLookupTypeResolution2.errors.txt b/tests/baselines/reference/deferredLookupTypeResolution2.errors.txt deleted file mode 100644 index 88bcd2c434048..0000000000000 --- a/tests/baselines/reference/deferredLookupTypeResolution2.errors.txt +++ /dev/null @@ -1,31 +0,0 @@ -tests/cases/compiler/deferredLookupTypeResolution2.ts(14,13): error TS2536: Type '({ [K in Extract]: "true"; } & { [key: string]: "false"; })["1"]' cannot be used to index type '{ true: "true"; }'. -tests/cases/compiler/deferredLookupTypeResolution2.ts(19,21): error TS2536: Type '({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in Extract]: "true"; } & { [key: string]: "false"; })["1"]]' cannot be used to index type '{ true: "true"; }'. - - -==== tests/cases/compiler/deferredLookupTypeResolution2.ts (2 errors) ==== - // Repro from #17456 - - type StringContains = ({ [K in S]: 'true' } & { [key: string]: 'false'})[L]; - - type ObjectHasKey = StringContains, L>; - - type A = ObjectHasKey; - - type B = ObjectHasKey<[string, number], '1'>; // "true" - type C = ObjectHasKey<[string, number], '2'>; // "false" - type D = A<[string]>; // "true" - - // Error, "false" not handled - type E = { true: 'true' }[ObjectHasKey]; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2536: Type '({ [K in Extract]: "true"; } & { [key: string]: "false"; })["1"]' cannot be used to index type '{ true: "true"; }'. - - type Juxtapose = ({ true: 'otherwise' } & { [k: string]: 'true' })[ObjectHasKey]; - - // Error, "otherwise" is missing - type DeepError = { true: 'true' }[Juxtapose]; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2536: Type '({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in Extract]: "true"; } & { [key: string]: "false"; })["1"]]' cannot be used to index type '{ true: "true"; }'. - - type DeepOK = { true: 'true', otherwise: 'false' }[Juxtapose]; - \ No newline at end of file diff --git a/tests/baselines/reference/enumBasics.types b/tests/baselines/reference/enumBasics.types index 697d5b40f6f18..0ca967cc258fc 100644 --- a/tests/baselines/reference/enumBasics.types +++ b/tests/baselines/reference/enumBasics.types @@ -141,7 +141,7 @@ enum E7 { A = 'foo'['foo'] >A : E7 ->'foo'['foo'] : any +>'foo'['foo'] : error >'foo' : "foo" >'foo' : "foo" } @@ -152,7 +152,7 @@ enum E8 { B = 'foo'['foo'] >B : E8 ->'foo'['foo'] : any +>'foo'['foo'] : error >'foo' : "foo" >'foo' : "foo" } diff --git a/tests/baselines/reference/enumIndexer.types b/tests/baselines/reference/enumIndexer.types index 6c6e50822b517..a47e9da8c9a4d 100644 --- a/tests/baselines/reference/enumIndexer.types +++ b/tests/baselines/reference/enumIndexer.types @@ -31,7 +31,7 @@ var x = _arr.map(o => MyEnumType[o.key] === enumValue); // these are not same ty >o => MyEnumType[o.key] === enumValue : (o: { key: string; }) => boolean >o : { key: string; } >MyEnumType[o.key] === enumValue : boolean ->MyEnumType[o.key] : any +>MyEnumType[o.key] : error >MyEnumType : typeof MyEnumType >o.key : string >o : { key: string; } diff --git a/tests/baselines/reference/genericIndexedAccessMethodIntersectionCanBeAccessed.js b/tests/baselines/reference/genericIndexedAccessMethodIntersectionCanBeAccessed.js new file mode 100644 index 0000000000000..091fd6abbd0a0 --- /dev/null +++ b/tests/baselines/reference/genericIndexedAccessMethodIntersectionCanBeAccessed.js @@ -0,0 +1,31 @@ +//// [genericIndexedAccessMethodIntersectionCanBeAccessed.ts] +type ExtendedService = { + [K in keyof T]: T[K] & { + __$daemonMode?: string; + __$action?: string; + }; +}; + +type Service = { + [K in keyof T]: T[K] & {id?: string}; +}; + +export const createService = ( + ServiceCtr: ExtendedService & Service +) => { + Object.keys(ServiceCtr).forEach(key => { + const method = (ServiceCtr)[key as keyof T]; + const {__$daemonMode, __$action, id} = method; + }) +} + + +//// [genericIndexedAccessMethodIntersectionCanBeAccessed.js] +"use strict"; +exports.__esModule = true; +exports.createService = function (ServiceCtr) { + Object.keys(ServiceCtr).forEach(function (key) { + var method = (ServiceCtr)[key]; + var __$daemonMode = method.__$daemonMode, __$action = method.__$action, id = method.id; + }); +}; diff --git a/tests/baselines/reference/genericIndexedAccessMethodIntersectionCanBeAccessed.symbols b/tests/baselines/reference/genericIndexedAccessMethodIntersectionCanBeAccessed.symbols new file mode 100644 index 0000000000000..2b619c997dc54 --- /dev/null +++ b/tests/baselines/reference/genericIndexedAccessMethodIntersectionCanBeAccessed.symbols @@ -0,0 +1,69 @@ +=== tests/cases/compiler/genericIndexedAccessMethodIntersectionCanBeAccessed.ts === +type ExtendedService = { +>ExtendedService : Symbol(ExtendedService, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 0, 0)) +>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 0, 21)) + + [K in keyof T]: T[K] & { +>K : Symbol(K, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 1, 5)) +>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 0, 21)) +>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 0, 21)) +>K : Symbol(K, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 1, 5)) + + __$daemonMode?: string; +>__$daemonMode : Symbol(__$daemonMode, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 1, 28)) + + __$action?: string; +>__$action : Symbol(__$action, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 2, 31)) + + }; +}; + +type Service = { +>Service : Symbol(Service, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 5, 2)) +>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 7, 13)) + + [K in keyof T]: T[K] & {id?: string}; +>K : Symbol(K, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 8, 5)) +>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 7, 13)) +>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 7, 13)) +>K : Symbol(K, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 8, 5)) +>id : Symbol(id, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 8, 28)) + +}; + +export const createService = ( +>createService : Symbol(createService, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 11, 12)) +>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 11, 30)) + + ServiceCtr: ExtendedService & Service +>ServiceCtr : Symbol(ServiceCtr, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 11, 33)) +>ExtendedService : Symbol(ExtendedService, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 0, 0)) +>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 11, 30)) +>Service : Symbol(Service, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 5, 2)) +>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 11, 30)) + +) => { + Object.keys(ServiceCtr).forEach(key => { +>Object.keys(ServiceCtr).forEach : Symbol(Array.forEach, Decl(lib.es5.d.ts, --, --)) +>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --)) +>ServiceCtr : Symbol(ServiceCtr, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 11, 33)) +>forEach : Symbol(Array.forEach, Decl(lib.es5.d.ts, --, --)) +>key : Symbol(key, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 14, 36)) + + const method = (ServiceCtr)[key as keyof T]; +>method : Symbol(method, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 15, 13)) +>ServiceCtr : Symbol(ServiceCtr, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 11, 33)) +>key : Symbol(key, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 14, 36)) +>T : Symbol(T, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 11, 30)) + + const {__$daemonMode, __$action, id} = method; +>__$daemonMode : Symbol(__$daemonMode, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 16, 15)) +>__$action : Symbol(__$action, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 16, 29)) +>id : Symbol(id, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 16, 40)) +>method : Symbol(method, Decl(genericIndexedAccessMethodIntersectionCanBeAccessed.ts, 15, 13)) + + }) +} + diff --git a/tests/baselines/reference/genericIndexedAccessMethodIntersectionCanBeAccessed.types b/tests/baselines/reference/genericIndexedAccessMethodIntersectionCanBeAccessed.types new file mode 100644 index 0000000000000..d16a75912f491 --- /dev/null +++ b/tests/baselines/reference/genericIndexedAccessMethodIntersectionCanBeAccessed.types @@ -0,0 +1,59 @@ +=== tests/cases/compiler/genericIndexedAccessMethodIntersectionCanBeAccessed.ts === +type ExtendedService = { +>ExtendedService : ExtendedService + + [K in keyof T]: T[K] & { + __$daemonMode?: string; +>__$daemonMode : string | undefined + + __$action?: string; +>__$action : string | undefined + + }; +}; + +type Service = { +>Service : Service + + [K in keyof T]: T[K] & {id?: string}; +>id : string | undefined + +}; + +export const createService = ( +>createService : (ServiceCtr: ExtendedService & Service) => void +>( ServiceCtr: ExtendedService & Service) => { Object.keys(ServiceCtr).forEach(key => { const method = (ServiceCtr)[key as keyof T]; const {__$daemonMode, __$action, id} = method; })} : (ServiceCtr: ExtendedService & Service) => void + + ServiceCtr: ExtendedService & Service +>ServiceCtr : ExtendedService & Service + +) => { + Object.keys(ServiceCtr).forEach(key => { +>Object.keys(ServiceCtr).forEach(key => { const method = (ServiceCtr)[key as keyof T]; const {__$daemonMode, __$action, id} = method; }) : void +>Object.keys(ServiceCtr).forEach : (callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any) => void +>Object.keys(ServiceCtr) : string[] +>Object.keys : (o: {}) => string[] +>Object : ObjectConstructor +>keys : (o: {}) => string[] +>ServiceCtr : ExtendedService & Service +>forEach : (callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any) => void +>key => { const method = (ServiceCtr)[key as keyof T]; const {__$daemonMode, __$action, id} = method; } : (key: string) => void +>key : string + + const method = (ServiceCtr)[key as keyof T]; +>method : (ExtendedService & Service)[keyof T] +>(ServiceCtr)[key as keyof T] : (ExtendedService & Service)[keyof T] +>(ServiceCtr) : ExtendedService & Service +>ServiceCtr : ExtendedService & Service +>key as keyof T : keyof T +>key : string + + const {__$daemonMode, __$action, id} = method; +>__$daemonMode : string | undefined +>__$action : string | undefined +>id : string | undefined +>method : (ExtendedService & Service)[keyof T] + + }) +} + diff --git a/tests/baselines/reference/indexClassByNumber.types b/tests/baselines/reference/indexClassByNumber.types index dfd27305ba9f3..0da451adb36f3 100644 --- a/tests/baselines/reference/indexClassByNumber.types +++ b/tests/baselines/reference/indexClassByNumber.types @@ -11,7 +11,7 @@ var f = new foo(); f[0] = 4; // Shouldn't be allowed >f[0] = 4 : 4 ->f[0] : any +>f[0] : error >f : foo >0 : 0 >4 : 4 diff --git a/tests/baselines/reference/indexedAccessRelation.errors.txt b/tests/baselines/reference/indexedAccessRelation.errors.txt new file mode 100644 index 0000000000000..84e65df856d28 --- /dev/null +++ b/tests/baselines/reference/indexedAccessRelation.errors.txt @@ -0,0 +1,37 @@ +tests/cases/compiler/indexedAccessRelation.ts(16,23): error TS2345: Argument of type '{ a: T; }' is not assignable to parameter of type 'Pick, "a">'. + Types of property 'a' are incompatible. + Type 'T' is not assignable to type 'S["a"] & T'. + Type 'Foo' is not assignable to type 'S["a"] & T'. + Type 'Foo' is not assignable to type 'S["a"]'. + Type 'T' is not assignable to type 'S["a"]'. + Type 'Foo' is not assignable to type 'S["a"]'. + + +==== tests/cases/compiler/indexedAccessRelation.ts (1 errors) ==== + // Repro from #14723 + + class Component { + setState(state: Pick) {} + } + + export interface State { + a?: T; + } + + class Foo {} + + class Comp extends Component> + { + foo(a: T) { + this.setState({ a: a }); + ~~~~~~~~ +!!! error TS2345: Argument of type '{ a: T; }' is not assignable to parameter of type 'Pick, "a">'. +!!! error TS2345: Types of property 'a' are incompatible. +!!! error TS2345: Type 'T' is not assignable to type 'S["a"] & T'. +!!! error TS2345: Type 'Foo' is not assignable to type 'S["a"] & T'. +!!! error TS2345: Type 'Foo' is not assignable to type 'S["a"]'. +!!! error TS2345: Type 'T' is not assignable to type 'S["a"]'. +!!! error TS2345: Type 'Foo' is not assignable to type 'S["a"]'. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/indexedAccessRelation.types b/tests/baselines/reference/indexedAccessRelation.types index 6d2ee19dda240..180cff338ccc9 100644 --- a/tests/baselines/reference/indexedAccessRelation.types +++ b/tests/baselines/reference/indexedAccessRelation.types @@ -26,7 +26,7 @@ class Comp extends Component> >a : T this.setState({ a: a }); ->this.setState({ a: a }) : void +>this.setState({ a: a }) : any >this.setState : (state: Pick, K>) => void >this : this >setState : (state: Pick, K>) => void diff --git a/tests/baselines/reference/indexingTypesWithNever.types b/tests/baselines/reference/indexingTypesWithNever.types index 7994116d84cef..bf141ae0059e4 100644 --- a/tests/baselines/reference/indexingTypesWithNever.types +++ b/tests/baselines/reference/indexingTypesWithNever.types @@ -69,8 +69,8 @@ declare function genericFn3< // Should be never const result5 = genericFn3({ g: "gtest", h: "htest" }, "g", "h"); // 'g' & 'h' will reduce to never ->result5 : error ->genericFn3({ g: "gtest", h: "htest" }, "g", "h") : error +>result5 : unknown +>genericFn3({ g: "gtest", h: "htest" }, "g", "h") : unknown >genericFn3 : (obj: T, u: U, v: V) => T[U & V] >{ g: "gtest", h: "htest" } : { g: string; h: string; } >g : string diff --git a/tests/baselines/reference/limitDeepInstantiations.errors.txt b/tests/baselines/reference/limitDeepInstantiations.errors.txt index 2b68b78743704..2cf5aade7fd61 100644 --- a/tests/baselines/reference/limitDeepInstantiations.errors.txt +++ b/tests/baselines/reference/limitDeepInstantiations.errors.txt @@ -1,7 +1,8 @@ tests/cases/compiler/limitDeepInstantiations.ts(3,35): error TS2502: '"true"' is referenced directly or indirectly in its own type annotation. +tests/cases/compiler/limitDeepInstantiations.ts(5,13): error TS2344: Type '"false"' does not satisfy the constraint '"true"'. -==== tests/cases/compiler/limitDeepInstantiations.ts (1 errors) ==== +==== tests/cases/compiler/limitDeepInstantiations.ts (2 errors) ==== // Repro from #14837 type Foo = { "true": Foo> }[T]; @@ -9,4 +10,6 @@ tests/cases/compiler/limitDeepInstantiations.ts(3,35): error TS2502: '"true"' is !!! error TS2502: '"true"' is referenced directly or indirectly in its own type annotation. let f1: Foo<"true", {}>; let f2: Foo<"false", {}>; + ~~~~~~~ +!!! error TS2344: Type '"false"' does not satisfy the constraint '"true"'. \ No newline at end of file diff --git a/tests/baselines/reference/limitDeepInstantiations.types b/tests/baselines/reference/limitDeepInstantiations.types index 04899df77dbb4..bce090db14b26 100644 --- a/tests/baselines/reference/limitDeepInstantiations.types +++ b/tests/baselines/reference/limitDeepInstantiations.types @@ -9,5 +9,5 @@ let f1: Foo<"true", {}>; >f1 : any let f2: Foo<"false", {}>; ->f2 : any +>f2 : unknown diff --git a/tests/baselines/reference/modularizeLibrary_UsingES5LibES6ArrayLibES6WellknownSymbolLib.types b/tests/baselines/reference/modularizeLibrary_UsingES5LibES6ArrayLibES6WellknownSymbolLib.types index caca4cf87599a..830cbe6a0f42f 100644 --- a/tests/baselines/reference/modularizeLibrary_UsingES5LibES6ArrayLibES6WellknownSymbolLib.types +++ b/tests/baselines/reference/modularizeLibrary_UsingES5LibES6ArrayLibES6WellknownSymbolLib.types @@ -28,7 +28,7 @@ let a = ['c', 'd']; a[Symbol.isConcatSpreadable] = false; >a[Symbol.isConcatSpreadable] = false : false ->a[Symbol.isConcatSpreadable] : any +>a[Symbol.isConcatSpreadable] : error >a : string[] >Symbol.isConcatSpreadable : symbol >Symbol : SymbolConstructor diff --git a/tests/baselines/reference/newWithSpreadES5.types b/tests/baselines/reference/newWithSpreadES5.types index 14b53040a02e0..f40235832bb95 100644 --- a/tests/baselines/reference/newWithSpreadES5.types +++ b/tests/baselines/reference/newWithSpreadES5.types @@ -445,9 +445,9 @@ new h["a-b"]["a-b"](1, 2, ...a, "string"); // Element access expression with a number new i["a-b"][1](1, 2, "string"); ->new i["a-b"][1](1, 2, "string") : any ->i["a-b"][1] : any ->i["a-b"] : any +>new i["a-b"][1](1, 2, "string") : error +>i["a-b"][1] : error +>i["a-b"] : error >i : C[][] >"a-b" : "a-b" >1 : 1 @@ -456,9 +456,9 @@ new i["a-b"][1](1, 2, "string"); >"string" : "string" new i["a-b"][1](1, 2, ...a); ->new i["a-b"][1](1, 2, ...a) : any ->i["a-b"][1] : any ->i["a-b"] : any +>new i["a-b"][1](1, 2, ...a) : error +>i["a-b"][1] : error +>i["a-b"] : error >i : C[][] >"a-b" : "a-b" >1 : 1 @@ -468,9 +468,9 @@ new i["a-b"][1](1, 2, ...a); >a : string[] new i["a-b"][1](1, 2, ...a, "string"); ->new i["a-b"][1](1, 2, ...a, "string") : any ->i["a-b"][1] : any ->i["a-b"] : any +>new i["a-b"][1](1, 2, ...a, "string") : error +>i["a-b"][1] : error +>i["a-b"] : error >i : C[][] >"a-b" : "a-b" >1 : 1 diff --git a/tests/baselines/reference/newWithSpreadES6.types b/tests/baselines/reference/newWithSpreadES6.types index 5914425b096fc..ab2cf6b3d1d68 100644 --- a/tests/baselines/reference/newWithSpreadES6.types +++ b/tests/baselines/reference/newWithSpreadES6.types @@ -446,9 +446,9 @@ new h["a-b"]["a-b"](1, 2, ...a, "string"); // Element access expression with a number new i["a-b"][1](1, 2, "string"); ->new i["a-b"][1](1, 2, "string") : any ->i["a-b"][1] : any ->i["a-b"] : any +>new i["a-b"][1](1, 2, "string") : error +>i["a-b"][1] : error +>i["a-b"] : error >i : C[][] >"a-b" : "a-b" >1 : 1 @@ -457,9 +457,9 @@ new i["a-b"][1](1, 2, "string"); >"string" : "string" new i["a-b"][1](1, 2, ...a); ->new i["a-b"][1](1, 2, ...a) : any ->i["a-b"][1] : any ->i["a-b"] : any +>new i["a-b"][1](1, 2, ...a) : error +>i["a-b"][1] : error +>i["a-b"] : error >i : C[][] >"a-b" : "a-b" >1 : 1 @@ -469,9 +469,9 @@ new i["a-b"][1](1, 2, ...a); >a : string[] new i["a-b"][1](1, 2, ...a, "string"); ->new i["a-b"][1](1, 2, ...a, "string") : any ->i["a-b"][1] : any ->i["a-b"] : any +>new i["a-b"][1](1, 2, ...a, "string") : error +>i["a-b"][1] : error +>i["a-b"] : error >i : C[][] >"a-b" : "a-b" >1 : 1 diff --git a/tests/baselines/reference/noImplicitAnyIndexingSuppressed.types b/tests/baselines/reference/noImplicitAnyIndexingSuppressed.types index 3b004aa9589d3..fe34cdbc130b9 100644 --- a/tests/baselines/reference/noImplicitAnyIndexingSuppressed.types +++ b/tests/baselines/reference/noImplicitAnyIndexingSuppressed.types @@ -24,8 +24,8 @@ var strRepresentation2 = MyEmusEnum[MyEmusEnum.emu] // Should be okay, as we suppress implicit 'any' property access checks var strRepresentation3 = MyEmusEnum["monehh"]; ->strRepresentation3 : any ->MyEmusEnum["monehh"] : any +>strRepresentation3 : error +>MyEmusEnum["monehh"] : error >MyEmusEnum : typeof MyEmusEnum >"monehh" : "monehh" @@ -39,15 +39,15 @@ var strRepresentation4 = MyEmusEnum["emu"]; // Should be okay, as we suppress implicit 'any' property access checks var x = {}["hi"]; ->x : any ->{}["hi"] : any +>x : error +>{}["hi"] : error >{} : {} >"hi" : "hi" // Should be okay, as we suppress implicit 'any' property access checks var y = {}[10]; ->y : any ->{}[10] : any +>y : error +>{}[10] : error >{} : {} >10 : 10 @@ -61,8 +61,8 @@ var emptyObj = {}; // Should be okay, as we suppress implicit 'any' property access checks var z1 = emptyObj[hi]; ->z1 : any ->emptyObj[hi] : any +>z1 : error +>emptyObj[hi] : error >emptyObj : {} >hi : any diff --git a/tests/baselines/reference/nonPrimitiveIndexingWithForIn.types b/tests/baselines/reference/nonPrimitiveIndexingWithForIn.types index 44e2b3f4d50d8..430e03652d794 100644 --- a/tests/baselines/reference/nonPrimitiveIndexingWithForIn.types +++ b/tests/baselines/reference/nonPrimitiveIndexingWithForIn.types @@ -7,8 +7,8 @@ for (var key in a) { >a : object var value = a[key]; ->value : any ->a[key] : any +>value : error +>a[key] : error >a : object >key : string } diff --git a/tests/baselines/reference/nonPrimitiveIndexingWithForInSupressError.types b/tests/baselines/reference/nonPrimitiveIndexingWithForInSupressError.types index 3fafa40b59615..9c094010701ab 100644 --- a/tests/baselines/reference/nonPrimitiveIndexingWithForInSupressError.types +++ b/tests/baselines/reference/nonPrimitiveIndexingWithForInSupressError.types @@ -7,8 +7,8 @@ for (var key in a) { >a : object var value = a[key]; ->value : any ->a[key] : any +>value : error +>a[key] : error >a : object >key : string } diff --git a/tests/baselines/reference/numericIndexingResults.types b/tests/baselines/reference/numericIndexingResults.types index db4d341b56008..f4e0d168e6e22 100644 --- a/tests/baselines/reference/numericIndexingResults.types +++ b/tests/baselines/reference/numericIndexingResults.types @@ -30,8 +30,8 @@ var r2 = c['2']; >'2' : "2" var r3 = c['3']; ->r3 : any ->c['3'] : any +>r3 : error +>c['3'] : error >c : C >'3' : "3" @@ -80,8 +80,8 @@ var r2 = i['2']; >'2' : "2" var r3 = i['3']; ->r3 : any ->i['3'] : any +>r3 : error +>i['3'] : error >i : I >'3' : "3" @@ -129,8 +129,8 @@ var r2 = a['2']; >'2' : "2" var r3 = a['3']; ->r3 : any ->a['3'] : any +>r3 : error +>a['3'] : error >a : { [x: number]: string; 1: string; "2": string; } >'3' : "3" @@ -162,20 +162,20 @@ var b: { [x: number]: string } = { 1: '', "2": '' } >'' : "" var r1a = b['1']; ->r1a : any ->b['1'] : any +>r1a : error +>b['1'] : error >b : { [x: number]: string; } >'1' : "1" var r2a = b['2']; ->r2a : any ->b['2'] : any +>r2a : error +>b['2'] : error >b : { [x: number]: string; } >'2' : "2" var r3 = b['3']; ->r3 : any ->b['3'] : any +>r3 : error +>b['3'] : error >b : { [x: number]: string; } >'3' : "3" @@ -221,8 +221,8 @@ var r2b = b2['2']; >'2' : "2" var r3 = b2['3']; ->r3 : any ->b2['3'] : any +>r3 : error +>b2['3'] : error >b2 : { [x: number]: string; 1: string; "2": string; } >'3' : "3" diff --git a/tests/baselines/reference/objectTypeWithCallSignatureHidingMembersOfExtendedFunction.types b/tests/baselines/reference/objectTypeWithCallSignatureHidingMembersOfExtendedFunction.types index d36ef8866c7bb..3ee91c6aff31e 100644 --- a/tests/baselines/reference/objectTypeWithCallSignatureHidingMembersOfExtendedFunction.types +++ b/tests/baselines/reference/objectTypeWithCallSignatureHidingMembersOfExtendedFunction.types @@ -55,8 +55,8 @@ var r1d = i.data; >data : number var r1e = i['hm']; // should be Object ->r1e : any ->i['hm'] : any +>r1e : error +>i['hm'] : error >i : I >'hm' : "hm" @@ -104,8 +104,8 @@ var r2d = x.data; >data : number var r2e = x['hm']; // should be Object ->r2e : any ->x['hm'] : any +>r2e : error +>x['hm'] : error >x : { (): void; apply(a: any, b?: any): void; call(thisArg: number, ...argArray: number[]): any; } >'hm' : "hm" diff --git a/tests/baselines/reference/objectTypeWithConstructSignatureHidingMembersOfExtendedFunction.types b/tests/baselines/reference/objectTypeWithConstructSignatureHidingMembersOfExtendedFunction.types index 8bb1785516bc8..6e00a2ea1e964 100644 --- a/tests/baselines/reference/objectTypeWithConstructSignatureHidingMembersOfExtendedFunction.types +++ b/tests/baselines/reference/objectTypeWithConstructSignatureHidingMembersOfExtendedFunction.types @@ -52,8 +52,8 @@ var r1d = i.data; >data : number var r1e = i['hm']; // should be Object ->r1e : any ->i['hm'] : any +>r1e : error +>i['hm'] : error >i : I >'hm' : "hm" @@ -101,8 +101,8 @@ var r2d = x.data; >data : number var r2e = x['hm']; // should be Object ->r2e : any ->x['hm'] : any +>r2e : error +>x['hm'] : error >x : { new (): number; apply(a: any, b?: any): void; call(thisArg: number, ...argArray: number[]): any; } >'hm' : "hm" diff --git a/tests/baselines/reference/objectTypeWithStringNamedPropertyOfIllegalCharacters.types b/tests/baselines/reference/objectTypeWithStringNamedPropertyOfIllegalCharacters.types index d110e79e26edd..ad30405de0ec0 100644 --- a/tests/baselines/reference/objectTypeWithStringNamedPropertyOfIllegalCharacters.types +++ b/tests/baselines/reference/objectTypeWithStringNamedPropertyOfIllegalCharacters.types @@ -28,8 +28,8 @@ var r = c[" "]; >" " : " " var r2 = c[" "]; ->r2 : any ->c[" "] : any +>r2 : error +>c[" "] : error >c : C >" " : " " @@ -67,8 +67,8 @@ var r = i[" "]; >" " : " " var r2 = i[" "]; ->r2 : any ->i[" "] : any +>r2 : error +>i[" "] : error >i : I >" " : " " @@ -106,8 +106,8 @@ var r = a[" "]; >" " : " " var r2 = a[" "]; ->r2 : any ->a[" "] : any +>r2 : error +>a[" "] : error >a : { " ": number; "a b": string; "~!@#$%^&*()_+{}|:'<>?\/.,`": number; } >" " : " " @@ -148,8 +148,8 @@ var r = b[" "]; >" " : " " var r2 = b[" "]; ->r2 : any ->b[" "] : any +>r2 : error +>b[" "] : error >b : { " ": number; "a b": string; "~!@#$%^&*()_+{}|:'<>?\/.,`": number; } >" " : " " diff --git a/tests/baselines/reference/octalIntegerLiteral.types b/tests/baselines/reference/octalIntegerLiteral.types index 160a1460977aa..5b3e484821e9d 100644 --- a/tests/baselines/reference/octalIntegerLiteral.types +++ b/tests/baselines/reference/octalIntegerLiteral.types @@ -69,7 +69,7 @@ obj1[0o45436]; // string >0o45436 : 19230 obj1["0o45436"]; // any ->obj1["0o45436"] : any +>obj1["0o45436"] : error >obj1 : { 0o45436: string; a: number; b: number; oct1: number; 0o7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777: boolean; } >"0o45436" : "0o45436" @@ -109,7 +109,7 @@ obj2[0O45436]; // string >0O45436 : 19230 obj2["0O45436"]; // any ->obj2["0O45436"] : any +>obj2["0O45436"] : error >obj2 : { 0O45436: string; a: number; b: number; oct2: number; 0o7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777: boolean; } >"0O45436" : "0O45436" @@ -149,7 +149,7 @@ obj2["5.462437423415177e+244"]; // boolean >"5.462437423415177e+244" : "5.462437423415177e+244" obj2["Infinity"]; // any ->obj2["Infinity"] : any +>obj2["Infinity"] : error >obj2 : { 0O45436: string; a: number; b: number; oct2: number; 0o7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777: boolean; } >"Infinity" : "Infinity" diff --git a/tests/baselines/reference/octalIntegerLiteralES6.types b/tests/baselines/reference/octalIntegerLiteralES6.types index 0c799a4469745..8f1e7256b17fa 100644 --- a/tests/baselines/reference/octalIntegerLiteralES6.types +++ b/tests/baselines/reference/octalIntegerLiteralES6.types @@ -69,7 +69,7 @@ obj1[0o45436]; // string >0o45436 : 19230 obj1["0o45436"]; // any ->obj1["0o45436"] : any +>obj1["0o45436"] : error >obj1 : { 0o45436: string; a: number; b: number; oct1: number; 0o7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777: boolean; } >"0o45436" : "0o45436" @@ -109,7 +109,7 @@ obj2[0O45436]; // string >0O45436 : 19230 obj2["0O45436"]; // any ->obj2["0O45436"] : any +>obj2["0O45436"] : error >obj2 : { 0O45436: string; a: number; b: number; oct2: number; 0o7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777: boolean; } >"0O45436" : "0O45436" @@ -149,7 +149,7 @@ obj2["5.462437423415177e+244"]; // boolean >"5.462437423415177e+244" : "5.462437423415177e+244" obj2["Infinity"]; // any ->obj2["Infinity"] : any +>obj2["Infinity"] : error >obj2 : { 0O45436: string; a: number; b: number; oct2: number; 0o7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777: boolean; } >"Infinity" : "Infinity" diff --git a/tests/baselines/reference/protoAsIndexInIndexExpression.types b/tests/baselines/reference/protoAsIndexInIndexExpression.types index 7d2761990638e..2da76f32f4a68 100644 --- a/tests/baselines/reference/protoAsIndexInIndexExpression.types +++ b/tests/baselines/reference/protoAsIndexInIndexExpression.types @@ -15,7 +15,7 @@ var WorkspacePrototype = { }; WorkspacePrototype['__proto__'] = EntityPrototype; >WorkspacePrototype['__proto__'] = EntityPrototype : any ->WorkspacePrototype['__proto__'] : any +>WorkspacePrototype['__proto__'] : error >WorkspacePrototype : { serialize: () => any; } >'__proto__' : "__proto__" >EntityPrototype : any diff --git a/tests/baselines/reference/protoInIndexer.types b/tests/baselines/reference/protoInIndexer.types index c15f98b75ffcf..e47bb0dd34174 100644 --- a/tests/baselines/reference/protoInIndexer.types +++ b/tests/baselines/reference/protoInIndexer.types @@ -5,7 +5,7 @@ class X { constructor() { this['__proto__'] = null; // used to cause ICE >this['__proto__'] = null : null ->this['__proto__'] : any +>this['__proto__'] : error >this : this >'__proto__' : "__proto__" >null : null diff --git a/tests/baselines/reference/spyComparisonChecking.errors.txt b/tests/baselines/reference/spyComparisonChecking.errors.txt new file mode 100644 index 0000000000000..8b057dd30ed2e --- /dev/null +++ b/tests/baselines/reference/spyComparisonChecking.errors.txt @@ -0,0 +1,29 @@ +tests/cases/compiler/spyComparisonChecking.ts(20,32): error TS2339: Property 'returnValue' does not exist on type 'Function'. + + +==== tests/cases/compiler/spyComparisonChecking.ts (1 errors) ==== + interface Spy { + (...params: any[]): any; + + identity: string; + and: Function; + mostRecentCall: { args: any[]; }; + argsForCall: any[]; + } + + type SpyObj = T & { + [k in keyof T]: Spy; + } + + declare function createSpyObj( + name: string, names: Array): SpyObj; + + function mock(spyName: string, methodNames: Array): SpyObj { + const spyObj = createSpyObj(spyName, methodNames); + for (const methodName of methodNames) { + spyObj[methodName].and.returnValue(1); + ~~~~~~~~~~~ +!!! error TS2339: Property 'returnValue' does not exist on type 'Function'. + } + return spyObj; + } \ No newline at end of file diff --git a/tests/baselines/reference/spyComparisonChecking.js b/tests/baselines/reference/spyComparisonChecking.js new file mode 100644 index 0000000000000..918c4e149e9a5 --- /dev/null +++ b/tests/baselines/reference/spyComparisonChecking.js @@ -0,0 +1,34 @@ +//// [spyComparisonChecking.ts] +interface Spy { + (...params: any[]): any; + + identity: string; + and: Function; + mostRecentCall: { args: any[]; }; + argsForCall: any[]; +} + +type SpyObj = T & { + [k in keyof T]: Spy; +} + +declare function createSpyObj( + name: string, names: Array): SpyObj; + +function mock(spyName: string, methodNames: Array): SpyObj { + const spyObj = createSpyObj(spyName, methodNames); + for (const methodName of methodNames) { + spyObj[methodName].and.returnValue(1); + } + return spyObj; +} + +//// [spyComparisonChecking.js] +function mock(spyName, methodNames) { + var spyObj = createSpyObj(spyName, methodNames); + for (var _i = 0, methodNames_1 = methodNames; _i < methodNames_1.length; _i++) { + var methodName = methodNames_1[_i]; + spyObj[methodName].and.returnValue(1); + } + return spyObj; +} diff --git a/tests/baselines/reference/spyComparisonChecking.symbols b/tests/baselines/reference/spyComparisonChecking.symbols new file mode 100644 index 0000000000000..50d8afaa0d13b --- /dev/null +++ b/tests/baselines/reference/spyComparisonChecking.symbols @@ -0,0 +1,75 @@ +=== tests/cases/compiler/spyComparisonChecking.ts === +interface Spy { +>Spy : Symbol(Spy, Decl(spyComparisonChecking.ts, 0, 0)) + + (...params: any[]): any; +>params : Symbol(params, Decl(spyComparisonChecking.ts, 1, 5)) + + identity: string; +>identity : Symbol(Spy.identity, Decl(spyComparisonChecking.ts, 1, 28)) + + and: Function; +>and : Symbol(Spy.and, Decl(spyComparisonChecking.ts, 3, 21)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + + mostRecentCall: { args: any[]; }; +>mostRecentCall : Symbol(Spy.mostRecentCall, Decl(spyComparisonChecking.ts, 4, 18)) +>args : Symbol(args, Decl(spyComparisonChecking.ts, 5, 21)) + + argsForCall: any[]; +>argsForCall : Symbol(Spy.argsForCall, Decl(spyComparisonChecking.ts, 5, 37)) +} + +type SpyObj = T & { +>SpyObj : Symbol(SpyObj, Decl(spyComparisonChecking.ts, 7, 1)) +>T : Symbol(T, Decl(spyComparisonChecking.ts, 9, 12)) +>T : Symbol(T, Decl(spyComparisonChecking.ts, 9, 12)) + + [k in keyof T]: Spy; +>k : Symbol(k, Decl(spyComparisonChecking.ts, 10, 5)) +>T : Symbol(T, Decl(spyComparisonChecking.ts, 9, 12)) +>Spy : Symbol(Spy, Decl(spyComparisonChecking.ts, 0, 0)) +} + +declare function createSpyObj( +>createSpyObj : Symbol(createSpyObj, Decl(spyComparisonChecking.ts, 11, 1)) +>T : Symbol(T, Decl(spyComparisonChecking.ts, 13, 30)) + + name: string, names: Array): SpyObj; +>name : Symbol(name, Decl(spyComparisonChecking.ts, 13, 33)) +>names : Symbol(names, Decl(spyComparisonChecking.ts, 14, 17)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(spyComparisonChecking.ts, 13, 30)) +>SpyObj : Symbol(SpyObj, Decl(spyComparisonChecking.ts, 7, 1)) +>T : Symbol(T, Decl(spyComparisonChecking.ts, 13, 30)) + +function mock(spyName: string, methodNames: Array): SpyObj { +>mock : Symbol(mock, Decl(spyComparisonChecking.ts, 14, 52)) +>T : Symbol(T, Decl(spyComparisonChecking.ts, 16, 14)) +>spyName : Symbol(spyName, Decl(spyComparisonChecking.ts, 16, 17)) +>methodNames : Symbol(methodNames, Decl(spyComparisonChecking.ts, 16, 33)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(spyComparisonChecking.ts, 16, 14)) +>SpyObj : Symbol(SpyObj, Decl(spyComparisonChecking.ts, 7, 1)) +>T : Symbol(T, Decl(spyComparisonChecking.ts, 16, 14)) + + const spyObj = createSpyObj(spyName, methodNames); +>spyObj : Symbol(spyObj, Decl(spyComparisonChecking.ts, 17, 9)) +>createSpyObj : Symbol(createSpyObj, Decl(spyComparisonChecking.ts, 11, 1)) +>T : Symbol(T, Decl(spyComparisonChecking.ts, 16, 14)) +>spyName : Symbol(spyName, Decl(spyComparisonChecking.ts, 16, 17)) +>methodNames : Symbol(methodNames, Decl(spyComparisonChecking.ts, 16, 33)) + + for (const methodName of methodNames) { +>methodName : Symbol(methodName, Decl(spyComparisonChecking.ts, 18, 14)) +>methodNames : Symbol(methodNames, Decl(spyComparisonChecking.ts, 16, 33)) + + spyObj[methodName].and.returnValue(1); +>spyObj[methodName].and : Symbol(Spy.and, Decl(spyComparisonChecking.ts, 3, 21)) +>spyObj : Symbol(spyObj, Decl(spyComparisonChecking.ts, 17, 9)) +>methodName : Symbol(methodName, Decl(spyComparisonChecking.ts, 18, 14)) +>and : Symbol(Spy.and, Decl(spyComparisonChecking.ts, 3, 21)) + } + return spyObj; +>spyObj : Symbol(spyObj, Decl(spyComparisonChecking.ts, 17, 9)) +} diff --git a/tests/baselines/reference/spyComparisonChecking.types b/tests/baselines/reference/spyComparisonChecking.types new file mode 100644 index 0000000000000..3401bc45ac4b3 --- /dev/null +++ b/tests/baselines/reference/spyComparisonChecking.types @@ -0,0 +1,62 @@ +=== tests/cases/compiler/spyComparisonChecking.ts === +interface Spy { + (...params: any[]): any; +>params : any[] + + identity: string; +>identity : string + + and: Function; +>and : Function + + mostRecentCall: { args: any[]; }; +>mostRecentCall : { args: any[]; } +>args : any[] + + argsForCall: any[]; +>argsForCall : any[] +} + +type SpyObj = T & { +>SpyObj : SpyObj + + [k in keyof T]: Spy; +} + +declare function createSpyObj( +>createSpyObj : (name: string, names: (keyof T)[]) => SpyObj + + name: string, names: Array): SpyObj; +>name : string +>names : (keyof T)[] + +function mock(spyName: string, methodNames: Array): SpyObj { +>mock : (spyName: string, methodNames: (keyof T)[]) => SpyObj +>spyName : string +>methodNames : (keyof T)[] + + const spyObj = createSpyObj(spyName, methodNames); +>spyObj : SpyObj +>createSpyObj(spyName, methodNames) : SpyObj +>createSpyObj : (name: string, names: (keyof T)[]) => SpyObj +>spyName : string +>methodNames : (keyof T)[] + + for (const methodName of methodNames) { +>methodName : keyof T +>methodNames : (keyof T)[] + + spyObj[methodName].and.returnValue(1); +>spyObj[methodName].and.returnValue(1) : any +>spyObj[methodName].and.returnValue : any +>spyObj[methodName].and : Function +>spyObj[methodName] : SpyObj[keyof T] +>spyObj : SpyObj +>methodName : keyof T +>and : Function +>returnValue : any +>1 : 1 + } + return spyObj; +>spyObj : SpyObj +} diff --git a/tests/baselines/reference/superSymbolIndexedAccess1.types b/tests/baselines/reference/superSymbolIndexedAccess1.types index 11b67cadfcd83..46e2133643684 100644 --- a/tests/baselines/reference/superSymbolIndexedAccess1.types +++ b/tests/baselines/reference/superSymbolIndexedAccess1.types @@ -28,8 +28,8 @@ class Bar extends Foo { >symbol : symbol return super[symbol](); ->super[symbol]() : any ->super[symbol] : any +>super[symbol]() : error +>super[symbol] : error >super : Foo >symbol : symbol } diff --git a/tests/baselines/reference/superSymbolIndexedAccess5.types b/tests/baselines/reference/superSymbolIndexedAccess5.types index cbbd98ee320e1..b0395936a8a6a 100644 --- a/tests/baselines/reference/superSymbolIndexedAccess5.types +++ b/tests/baselines/reference/superSymbolIndexedAccess5.types @@ -23,8 +23,8 @@ class Bar extends Foo { >symbol : any return super[symbol](); ->super[symbol]() : any ->super[symbol] : any +>super[symbol]() : error +>super[symbol] : error >super : Foo >symbol : any } diff --git a/tests/baselines/reference/superSymbolIndexedAccess6.types b/tests/baselines/reference/superSymbolIndexedAccess6.types index dab662927186e..e60869d6fe6c5 100644 --- a/tests/baselines/reference/superSymbolIndexedAccess6.types +++ b/tests/baselines/reference/superSymbolIndexedAccess6.types @@ -23,8 +23,8 @@ class Bar extends Foo { >symbol : any return super[symbol](); ->super[symbol]() : any ->super[symbol] : any +>super[symbol]() : error +>super[symbol] : error >super : typeof Foo >symbol : any } diff --git a/tests/baselines/reference/symbolProperty55.types b/tests/baselines/reference/symbolProperty55.types index 3c185f96d1ee1..d96b8b43751b3 100644 --- a/tests/baselines/reference/symbolProperty55.types +++ b/tests/baselines/reference/symbolProperty55.types @@ -21,7 +21,7 @@ module M { // The following should be of type 'any'. This is because even though obj has a property keyed by Symbol.iterator, // the key passed in here is the *wrong* Symbol.iterator. It is not the iterator property of the global Symbol. obj[Symbol.iterator]; ->obj[Symbol.iterator] : any +>obj[Symbol.iterator] : error >obj : { [Symbol.iterator]: number; } >Symbol.iterator : symbol >Symbol : SymbolConstructor diff --git a/tests/baselines/reference/symbolProperty56.types b/tests/baselines/reference/symbolProperty56.types index 1f061739c4116..b6731ed5e8003 100644 --- a/tests/baselines/reference/symbolProperty56.types +++ b/tests/baselines/reference/symbolProperty56.types @@ -21,9 +21,9 @@ module M { // The following should be of type 'any'. This is because even though obj has a property keyed by Symbol.iterator, // the key passed in here is the *wrong* Symbol.iterator. It is not the iterator property of the global Symbol. obj[Symbol["iterator"]]; ->obj[Symbol["iterator"]] : any +>obj[Symbol["iterator"]] : error >obj : { [Symbol.iterator]: number; } ->Symbol["iterator"] : any +>Symbol["iterator"] : error >Symbol : {} >"iterator" : "iterator" } diff --git a/tests/baselines/reference/symbolProperty57.types b/tests/baselines/reference/symbolProperty57.types index 88dca83627fd9..eeb00489bb201 100644 --- a/tests/baselines/reference/symbolProperty57.types +++ b/tests/baselines/reference/symbolProperty57.types @@ -14,9 +14,9 @@ var obj = { // Should give type 'any'. obj[Symbol["nonsense"]]; ->obj[Symbol["nonsense"]] : any +>obj[Symbol["nonsense"]] : error >obj : { [Symbol.iterator]: number; } ->Symbol["nonsense"] : any +>Symbol["nonsense"] : error >Symbol : SymbolConstructor >"nonsense" : "nonsense" diff --git a/tests/baselines/reference/systemJsForInNoException.types b/tests/baselines/reference/systemJsForInNoException.types index 6d9dbbb6e7b48..31bef844a6f59 100644 --- a/tests/baselines/reference/systemJsForInNoException.types +++ b/tests/baselines/reference/systemJsForInNoException.types @@ -14,7 +14,7 @@ for (var key in obj) >console.log : (message?: any, ...optionalParams: any[]) => void >console : Console >log : (message?: any, ...optionalParams: any[]) => void ->obj[key] : any +>obj[key] : error >obj : { a: number; } >key : string diff --git a/tests/baselines/reference/templateStringInIndexExpression.types b/tests/baselines/reference/templateStringInIndexExpression.types index f0faac5f45c03..9ad6b1e141db0 100644 --- a/tests/baselines/reference/templateStringInIndexExpression.types +++ b/tests/baselines/reference/templateStringInIndexExpression.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es6/templates/templateStringInIndexExpression.ts === `abc${0}abc`[`0`]; ->`abc${0}abc`[`0`] : any +>`abc${0}abc`[`0`] : error >`abc${0}abc` : string >0 : 0 >`0` : "0" diff --git a/tests/baselines/reference/templateStringInIndexExpressionES6.types b/tests/baselines/reference/templateStringInIndexExpressionES6.types index eabc71c9facbc..d86fb2309e72b 100644 --- a/tests/baselines/reference/templateStringInIndexExpressionES6.types +++ b/tests/baselines/reference/templateStringInIndexExpressionES6.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es6/templates/templateStringInIndexExpressionES6.ts === `abc${0}abc`[`0`]; ->`abc${0}abc`[`0`] : any +>`abc${0}abc`[`0`] : error >`abc${0}abc` : string >0 : 0 >`0` : "0" diff --git a/tests/baselines/reference/thisIndexOnExistingReadonlyFieldIsNotNever.js b/tests/baselines/reference/thisIndexOnExistingReadonlyFieldIsNotNever.js new file mode 100644 index 0000000000000..56273a2b00691 --- /dev/null +++ b/tests/baselines/reference/thisIndexOnExistingReadonlyFieldIsNotNever.js @@ -0,0 +1,60 @@ +//// [thisIndexOnExistingReadonlyFieldIsNotNever.ts] +declare class Component { + readonly props: Readonly<{ children?: unknown }> & Readonly

; + state: Readonly; +} +interface CoachMarkAnchorProps { + anchorRef?: (anchor: C) => void; +} +type AnchorType

= Component

; + +class CoachMarkAnchorDecorator { + decorateComponent

(anchor: P) { + return class CoachMarkAnchor extends Component> & P, {}> { + private _onAnchorRef = (anchor: AnchorType

) => { + const anchorRef = this.props.anchorRef; + if (anchorRef) { + anchorRef(anchor); + } + } + }; + } +} + + +//// [thisIndexOnExistingReadonlyFieldIsNotNever.js] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var CoachMarkAnchorDecorator = /** @class */ (function () { + function CoachMarkAnchorDecorator() { + } + CoachMarkAnchorDecorator.prototype.decorateComponent = function (anchor) { + return /** @class */ (function (_super) { + __extends(CoachMarkAnchor, _super); + function CoachMarkAnchor() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this._onAnchorRef = function (anchor) { + var anchorRef = _this.props.anchorRef; + if (anchorRef) { + anchorRef(anchor); + } + }; + return _this; + } + return CoachMarkAnchor; + }(Component)); + }; + return CoachMarkAnchorDecorator; +}()); diff --git a/tests/baselines/reference/thisIndexOnExistingReadonlyFieldIsNotNever.symbols b/tests/baselines/reference/thisIndexOnExistingReadonlyFieldIsNotNever.symbols new file mode 100644 index 0000000000000..6cedbe269bfd8 --- /dev/null +++ b/tests/baselines/reference/thisIndexOnExistingReadonlyFieldIsNotNever.symbols @@ -0,0 +1,76 @@ +=== tests/cases/compiler/thisIndexOnExistingReadonlyFieldIsNotNever.ts === +declare class Component { +>Component : Symbol(Component, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 0)) +>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 24)) +>S : Symbol(S, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 26)) + + readonly props: Readonly<{ children?: unknown }> & Readonly

; +>props : Symbol(Component.props, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 36)) +>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --)) +>children : Symbol(children, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 1, 30)) +>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --)) +>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 24)) + + state: Readonly; +>state : Symbol(Component.state, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 1, 67)) +>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --)) +>S : Symbol(S, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 26)) +} +interface CoachMarkAnchorProps { +>CoachMarkAnchorProps : Symbol(CoachMarkAnchorProps, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 3, 1)) +>C : Symbol(C, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 4, 31)) + + anchorRef?: (anchor: C) => void; +>anchorRef : Symbol(CoachMarkAnchorProps.anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 4, 35)) +>anchor : Symbol(anchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 5, 17)) +>C : Symbol(C, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 4, 31)) +} +type AnchorType

= Component

; +>AnchorType : Symbol(AnchorType, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 6, 1)) +>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 7, 16)) +>Component : Symbol(Component, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 0)) +>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 7, 16)) + +class CoachMarkAnchorDecorator { +>CoachMarkAnchorDecorator : Symbol(CoachMarkAnchorDecorator, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 7, 34)) + + decorateComponent

(anchor: P) { +>decorateComponent : Symbol(CoachMarkAnchorDecorator.decorateComponent, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 9, 32)) +>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 22)) +>anchor : Symbol(anchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 25)) +>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 22)) + + return class CoachMarkAnchor extends Component> & P, {}> { +>CoachMarkAnchor : Symbol(CoachMarkAnchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 11, 14)) +>Component : Symbol(Component, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 0)) +>CoachMarkAnchorProps : Symbol(CoachMarkAnchorProps, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 3, 1)) +>AnchorType : Symbol(AnchorType, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 6, 1)) +>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 22)) +>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 22)) + + private _onAnchorRef = (anchor: AnchorType

) => { +>_onAnchorRef : Symbol(CoachMarkAnchor._onAnchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 11, 101)) +>anchor : Symbol(anchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 12, 36)) +>AnchorType : Symbol(AnchorType, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 6, 1)) +>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 22)) + + const anchorRef = this.props.anchorRef; +>anchorRef : Symbol(anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 13, 21)) +>this.props.anchorRef : Symbol(anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 4, 35)) +>this.props : Symbol(Component.props, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 36)) +>this : Symbol(CoachMarkAnchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 11, 14)) +>props : Symbol(Component.props, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 36)) +>anchorRef : Symbol(anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 4, 35)) + + if (anchorRef) { +>anchorRef : Symbol(anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 13, 21)) + + anchorRef(anchor); +>anchorRef : Symbol(anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 13, 21)) +>anchor : Symbol(anchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 12, 36)) + } + } + }; + } +} + diff --git a/tests/baselines/reference/thisIndexOnExistingReadonlyFieldIsNotNever.types b/tests/baselines/reference/thisIndexOnExistingReadonlyFieldIsNotNever.types new file mode 100644 index 0000000000000..30dfd635724d1 --- /dev/null +++ b/tests/baselines/reference/thisIndexOnExistingReadonlyFieldIsNotNever.types @@ -0,0 +1,57 @@ +=== tests/cases/compiler/thisIndexOnExistingReadonlyFieldIsNotNever.ts === +declare class Component { +>Component : Component + + readonly props: Readonly<{ children?: unknown }> & Readonly

; +>props : Readonly<{ children?: unknown; }> & Readonly

+>children : unknown + + state: Readonly; +>state : Readonly +} +interface CoachMarkAnchorProps { + anchorRef?: (anchor: C) => void; +>anchorRef : ((anchor: C) => void) | undefined +>anchor : C +} +type AnchorType

= Component

; +>AnchorType : Component + +class CoachMarkAnchorDecorator { +>CoachMarkAnchorDecorator : CoachMarkAnchorDecorator + + decorateComponent

(anchor: P) { +>decorateComponent :

(anchor: P) => typeof CoachMarkAnchor +>anchor : P + + return class CoachMarkAnchor extends Component> & P, {}> { +>class CoachMarkAnchor extends Component> & P, {}> { private _onAnchorRef = (anchor: AnchorType

) => { const anchorRef = this.props.anchorRef; if (anchorRef) { anchorRef(anchor); } } } : typeof CoachMarkAnchor +>CoachMarkAnchor : typeof CoachMarkAnchor +>Component : Component> & P, {}> + + private _onAnchorRef = (anchor: AnchorType

) => { +>_onAnchorRef : (anchor: Component) => void +>(anchor: AnchorType

) => { const anchorRef = this.props.anchorRef; if (anchorRef) { anchorRef(anchor); } } : (anchor: Component) => void +>anchor : Component + + const anchorRef = this.props.anchorRef; +>anchorRef : (CoachMarkAnchorProps> & P)["anchorRef"] | undefined +>this.props.anchorRef : (CoachMarkAnchorProps> & P)["anchorRef"] | undefined +>this.props : Readonly<{ children?: unknown; }> & Readonly> & P> +>this : this +>props : Readonly<{ children?: unknown; }> & Readonly> & P> +>anchorRef : (CoachMarkAnchorProps> & P)["anchorRef"] | undefined + + if (anchorRef) { +>anchorRef : (CoachMarkAnchorProps> & P)["anchorRef"] | undefined + + anchorRef(anchor); +>anchorRef(anchor) : void +>anchorRef : (anchor: Component) => void +>anchor : Component + } + } + }; + } +} + diff --git a/tests/baselines/reference/unionTypeIndexSignature.types b/tests/baselines/reference/unionTypeIndexSignature.types index b8dc990040428..f20d879a5484c 100644 --- a/tests/baselines/reference/unionTypeIndexSignature.types +++ b/tests/baselines/reference/unionTypeIndexSignature.types @@ -32,16 +32,16 @@ var unionOfTypesWithAndWithoutStringSignature: { [a: string]: number; } | boolea >a : string anyVar = unionOfTypesWithAndWithoutStringSignature["hello"]; // any ->anyVar = unionOfTypesWithAndWithoutStringSignature["hello"] : any +>anyVar = unionOfTypesWithAndWithoutStringSignature["hello"] : error >anyVar : number ->unionOfTypesWithAndWithoutStringSignature["hello"] : any +>unionOfTypesWithAndWithoutStringSignature["hello"] : error >unionOfTypesWithAndWithoutStringSignature : boolean | { [a: string]: number; } >"hello" : "hello" anyVar = unionOfTypesWithAndWithoutStringSignature[10]; // any ->anyVar = unionOfTypesWithAndWithoutStringSignature[10] : any +>anyVar = unionOfTypesWithAndWithoutStringSignature[10] : error >anyVar : number ->unionOfTypesWithAndWithoutStringSignature[10] : any +>unionOfTypesWithAndWithoutStringSignature[10] : error >unionOfTypesWithAndWithoutStringSignature : boolean | { [a: string]: number; } >10 : 10 @@ -53,9 +53,9 @@ var unionOfDifferentReturnType1: { [a: number]: number; } | { [a: number]: Date; >a : number numOrDate = unionOfDifferentReturnType1["hello"]; // any ->numOrDate = unionOfDifferentReturnType1["hello"] : any +>numOrDate = unionOfDifferentReturnType1["hello"] : error >numOrDate : number | Date ->unionOfDifferentReturnType1["hello"] : any +>unionOfDifferentReturnType1["hello"] : error >unionOfDifferentReturnType1 : { [a: number]: number; } | { [a: number]: Date; } >"hello" : "hello" @@ -71,16 +71,16 @@ var unionOfTypesWithAndWithoutStringSignature1: { [a: number]: number; } | boole >a : number anyVar = unionOfTypesWithAndWithoutStringSignature1["hello"]; // any ->anyVar = unionOfTypesWithAndWithoutStringSignature1["hello"] : any +>anyVar = unionOfTypesWithAndWithoutStringSignature1["hello"] : error >anyVar : number ->unionOfTypesWithAndWithoutStringSignature1["hello"] : any +>unionOfTypesWithAndWithoutStringSignature1["hello"] : error >unionOfTypesWithAndWithoutStringSignature1 : boolean | { [a: number]: number; } >"hello" : "hello" anyVar = unionOfTypesWithAndWithoutStringSignature1[10]; // any ->anyVar = unionOfTypesWithAndWithoutStringSignature1[10] : any +>anyVar = unionOfTypesWithAndWithoutStringSignature1[10] : error >anyVar : number ->unionOfTypesWithAndWithoutStringSignature1[10] : any +>unionOfTypesWithAndWithoutStringSignature1[10] : error >unionOfTypesWithAndWithoutStringSignature1 : boolean | { [a: number]: number; } >10 : 10 diff --git a/tests/baselines/reference/varianceCallbacksAndIndexedAccesses.js b/tests/baselines/reference/varianceCallbacksAndIndexedAccesses.js new file mode 100644 index 0000000000000..ec188824455a1 --- /dev/null +++ b/tests/baselines/reference/varianceCallbacksAndIndexedAccesses.js @@ -0,0 +1,36 @@ +//// [varianceCallbacksAndIndexedAccesses.ts] +type Source = { + (type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; + (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; +} + +interface Action1 { + (arg: T): void; +} +interface MessageEventLike { + source: WindowLike; + origin: string; + data: T; +} +interface PostMessageObject { + postMessage(message: T, host: string): void; +} +interface WindowLike extends PostMessageObject { + addEventListener(type: "message", handler: Action1>): void; + addEventListener(type: string, handler: Action1): void; + removeEventListener(type: "message", handler: Action1>): void; + removeEventListener(type: string, handler: Action1): void; +} +type Target = { + (type: "message", handler: Action1>): void; + (type: string, handler: Action1): void; +}; + +function f1(s: Source, t: Target) { + t = s; +} + +//// [varianceCallbacksAndIndexedAccesses.js] +function f1(s, t) { + t = s; +} diff --git a/tests/baselines/reference/varianceCallbacksAndIndexedAccesses.symbols b/tests/baselines/reference/varianceCallbacksAndIndexedAccesses.symbols new file mode 100644 index 0000000000000..343d146b5fdf4 --- /dev/null +++ b/tests/baselines/reference/varianceCallbacksAndIndexedAccesses.symbols @@ -0,0 +1,121 @@ +=== tests/cases/compiler/varianceCallbacksAndIndexedAccesses.ts === +type Source = { +>Source : Symbol(Source, Decl(varianceCallbacksAndIndexedAccesses.ts, 0, 0)) + + (type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; +>K : Symbol(K, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 5)) +>WindowEventMap : Symbol(WindowEventMap, Decl(lib.dom.d.ts, --, --)) +>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 37)) +>K : Symbol(K, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 5)) +>listener : Symbol(listener, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 45)) +>this : Symbol(this, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 57)) +>Window : Symbol(Window, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>ev : Symbol(ev, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 70)) +>WindowEventMap : Symbol(WindowEventMap, Decl(lib.dom.d.ts, --, --)) +>K : Symbol(K, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 5)) +>options : Symbol(options, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 101)) +>AddEventListenerOptions : Symbol(AddEventListenerOptions, Decl(lib.dom.d.ts, --, --)) + + (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; +>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 2, 3)) +>listener : Symbol(listener, Decl(varianceCallbacksAndIndexedAccesses.ts, 2, 16)) +>EventListenerOrEventListenerObject : Symbol(EventListenerOrEventListenerObject, Decl(lib.dom.d.ts, --, --)) +>options : Symbol(options, Decl(varianceCallbacksAndIndexedAccesses.ts, 2, 62)) +>AddEventListenerOptions : Symbol(AddEventListenerOptions, Decl(lib.dom.d.ts, --, --)) +} + +interface Action1 { +>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1)) +>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 5, 18)) + + (arg: T): void; +>arg : Symbol(arg, Decl(varianceCallbacksAndIndexedAccesses.ts, 6, 5)) +>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 5, 18)) +} +interface MessageEventLike { +>MessageEventLike : Symbol(MessageEventLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 7, 1)) +>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 8, 27)) + + source: WindowLike; +>source : Symbol(MessageEventLike.source, Decl(varianceCallbacksAndIndexedAccesses.ts, 8, 31)) +>WindowLike : Symbol(WindowLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 15, 1)) +>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 8, 27)) + + origin: string; +>origin : Symbol(MessageEventLike.origin, Decl(varianceCallbacksAndIndexedAccesses.ts, 9, 26)) + + data: T; +>data : Symbol(MessageEventLike.data, Decl(varianceCallbacksAndIndexedAccesses.ts, 10, 19)) +>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 8, 27)) +} +interface PostMessageObject { +>PostMessageObject : Symbol(PostMessageObject, Decl(varianceCallbacksAndIndexedAccesses.ts, 12, 1)) +>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 13, 28)) + + postMessage(message: T, host: string): void; +>postMessage : Symbol(PostMessageObject.postMessage, Decl(varianceCallbacksAndIndexedAccesses.ts, 13, 32)) +>message : Symbol(message, Decl(varianceCallbacksAndIndexedAccesses.ts, 14, 16)) +>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 13, 28)) +>host : Symbol(host, Decl(varianceCallbacksAndIndexedAccesses.ts, 14, 27)) +} +interface WindowLike extends PostMessageObject { +>WindowLike : Symbol(WindowLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 15, 1)) +>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 21)) +>PostMessageObject : Symbol(PostMessageObject, Decl(varianceCallbacksAndIndexedAccesses.ts, 12, 1)) +>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 21)) + + addEventListener(type: "message", handler: Action1>): void; +>addEventListener : Symbol(WindowLike.addEventListener, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 54), Decl(varianceCallbacksAndIndexedAccesses.ts, 17, 83)) +>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 17, 21)) +>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 17, 37)) +>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1)) +>MessageEventLike : Symbol(MessageEventLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 7, 1)) +>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 21)) + + addEventListener(type: string, handler: Action1): void; +>addEventListener : Symbol(WindowLike.addEventListener, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 54), Decl(varianceCallbacksAndIndexedAccesses.ts, 17, 83)) +>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 18, 21)) +>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 18, 34)) +>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1)) + + removeEventListener(type: "message", handler: Action1>): void; +>removeEventListener : Symbol(WindowLike.removeEventListener, Decl(varianceCallbacksAndIndexedAccesses.ts, 18, 64), Decl(varianceCallbacksAndIndexedAccesses.ts, 19, 86)) +>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 19, 24)) +>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 19, 40)) +>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1)) +>MessageEventLike : Symbol(MessageEventLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 7, 1)) +>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 21)) + + removeEventListener(type: string, handler: Action1): void; +>removeEventListener : Symbol(WindowLike.removeEventListener, Decl(varianceCallbacksAndIndexedAccesses.ts, 18, 64), Decl(varianceCallbacksAndIndexedAccesses.ts, 19, 86)) +>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 20, 24)) +>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 20, 37)) +>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1)) +} +type Target = { +>Target : Symbol(Target, Decl(varianceCallbacksAndIndexedAccesses.ts, 21, 1)) + + (type: "message", handler: Action1>): void; +>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 23, 5)) +>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 23, 21)) +>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1)) +>MessageEventLike : Symbol(MessageEventLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 7, 1)) + + (type: string, handler: Action1): void; +>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 24, 5)) +>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 24, 18)) +>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1)) + +}; + +function f1(s: Source, t: Target) { +>f1 : Symbol(f1, Decl(varianceCallbacksAndIndexedAccesses.ts, 25, 2)) +>s : Symbol(s, Decl(varianceCallbacksAndIndexedAccesses.ts, 27, 12)) +>Source : Symbol(Source, Decl(varianceCallbacksAndIndexedAccesses.ts, 0, 0)) +>t : Symbol(t, Decl(varianceCallbacksAndIndexedAccesses.ts, 27, 22)) +>Target : Symbol(Target, Decl(varianceCallbacksAndIndexedAccesses.ts, 21, 1)) + + t = s; +>t : Symbol(t, Decl(varianceCallbacksAndIndexedAccesses.ts, 27, 22)) +>s : Symbol(s, Decl(varianceCallbacksAndIndexedAccesses.ts, 27, 12)) +} diff --git a/tests/baselines/reference/varianceCallbacksAndIndexedAccesses.types b/tests/baselines/reference/varianceCallbacksAndIndexedAccesses.types new file mode 100644 index 0000000000000..6b4d90767b69d --- /dev/null +++ b/tests/baselines/reference/varianceCallbacksAndIndexedAccesses.types @@ -0,0 +1,81 @@ +=== tests/cases/compiler/varianceCallbacksAndIndexedAccesses.ts === +type Source = { +>Source : Source + + (type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; +>type : K +>listener : (this: Window, ev: WindowEventMap[K]) => any +>this : Window +>ev : WindowEventMap[K] +>options : boolean | AddEventListenerOptions + + (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; +>type : string +>listener : EventListenerOrEventListenerObject +>options : boolean | AddEventListenerOptions +} + +interface Action1 { + (arg: T): void; +>arg : T +} +interface MessageEventLike { + source: WindowLike; +>source : WindowLike + + origin: string; +>origin : string + + data: T; +>data : T +} +interface PostMessageObject { + postMessage(message: T, host: string): void; +>postMessage : (message: T, host: string) => void +>message : T +>host : string +} +interface WindowLike extends PostMessageObject { + addEventListener(type: "message", handler: Action1>): void; +>addEventListener : { (type: "message", handler: Action1>): void; (type: string, handler: Action1): void; } +>type : "message" +>handler : Action1> + + addEventListener(type: string, handler: Action1): void; +>addEventListener : { (type: "message", handler: Action1>): void; (type: string, handler: Action1): void; } +>type : string +>handler : Action1 + + removeEventListener(type: "message", handler: Action1>): void; +>removeEventListener : { (type: "message", handler: Action1>): void; (type: string, handler: Action1): void; } +>type : "message" +>handler : Action1> + + removeEventListener(type: string, handler: Action1): void; +>removeEventListener : { (type: "message", handler: Action1>): void; (type: string, handler: Action1): void; } +>type : string +>handler : Action1 +} +type Target = { +>Target : Target + + (type: "message", handler: Action1>): void; +>type : "message" +>handler : Action1> + + (type: string, handler: Action1): void; +>type : string +>handler : Action1 + +}; + +function f1(s: Source, t: Target) { +>f1 : (s: Source, t: Target) => void +>s : Source +>t : Target + + t = s; +>t = s : Source +>t : Target +>s : Source +} diff --git a/tests/cases/compiler/circularlySimplifyingConditionalTypesNoCrash.ts b/tests/cases/compiler/circularlySimplifyingConditionalTypesNoCrash.ts new file mode 100644 index 0000000000000..ccacb10dd2d64 --- /dev/null +++ b/tests/cases/compiler/circularlySimplifyingConditionalTypesNoCrash.ts @@ -0,0 +1,48 @@ +// @strict: true +type Omit = Pick>; + +type Shared< // Circularly self constraining type, defered thanks to mapping + InjectedProps, + DecorationTargetProps extends Shared + > = { + [P in Extract]: InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : never; + }; + +interface ComponentClass

{ + defaultProps?: Partial

; // Inference target is also mapped _and_ optional +} + +interface InferableComponentEnhancerWithProps { +

>( + component: ComponentClass

+ ): ComponentClass> & TNeedsProps> & { WrappedComponent: ComponentClass

} +} // Then intersected with and indexed via Omit and & + +interface Connect { // Then strictly compared with another signature in its context + ( + mapStateToProps: unknown, + ): InferableComponentEnhancerWithProps; + + ( + mapStateToProps: null | undefined, + mapDispatchToProps: unknown, + mergeProps: null | undefined, + options: unknown + ): InferableComponentEnhancerWithProps; +} + +declare var connect: Connect; + +const myStoreConnect: Connect = function( + mapStateToProps?: any, + mapDispatchToProps?: any, + mergeProps?: any, + options: unknown = {}, +) { + return connect( + mapStateToProps, + mapDispatchToProps, + mergeProps, + options, + ); +}; \ No newline at end of file diff --git a/tests/cases/compiler/genericIndexedAccessMethodIntersectionCanBeAccessed.ts b/tests/cases/compiler/genericIndexedAccessMethodIntersectionCanBeAccessed.ts new file mode 100644 index 0000000000000..b4d604ff90aec --- /dev/null +++ b/tests/cases/compiler/genericIndexedAccessMethodIntersectionCanBeAccessed.ts @@ -0,0 +1,20 @@ +// @strict: true +type ExtendedService = { + [K in keyof T]: T[K] & { + __$daemonMode?: string; + __$action?: string; + }; +}; + +type Service = { + [K in keyof T]: T[K] & {id?: string}; +}; + +export const createService = ( + ServiceCtr: ExtendedService & Service +) => { + Object.keys(ServiceCtr).forEach(key => { + const method = (ServiceCtr)[key as keyof T]; + const {__$daemonMode, __$action, id} = method; + }) +} diff --git a/tests/cases/compiler/spyComparisonChecking.ts b/tests/cases/compiler/spyComparisonChecking.ts new file mode 100644 index 0000000000000..68b53de98db46 --- /dev/null +++ b/tests/cases/compiler/spyComparisonChecking.ts @@ -0,0 +1,23 @@ +interface Spy { + (...params: any[]): any; + + identity: string; + and: Function; + mostRecentCall: { args: any[]; }; + argsForCall: any[]; +} + +type SpyObj = T & { + [k in keyof T]: Spy; +} + +declare function createSpyObj( + name: string, names: Array): SpyObj; + +function mock(spyName: string, methodNames: Array): SpyObj { + const spyObj = createSpyObj(spyName, methodNames); + for (const methodName of methodNames) { + spyObj[methodName].and.returnValue(1); + } + return spyObj; +} \ No newline at end of file diff --git a/tests/cases/compiler/thisIndexOnExistingReadonlyFieldIsNotNever.ts b/tests/cases/compiler/thisIndexOnExistingReadonlyFieldIsNotNever.ts new file mode 100644 index 0000000000000..a271cbdbc9c3e --- /dev/null +++ b/tests/cases/compiler/thisIndexOnExistingReadonlyFieldIsNotNever.ts @@ -0,0 +1,22 @@ +// @strict: true +declare class Component { + readonly props: Readonly<{ children?: unknown }> & Readonly

; + state: Readonly; +} +interface CoachMarkAnchorProps { + anchorRef?: (anchor: C) => void; +} +type AnchorType

= Component

; + +class CoachMarkAnchorDecorator { + decorateComponent

(anchor: P) { + return class CoachMarkAnchor extends Component> & P, {}> { + private _onAnchorRef = (anchor: AnchorType

) => { + const anchorRef = this.props.anchorRef; + if (anchorRef) { + anchorRef(anchor); + } + } + }; + } +} diff --git a/tests/cases/compiler/varianceCallbacksAndIndexedAccesses.ts b/tests/cases/compiler/varianceCallbacksAndIndexedAccesses.ts new file mode 100644 index 0000000000000..471829ffd8174 --- /dev/null +++ b/tests/cases/compiler/varianceCallbacksAndIndexedAccesses.ts @@ -0,0 +1,32 @@ + + +type Source = { + (type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; + (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; +} + +interface Action1 { + (arg: T): void; +} +interface MessageEventLike { + source: WindowLike; + origin: string; + data: T; +} +interface PostMessageObject { + postMessage(message: T, host: string): void; +} +interface WindowLike extends PostMessageObject { + addEventListener(type: "message", handler: Action1>): void; + addEventListener(type: string, handler: Action1): void; + removeEventListener(type: "message", handler: Action1>): void; + removeEventListener(type: string, handler: Action1): void; +} +type Target = { + (type: "message", handler: Action1>): void; + (type: string, handler: Action1): void; +}; + +function f1(s: Source, t: Target) { + t = s; +} \ No newline at end of file