diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 33b3505661a3a..2bdfe9c0c0357 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -164,6 +164,7 @@ namespace ts { anyFunctionType.flags |= TypeFlags.ContainsAnyFunctionType; const noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + const circularConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); const anySignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false); const unknownSignature = createSignature(undefined, undefined, undefined, emptyArray, unknownType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false); @@ -4135,9 +4136,6 @@ namespace ts { if (!links.declaredType) { const type = createType(TypeFlags.TypeParameter); type.symbol = symbol; - if (!(getDeclarationOfKind(symbol, SyntaxKind.TypeParameter)).constraint) { - type.constraint = noConstraintType; - } links.declaredType = type; } return links.declaredType; @@ -4754,19 +4752,79 @@ namespace ts { getPropertiesOfObjectType(type); } + function getConstraintOfTypeVariable(type: TypeVariable): Type { + return type.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(type) : getBaseConstraintOfTypeVariable(type); + } + + function getConstraintOfTypeParameter(typeParameter: TypeParameter): Type { + return hasNonCircularBaseConstraint(typeParameter) ? getConstraintFromTypeParameter(typeParameter) : undefined; + } + + function getBaseConstraintOfTypeVariable(type: TypeVariable): Type { + const constraint = getResolvedBaseConstraint(type); + return constraint !== noConstraintType && constraint !== circularConstraintType ? constraint : undefined; + } + + function hasNonCircularBaseConstraint(type: TypeVariable): boolean { + return getResolvedBaseConstraint(type) !== circularConstraintType; + } + /** - * The apparent type of a type parameter is the base constraint instantiated with the type parameter - * as the type argument for the 'this' type. + * Return the resolved base constraint of a type variable. The noConstraintType singleton is returned if the + * type variable has no constraint, and the circularConstraintType singleton is returned if the constraint + * circularly references the type variable. */ - function getApparentTypeOfTypeVariable(type: TypeVariable) { + function getResolvedBaseConstraint(type: TypeVariable): Type { + let typeStack: Type[]; + let circular: boolean; if (!type.resolvedApparentType) { - let constraintType = getConstraintOfTypeVariable(type); - while (constraintType && constraintType.flags & TypeFlags.TypeParameter) { - constraintType = getConstraintOfTypeVariable(constraintType); - } - type.resolvedApparentType = getTypeWithThisArgument(constraintType || emptyObjectType, type); + typeStack = []; + const constraint = getBaseConstraint(type); + type.resolvedApparentType = circular ? circularConstraintType : getTypeWithThisArgument(constraint || noConstraintType, type); } return type.resolvedApparentType; + + function getBaseConstraint(t: Type): Type { + if (contains(typeStack, t)) { + circular = true; + return undefined; + } + typeStack.push(t); + const result = computeBaseConstraint(t); + typeStack.pop(); + return result; + } + + function computeBaseConstraint(t: Type): Type { + if (t.flags & TypeFlags.TypeParameter) { + const constraint = getConstraintFromTypeParameter(t); + return (t).isThisType ? constraint : + constraint ? getBaseConstraint(constraint) : undefined; + } + if (t.flags & TypeFlags.UnionOrIntersection) { + const types = (t).types; + const baseTypes: Type[] = []; + for (const type of types) { + const baseType = getBaseConstraint(type); + if (baseType) { + baseTypes.push(baseType); + } + } + return t.flags & TypeFlags.Union && baseTypes.length === types.length ? getUnionType(baseTypes) : + t.flags & TypeFlags.Intersection && baseTypes.length ? getIntersectionType(baseTypes) : + undefined; + } + if (t.flags & TypeFlags.Index) { + return stringType; + } + if (t.flags & TypeFlags.IndexedAccess) { + const baseObjectType = getBaseConstraint((t).objectType); + const baseIndexType = getBaseConstraint((t).indexType); + const baseIndexedAccess = baseObjectType && baseIndexType ? getIndexedAccessType(baseObjectType, baseIndexType) : undefined; + return baseIndexedAccess && baseIndexedAccess !== unknownType ? getBaseConstraint(baseIndexedAccess) : undefined; + } + return t; + } } /** @@ -4775,7 +4833,7 @@ namespace ts { * type itself. Note that the apparent type of a union type is the union type itself. */ function getApparentType(type: Type): Type { - const t = type.flags & TypeFlags.TypeVariable ? getApparentTypeOfTypeVariable(type) : type; + const t = type.flags & TypeFlags.TypeVariable ? getBaseConstraintOfTypeVariable(type) || emptyObjectType : type; return t.flags & TypeFlags.StringLike ? globalStringType : t.flags & TypeFlags.NumberLike ? globalNumberType : t.flags & TypeFlags.BooleanLike ? globalBooleanType : @@ -5329,20 +5387,7 @@ namespace ts { return (getDeclarationOfKind(type.symbol, SyntaxKind.TypeParameter)).constraint; } - function hasConstraintReferenceTo(type: Type, target: TypeParameter): boolean { - let checked: Type[]; - while (type && type.flags & TypeFlags.TypeParameter && !((type as TypeParameter).isThisType) && !contains(checked, type)) { - if (type === target) { - return true; - } - (checked || (checked = [])).push(type); - const constraintDeclaration = getConstraintDeclaration(type); - type = constraintDeclaration && getTypeFromTypeNode(constraintDeclaration); - } - return false; - } - - function getConstraintOfTypeParameter(typeParameter: TypeParameter): Type { + function getConstraintFromTypeParameter(typeParameter: TypeParameter): Type { if (!typeParameter.constraint) { if (typeParameter.target) { const targetConstraint = getConstraintOfTypeParameter(typeParameter.target); @@ -5350,23 +5395,12 @@ namespace ts { } else { const constraintDeclaration = getConstraintDeclaration(typeParameter); - let constraint = getTypeFromTypeNode(constraintDeclaration); - if (hasConstraintReferenceTo(constraint, typeParameter)) { - error(constraintDeclaration, Diagnostics.Type_parameter_0_has_a_circular_constraint, typeToString(typeParameter)); - constraint = unknownType; - } - typeParameter.constraint = constraint; + typeParameter.constraint = constraintDeclaration ? getTypeFromTypeNode(constraintDeclaration) : noConstraintType; } } return typeParameter.constraint === noConstraintType ? undefined : typeParameter.constraint; } - function getConstraintOfTypeVariable(type: TypeVariable): Type { - return type.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(type) : - type.flags & TypeFlags.IndexedAccess ? (type).constraint : - undefined; - } - function getParentSymbolOfTypeParameter(typeParameter: TypeParameter): Symbol { return getSymbolOfNode(getDeclarationOfKind(typeParameter.symbol, SyntaxKind.TypeParameter).parent); } @@ -6042,24 +6076,6 @@ namespace ts { const type = createType(TypeFlags.IndexedAccess); type.objectType = objectType; type.indexType = indexType; - // We eagerly compute the constraint of the indexed access type such that circularity - // errors are immediately caught and reported. For example, class C { x: this["x"] } - // becomes an error only when the constraint is eagerly computed. - if (type.objectType.flags & TypeFlags.StructuredType) { - // The constraint of T[K], where T is an object, union, or intersection type, - // is the type of the string index signature of T, if any. - type.constraint = getIndexTypeOfType(type.objectType, IndexKind.String); - } - else if (type.objectType.flags & TypeFlags.TypeVariable) { - // The constraint of T[K], where T is a type variable, is A[K], where A is the - // apparent type of T. - const apparentType = getApparentTypeOfTypeVariable(type.objectType); - if (apparentType !== emptyObjectType) { - type.constraint = isTypeOfKind((type).indexType, TypeFlags.StringLike) ? - getIndexedAccessType(apparentType, (type).indexType) : - getIndexTypeOfType(apparentType, IndexKind.String); - } - } return type; } @@ -6150,13 +6166,6 @@ namespace ts { if (objectType.flags & TypeFlags.Any) { return objectType; } - // We first check that the index type is assignable to 'keyof T' for the object type. - if (accessNode) { - if (!isTypeAssignableTo(indexType, getIndexType(objectType))) { - error(accessNode, Diagnostics.Type_0_cannot_be_used_to_index_type_1, typeToString(indexType), typeToString(objectType)); - return unknownType; - } - } // If the object type is a mapped type { [P in K]: E }, we instantiate E using a mapper that substitutes // the index type for P. For example, for an index access { [P in K]: Box }[X], we construct the // type Box. @@ -7197,7 +7206,7 @@ namespace ts { return related === RelationComparisonResult.Succeeded; } } - if (source.flags & TypeFlags.StructuredOrTypeParameter || target.flags & TypeFlags.StructuredOrTypeParameter) { + if (source.flags & TypeFlags.StructuredOrTypeVariable || target.flags & TypeFlags.StructuredOrTypeVariable) { return checkTypeRelatedTo(source, target, relation, undefined, undefined, undefined); } return false; @@ -7436,8 +7445,9 @@ namespace ts { } // A type S is related to a type T[K] if S is related to A[K], where K is string-like and // A is the apparent type of S. - if ((target).constraint) { - if (result = isRelatedTo(source, (target).constraint, reportErrors)) { + const constraint = getBaseConstraintOfTypeVariable(target); + if (constraint) { + if (result = isRelatedTo(source, constraint, reportErrors)) { errorInfo = saveErrorInfo; return result; } @@ -7475,8 +7485,9 @@ namespace ts { else if (source.flags & TypeFlags.IndexedAccess) { // A type S[K] is related to a type T if A[K] is related to T, where K is string-like and // A is the apparent type of S. - if ((source).constraint) { - if (result = isRelatedTo((source).constraint, target, reportErrors)) { + const constraint = getBaseConstraintOfTypeVariable(source); + if (constraint) { + if (result = isRelatedTo(constraint, target, reportErrors)) { errorInfo = saveErrorInfo; return result; } @@ -12528,7 +12539,7 @@ namespace ts { return unknownType; } - return getIndexedAccessType(objectType, indexType, node); + return checkIndexedAccessIndexType(getIndexedAccessType(objectType, indexType, node), node); } function checkThatExpressionIsProperSymbolReference(expression: Expression, expressionType: Type, reportError: boolean): boolean { @@ -15186,14 +15197,14 @@ namespace ts { function isLiteralContextualType(contextualType: Type) { if (contextualType) { if (contextualType.flags & TypeFlags.TypeVariable) { - const apparentType = getApparentTypeOfTypeVariable(contextualType); + const constraint = getBaseConstraintOfTypeVariable(contextualType) || emptyObjectType; // If the type parameter is constrained to the base primitive type we're checking for, // consider this a literal context. For example, given a type parameter 'T extends string', // this causes us to infer string literal types for T. - if (apparentType.flags & (TypeFlags.String | TypeFlags.Number | TypeFlags.Boolean | TypeFlags.Enum)) { + if (constraint.flags & (TypeFlags.String | TypeFlags.Number | TypeFlags.Boolean | TypeFlags.Enum)) { return true; } - contextualType = apparentType; + contextualType = constraint; } return maybeTypeOfKind(contextualType, (TypeFlags.Literal | TypeFlags.Index)); } @@ -15391,6 +15402,10 @@ namespace ts { } checkSourceElement(node.constraint); + const typeParameter = getDeclaredTypeOfTypeParameter(getSymbolOfNode(node)); + if (!hasNonCircularBaseConstraint(typeParameter)) { + error(node.constraint, Diagnostics.Type_parameter_0_has_a_circular_constraint, typeToString(typeParameter)); + } getConstraintOfTypeParameter(getDeclaredTypeOfTypeParameter(getSymbolOfNode(node))); if (produceDiagnostics) { checkTypeNameIsReserved(node.name, Diagnostics.Type_parameter_name_cannot_be_0); @@ -16014,8 +16029,20 @@ namespace ts { forEach(node.types, checkSourceElement); } + function checkIndexedAccessIndexType(type: Type, accessNode: ElementAccessExpression | IndexedAccessTypeNode) { + if (type.flags & TypeFlags.IndexedAccess) { + // Check that the index type is assignable to 'keyof T' for the object type. + const objectType = (type).objectType; + const indexType = (type).indexType; + if (!isTypeAssignableTo(indexType, getIndexType(objectType))) { + error(accessNode, Diagnostics.Type_0_cannot_be_used_to_index_type_1, typeToString(indexType), typeToString(objectType)); + } + } + return type; + } + function checkIndexedAccessType(node: IndexedAccessTypeNode) { - getTypeFromIndexedAccessTypeNode(node); + checkIndexedAccessIndexType(getTypeFromIndexedAccessTypeNode(node), node); } function checkMappedType(node: MappedTypeNode) { @@ -16023,8 +16050,7 @@ namespace ts { checkSourceElement(node.type); const type = getTypeFromMappedTypeNode(node); const constraintType = getConstraintTypeFromMappedType(type); - const keyType = constraintType.flags & TypeFlags.TypeVariable ? getApparentTypeOfTypeVariable(constraintType) : constraintType; - checkTypeAssignableTo(keyType, stringType, node.typeParameter.constraint); + checkTypeAssignableTo(constraintType, stringType, node.typeParameter.constraint); } function isPrivateWithinAmbient(node: Node): boolean { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 6eebb0b99d7f4..8e6263845335c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2803,7 +2803,7 @@ namespace ts { EnumLike = Enum | EnumLiteral, UnionOrIntersection = Union | Intersection, StructuredType = Object | Union | Intersection, - StructuredOrTypeParameter = StructuredType | TypeParameter | Index, + StructuredOrTypeVariable = StructuredType | TypeParameter | Index | IndexedAccess, TypeVariable = TypeParameter | IndexedAccess, // 'Narrowable' types are types where narrowing actually narrows. diff --git a/tests/baselines/reference/circularIndexedAccessErrors.errors.txt b/tests/baselines/reference/circularIndexedAccessErrors.errors.txt index e3076e08b7e6b..f76cfca073e74 100644 --- a/tests/baselines/reference/circularIndexedAccessErrors.errors.txt +++ b/tests/baselines/reference/circularIndexedAccessErrors.errors.txt @@ -1,14 +1,12 @@ tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(3,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation. tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(7,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation. -tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(15,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation. tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(19,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation. tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(23,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation. -tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(27,5): error TS2502: 'x' is referenced directly or indirectly in its own type annotation. -tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(28,5): error TS2502: 'y' is referenced directly or indirectly in its own type annotation. -tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(29,5): error TS2502: 'z' is referenced directly or indirectly in its own type annotation. +tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(38,24): error TS2313: Type parameter 'T' has a circular constraint. +tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(38,30): error TS2536: Type '"hello"' cannot be used to index type 'T'. -==== tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts (8 errors) ==== +==== tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts (6 errors) ==== type T1 = { x: T1["x"]; // Error @@ -27,9 +25,7 @@ tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(29,5): error let x2x = x2.x; interface T3> { - x: T["x"]; // Error - ~~~~~~~~~~ -!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation. + x: T["x"]; } interface T4> { @@ -45,13 +41,21 @@ tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(29,5): error } class C2 { - x: this["y"]; // Error - ~~~~~~~~~~~~~ -!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation. - y: this["z"]; // Error - ~~~~~~~~~~~~~ -!!! error TS2502: 'y' is referenced directly or indirectly in its own type annotation. - z: this["x"]; // Error - ~~~~~~~~~~~~~ -!!! error TS2502: 'z' is referenced directly or indirectly in its own type annotation. - } \ No newline at end of file + x: this["y"]; + y: this["z"]; + z: this["x"]; + } + + // Repro from #12627 + + interface Foo { + hello: boolean; + } + + function foo() { + ~~~~~~~~~~~~~~~~ +!!! error TS2313: Type parameter 'T' has a circular constraint. + ~~~~~~~~~~ +!!! error TS2536: Type '"hello"' cannot be used to index type 'T'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/circularIndexedAccessErrors.js b/tests/baselines/reference/circularIndexedAccessErrors.js index 46784ae8d18c2..97d059bce19bc 100644 --- a/tests/baselines/reference/circularIndexedAccessErrors.js +++ b/tests/baselines/reference/circularIndexedAccessErrors.js @@ -13,7 +13,7 @@ declare let x2: T2<"x">; let x2x = x2.x; interface T3> { - x: T["x"]; // Error + x: T["x"]; } interface T4> { @@ -25,10 +25,20 @@ class C1 { } class C2 { - x: this["y"]; // Error - y: this["z"]; // Error - z: this["x"]; // Error -} + x: this["y"]; + y: this["z"]; + z: this["x"]; +} + +// Repro from #12627 + +interface Foo { + hello: boolean; +} + +function foo() { +} + //// [circularIndexedAccessErrors.js] var x2x = x2.x; @@ -42,6 +52,8 @@ var C2 = (function () { } return C2; }()); +function foo() { +} //// [circularIndexedAccessErrors.d.ts] @@ -68,3 +80,7 @@ declare class C2 { y: this["z"]; z: this["x"]; } +interface Foo { + hello: boolean; +} +declare function foo(): void; diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js index 4b93897fdc48c..f5c2624fc40fe 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.js +++ b/tests/baselines/reference/keyofAndIndexedAccess.js @@ -296,6 +296,30 @@ class C1 { } } +type S2 = { + a: string; + b: string; +}; + +function f90(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K], x4: T[K]) { + x1 = x2; + x1 = x3; + x1 = x4; + x2 = x1; + x2 = x3; + x2 = x4; + x3 = x1; + x3 = x2; + x3 = x4; + x4 = x1; + x4 = x2; + x4 = x3; + x1.length; + x2.length; + x3.length; + x4.length; +} + // Repros from #12011 class Base { @@ -429,7 +453,44 @@ type SomeMethodDescriptor = { returnValue: string[]; } -let result = dispatchMethod("someMethod", ["hello", 35]); +let result = dispatchMethod("someMethod", ["hello", 35]); + +// Repro from #13073 + +type KeyTypes = "a" | "b" +let MyThingy: { [key in KeyTypes]: string[] }; + +function addToMyThingy(key: S) { + MyThingy[key].push("a"); +} + +// Repro from #13285 + +function updateIds, K extends string>( + obj: T, + idFields: K[], + idMapping: { [oldId: string]: string } +): Record { + for (const idField of idFields) { + const newId = idMapping[obj[idField]]; + if (newId) { + obj[idField] = newId; + } + } + return obj; +} + +// Repro from #13285 + +function updateIds2( + obj: T, + key: K, + stringMap: { [oldId: string]: string } +) { + var x = obj[key]; + stringMap[x]; // Should be OK. +} + //// [keyofAndIndexedAccess.js] var __extends = (this && this.__extends) || function (d, b) { @@ -644,6 +705,24 @@ var C1 = (function () { }; return C1; }()); +function f90(x1, x2, x3, x4) { + x1 = x2; + x1 = x3; + x1 = x4; + x2 = x1; + x2 = x3; + x2 = x4; + x3 = x1; + x3 = x2; + x3 = x4; + x4 = x1; + x4 = x2; + x4 = x3; + x1.length; + x2.length; + x3.length; + x4.length; +} // Repros from #12011 var Base = (function () { function Base() { @@ -713,6 +792,26 @@ function f(p) { a[p].add; // any } var result = dispatchMethod("someMethod", ["hello", 35]); +var MyThingy; +function addToMyThingy(key) { + MyThingy[key].push("a"); +} +// Repro from #13285 +function updateIds(obj, idFields, idMapping) { + for (var _i = 0, idFields_1 = idFields; _i < idFields_1.length; _i++) { + var idField = idFields_1[_i]; + var newId = idMapping[obj[idField]]; + if (newId) { + obj[idField] = newId; + } + } + return obj; +} +// Repro from #13285 +function updateIds2(obj, key, stringMap) { + var x = obj[key]; + stringMap[x]; // Should be OK. +} //// [keyofAndIndexedAccess.d.ts] @@ -848,6 +947,11 @@ declare class C1 { set(key: K, value: this[K]): void; foo(): void; } +declare type S2 = { + a: string; + b: string; +}; +declare function f90(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K], x4: T[K]): void; declare class Base { get(prop: K): this[K]; set(prop: K, value: this[K]): void; @@ -920,3 +1024,16 @@ declare type SomeMethodDescriptor = { returnValue: string[]; }; declare let result: string[]; +declare type KeyTypes = "a" | "b"; +declare let MyThingy: { + [key in KeyTypes]: string[]; +}; +declare function addToMyThingy(key: S): void; +declare function updateIds, K extends string>(obj: T, idFields: K[], idMapping: { + [oldId: string]: string; +}): Record; +declare function updateIds2(obj: T, key: K, stringMap: { + [oldId: string]: string; +}): void; diff --git a/tests/baselines/reference/keyofAndIndexedAccess.symbols b/tests/baselines/reference/keyofAndIndexedAccess.symbols index 1c69d4959d804..a6eb03dd6e50b 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess.symbols @@ -1139,440 +1139,643 @@ class C1 { } } +type S2 = { +>S2 : Symbol(S2, Decl(keyofAndIndexedAccess.ts, 295, 1)) + + a: string; +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 297, 11)) + + b: string; +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 298, 14)) + +}; + +function f90(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K], x4: T[K]) { +>f90 : Symbol(f90, Decl(keyofAndIndexedAccess.ts, 300, 2)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 302, 13)) +>S2 : Symbol(S2, Decl(keyofAndIndexedAccess.ts, 295, 1)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 302, 26)) +>S2 : Symbol(S2, Decl(keyofAndIndexedAccess.ts, 295, 1)) +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 302, 47)) +>S2 : Symbol(S2, Decl(keyofAndIndexedAccess.ts, 295, 1)) +>S2 : Symbol(S2, Decl(keyofAndIndexedAccess.ts, 295, 1)) +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 302, 64)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 302, 13)) +>S2 : Symbol(S2, Decl(keyofAndIndexedAccess.ts, 295, 1)) +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 302, 81)) +>S2 : Symbol(S2, Decl(keyofAndIndexedAccess.ts, 295, 1)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 302, 26)) +>x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 302, 92)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 302, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 302, 26)) + + x1 = x2; +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 302, 47)) +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 302, 64)) + + x1 = x3; +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 302, 47)) +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 302, 81)) + + x1 = x4; +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 302, 47)) +>x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 302, 92)) + + x2 = x1; +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 302, 64)) +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 302, 47)) + + x2 = x3; +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 302, 64)) +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 302, 81)) + + x2 = x4; +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 302, 64)) +>x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 302, 92)) + + x3 = x1; +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 302, 81)) +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 302, 47)) + + x3 = x2; +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 302, 81)) +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 302, 64)) + + x3 = x4; +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 302, 81)) +>x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 302, 92)) + + x4 = x1; +>x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 302, 92)) +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 302, 47)) + + x4 = x2; +>x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 302, 92)) +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 302, 64)) + + x4 = x3; +>x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 302, 92)) +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 302, 81)) + + x1.length; +>x1.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 302, 47)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) + + x2.length; +>x2.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 302, 64)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) + + x3.length; +>x3.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 302, 81)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) + + x4.length; +>x4.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 302, 92)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) +} + // Repros from #12011 class Base { ->Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 295, 1)) +>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 319, 1)) get(prop: K) { ->get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 299, 12)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 300, 8)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 300, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 300, 8)) +>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 323, 12)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 324, 8)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 324, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 324, 8)) return this[prop]; ->this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 295, 1)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 300, 30)) +>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 319, 1)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 324, 30)) } set(prop: K, value: this[K]) { ->set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 302, 5)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 303, 8)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 303, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 303, 8)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 303, 38)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 303, 8)) +>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 326, 5)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 327, 8)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 327, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 327, 8)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 327, 38)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 327, 8)) this[prop] = value; ->this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 295, 1)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 303, 30)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 303, 38)) +>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 319, 1)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 327, 30)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 327, 38)) } } class Person extends Base { ->Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 306, 1)) ->Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 295, 1)) +>Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 330, 1)) +>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 319, 1)) parts: number; ->parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 308, 27)) +>parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 332, 27)) constructor(parts: number) { ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 310, 16)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 334, 16)) super(); ->super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 295, 1)) +>super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 319, 1)) this.set("parts", parts); ->this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 302, 5)) ->this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 306, 1)) ->set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 302, 5)) ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 310, 16)) +>this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 326, 5)) +>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 330, 1)) +>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 326, 5)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 334, 16)) } getParts() { ->getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 313, 5)) +>getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 337, 5)) return this.get("parts") ->this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 299, 12)) ->this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 306, 1)) ->get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 299, 12)) +>this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 323, 12)) +>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 330, 1)) +>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 323, 12)) } } class OtherPerson { ->OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 317, 1)) +>OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 341, 1)) parts: number; ->parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 319, 19)) +>parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 343, 19)) constructor(parts: number) { ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 321, 16)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 345, 16)) setProperty(this, "parts", parts); >setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 81, 1)) ->this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 317, 1)) ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 321, 16)) +>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 341, 1)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 345, 16)) } getParts() { ->getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 323, 5)) +>getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 347, 5)) return getProperty(this, "parts") >getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) ->this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 317, 1)) +>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 341, 1)) } } // Modified repro from #12544 function path(obj: T, key1: K1): T[K1]; ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 331, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 331, 16)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 331, 14)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 331, 37)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 331, 14)) ->key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 331, 44)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 331, 16)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 331, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 331, 16)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 351, 1), Decl(keyofAndIndexedAccess.ts, 355, 62), Decl(keyofAndIndexedAccess.ts, 356, 100), Decl(keyofAndIndexedAccess.ts, 357, 142), Decl(keyofAndIndexedAccess.ts, 358, 59)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 355, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 355, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 355, 14)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 355, 37)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 355, 14)) +>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 355, 44)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 355, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 355, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 355, 16)) function path(obj: T, key1: K1, key2: K2): T[K1][K2]; ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 332, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 332, 16)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 332, 14)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 332, 36)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 332, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 332, 16)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 332, 61)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 332, 14)) ->key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 332, 68)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 332, 16)) ->key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 332, 78)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 332, 36)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 332, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 332, 16)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 332, 36)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 351, 1), Decl(keyofAndIndexedAccess.ts, 355, 62), Decl(keyofAndIndexedAccess.ts, 356, 100), Decl(keyofAndIndexedAccess.ts, 357, 142), Decl(keyofAndIndexedAccess.ts, 358, 59)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 356, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 356, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 356, 14)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 356, 36)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 356, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 356, 16)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 356, 61)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 356, 14)) +>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 356, 68)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 356, 16)) +>key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 356, 78)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 356, 36)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 356, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 356, 16)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 356, 36)) function path(obj: T, key1: K1, key2: K2, key3: K3): T[K1][K2][K3]; ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 333, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 333, 16)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 333, 14)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 333, 36)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 333, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 333, 16)) ->K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 333, 60)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 333, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 333, 16)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 333, 36)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 333, 89)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 333, 14)) ->key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 333, 96)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 333, 16)) ->key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 333, 106)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 333, 36)) ->key3 : Symbol(key3, Decl(keyofAndIndexedAccess.ts, 333, 116)) ->K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 333, 60)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 333, 14)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 333, 16)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 333, 36)) ->K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 333, 60)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 351, 1), Decl(keyofAndIndexedAccess.ts, 355, 62), Decl(keyofAndIndexedAccess.ts, 356, 100), Decl(keyofAndIndexedAccess.ts, 357, 142), Decl(keyofAndIndexedAccess.ts, 358, 59)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 357, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 357, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 357, 14)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 357, 36)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 357, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 357, 16)) +>K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 357, 60)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 357, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 357, 16)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 357, 36)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 357, 89)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 357, 14)) +>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 357, 96)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 357, 16)) +>key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 357, 106)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 357, 36)) +>key3 : Symbol(key3, Decl(keyofAndIndexedAccess.ts, 357, 116)) +>K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 357, 60)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 357, 14)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 357, 16)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 357, 36)) +>K3 : Symbol(K3, Decl(keyofAndIndexedAccess.ts, 357, 60)) function path(obj: any, ...keys: (string | number)[]): any; ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 334, 14)) ->keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 334, 23)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 351, 1), Decl(keyofAndIndexedAccess.ts, 355, 62), Decl(keyofAndIndexedAccess.ts, 356, 100), Decl(keyofAndIndexedAccess.ts, 357, 142), Decl(keyofAndIndexedAccess.ts, 358, 59)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 358, 14)) +>keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 358, 23)) function path(obj: any, ...keys: (string | number)[]): any { ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 335, 14)) ->keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 335, 23)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 351, 1), Decl(keyofAndIndexedAccess.ts, 355, 62), Decl(keyofAndIndexedAccess.ts, 356, 100), Decl(keyofAndIndexedAccess.ts, 357, 142), Decl(keyofAndIndexedAccess.ts, 358, 59)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 359, 14)) +>keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 359, 23)) let result = obj; ->result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 336, 7)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 335, 14)) +>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 360, 7)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 359, 14)) for (let k of keys) { ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 337, 12)) ->keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 335, 23)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 361, 12)) +>keys : Symbol(keys, Decl(keyofAndIndexedAccess.ts, 359, 23)) result = result[k]; ->result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 336, 7)) ->result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 336, 7)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 337, 12)) +>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 360, 7)) +>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 360, 7)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 361, 12)) } return result; ->result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 336, 7)) +>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 360, 7)) } type Thing = { ->Thing : Symbol(Thing, Decl(keyofAndIndexedAccess.ts, 341, 1)) +>Thing : Symbol(Thing, Decl(keyofAndIndexedAccess.ts, 365, 1)) a: { x: number, y: string }, ->a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 343, 14)) ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 344, 8)) ->y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 344, 19)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 367, 14)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 368, 8)) +>y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 368, 19)) b: boolean ->b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 344, 32)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 368, 32)) }; function f1(thing: Thing) { ->f1 : Symbol(f1, Decl(keyofAndIndexedAccess.ts, 346, 2)) ->thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 349, 12)) ->Thing : Symbol(Thing, Decl(keyofAndIndexedAccess.ts, 341, 1)) +>f1 : Symbol(f1, Decl(keyofAndIndexedAccess.ts, 370, 2)) +>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 373, 12)) +>Thing : Symbol(Thing, Decl(keyofAndIndexedAccess.ts, 365, 1)) let x1 = path(thing, 'a'); // { x: number, y: string } ->x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 350, 7)) ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59)) ->thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 349, 12)) +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 374, 7)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 351, 1), Decl(keyofAndIndexedAccess.ts, 355, 62), Decl(keyofAndIndexedAccess.ts, 356, 100), Decl(keyofAndIndexedAccess.ts, 357, 142), Decl(keyofAndIndexedAccess.ts, 358, 59)) +>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 373, 12)) let x2 = path(thing, 'a', 'y'); // string ->x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 351, 7)) ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59)) ->thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 349, 12)) +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 375, 7)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 351, 1), Decl(keyofAndIndexedAccess.ts, 355, 62), Decl(keyofAndIndexedAccess.ts, 356, 100), Decl(keyofAndIndexedAccess.ts, 357, 142), Decl(keyofAndIndexedAccess.ts, 358, 59)) +>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 373, 12)) let x3 = path(thing, 'b'); // boolean ->x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 352, 7)) ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59)) ->thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 349, 12)) +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 376, 7)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 351, 1), Decl(keyofAndIndexedAccess.ts, 355, 62), Decl(keyofAndIndexedAccess.ts, 356, 100), Decl(keyofAndIndexedAccess.ts, 357, 142), Decl(keyofAndIndexedAccess.ts, 358, 59)) +>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 373, 12)) let x4 = path(thing, ...['a', 'x']); // any ->x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 353, 7)) ->path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 327, 1), Decl(keyofAndIndexedAccess.ts, 331, 62), Decl(keyofAndIndexedAccess.ts, 332, 100), Decl(keyofAndIndexedAccess.ts, 333, 142), Decl(keyofAndIndexedAccess.ts, 334, 59)) ->thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 349, 12)) +>x4 : Symbol(x4, Decl(keyofAndIndexedAccess.ts, 377, 7)) +>path : Symbol(path, Decl(keyofAndIndexedAccess.ts, 351, 1), Decl(keyofAndIndexedAccess.ts, 355, 62), Decl(keyofAndIndexedAccess.ts, 356, 100), Decl(keyofAndIndexedAccess.ts, 357, 142), Decl(keyofAndIndexedAccess.ts, 358, 59)) +>thing : Symbol(thing, Decl(keyofAndIndexedAccess.ts, 373, 12)) } // Repro from comment in #12114 const assignTo2 = (object: T, key1: K1, key2: K2) => ->assignTo2 : Symbol(assignTo2, Decl(keyofAndIndexedAccess.ts, 358, 5)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 358, 19)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 358, 21)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 358, 19)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 358, 41)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 358, 19)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 358, 21)) ->object : Symbol(object, Decl(keyofAndIndexedAccess.ts, 358, 66)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 358, 19)) ->key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 358, 76)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 358, 21)) ->key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 358, 86)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 358, 41)) +>assignTo2 : Symbol(assignTo2, Decl(keyofAndIndexedAccess.ts, 382, 5)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 382, 19)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 382, 21)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 382, 19)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 382, 41)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 382, 19)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 382, 21)) +>object : Symbol(object, Decl(keyofAndIndexedAccess.ts, 382, 66)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 382, 19)) +>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 382, 76)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 382, 21)) +>key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 382, 86)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 382, 41)) (value: T[K1][K2]) => object[key1][key2] = value; ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 359, 5)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 358, 19)) ->K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 358, 21)) ->K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 358, 41)) ->object : Symbol(object, Decl(keyofAndIndexedAccess.ts, 358, 66)) ->key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 358, 76)) ->key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 358, 86)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 359, 5)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 383, 5)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 382, 19)) +>K1 : Symbol(K1, Decl(keyofAndIndexedAccess.ts, 382, 21)) +>K2 : Symbol(K2, Decl(keyofAndIndexedAccess.ts, 382, 41)) +>object : Symbol(object, Decl(keyofAndIndexedAccess.ts, 382, 66)) +>key1 : Symbol(key1, Decl(keyofAndIndexedAccess.ts, 382, 76)) +>key2 : Symbol(key2, Decl(keyofAndIndexedAccess.ts, 382, 86)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 383, 5)) // Modified repro from #12573 declare function one(handler: (t: T) => void): T ->one : Symbol(one, Decl(keyofAndIndexedAccess.ts, 359, 53)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 363, 21)) ->handler : Symbol(handler, Decl(keyofAndIndexedAccess.ts, 363, 24)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 363, 34)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 363, 21)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 363, 21)) +>one : Symbol(one, Decl(keyofAndIndexedAccess.ts, 383, 53)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 387, 21)) +>handler : Symbol(handler, Decl(keyofAndIndexedAccess.ts, 387, 24)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 387, 34)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 387, 21)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 387, 21)) var empty = one(() => {}) // inferred as {}, expected ->empty : Symbol(empty, Decl(keyofAndIndexedAccess.ts, 364, 3)) ->one : Symbol(one, Decl(keyofAndIndexedAccess.ts, 359, 53)) +>empty : Symbol(empty, Decl(keyofAndIndexedAccess.ts, 388, 3)) +>one : Symbol(one, Decl(keyofAndIndexedAccess.ts, 383, 53)) type Handlers = { [K in keyof T]: (t: T[K]) => void } ->Handlers : Symbol(Handlers, Decl(keyofAndIndexedAccess.ts, 364, 25)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 366, 14)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 366, 22)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 366, 14)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 366, 38)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 366, 14)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 366, 22)) +>Handlers : Symbol(Handlers, Decl(keyofAndIndexedAccess.ts, 388, 25)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 390, 14)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 390, 22)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 390, 14)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 390, 38)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 390, 14)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 390, 22)) declare function on(handlerHash: Handlers): T ->on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 366, 56)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 367, 20)) ->handlerHash : Symbol(handlerHash, Decl(keyofAndIndexedAccess.ts, 367, 23)) ->Handlers : Symbol(Handlers, Decl(keyofAndIndexedAccess.ts, 364, 25)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 367, 20)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 367, 20)) +>on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 390, 56)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 391, 20)) +>handlerHash : Symbol(handlerHash, Decl(keyofAndIndexedAccess.ts, 391, 23)) +>Handlers : Symbol(Handlers, Decl(keyofAndIndexedAccess.ts, 388, 25)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 391, 20)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 391, 20)) var hashOfEmpty1 = on({ test: () => {} }); // {} ->hashOfEmpty1 : Symbol(hashOfEmpty1, Decl(keyofAndIndexedAccess.ts, 368, 3)) ->on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 366, 56)) ->test : Symbol(test, Decl(keyofAndIndexedAccess.ts, 368, 23)) +>hashOfEmpty1 : Symbol(hashOfEmpty1, Decl(keyofAndIndexedAccess.ts, 392, 3)) +>on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 390, 56)) +>test : Symbol(test, Decl(keyofAndIndexedAccess.ts, 392, 23)) var hashOfEmpty2 = on({ test: (x: boolean) => {} }); // { test: boolean } ->hashOfEmpty2 : Symbol(hashOfEmpty2, Decl(keyofAndIndexedAccess.ts, 369, 3)) ->on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 366, 56)) ->test : Symbol(test, Decl(keyofAndIndexedAccess.ts, 369, 23)) ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 369, 31)) +>hashOfEmpty2 : Symbol(hashOfEmpty2, Decl(keyofAndIndexedAccess.ts, 393, 3)) +>on : Symbol(on, Decl(keyofAndIndexedAccess.ts, 390, 56)) +>test : Symbol(test, Decl(keyofAndIndexedAccess.ts, 393, 23)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 393, 31)) // Repro from #12624 interface Options1 { ->Options1 : Symbol(Options1, Decl(keyofAndIndexedAccess.ts, 369, 52)) ->Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 373, 19)) ->Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 373, 24)) +>Options1 : Symbol(Options1, Decl(keyofAndIndexedAccess.ts, 393, 52)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 397, 19)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 397, 24)) data?: Data ->data : Symbol(Options1.data, Decl(keyofAndIndexedAccess.ts, 373, 36)) ->Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 373, 19)) +>data : Symbol(Options1.data, Decl(keyofAndIndexedAccess.ts, 397, 36)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 397, 19)) computed?: Computed; ->computed : Symbol(Options1.computed, Decl(keyofAndIndexedAccess.ts, 374, 15)) ->Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 373, 24)) +>computed : Symbol(Options1.computed, Decl(keyofAndIndexedAccess.ts, 398, 15)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 397, 24)) } declare class Component1 { ->Component1 : Symbol(Component1, Decl(keyofAndIndexedAccess.ts, 376, 1)) ->Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 378, 25)) ->Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 378, 30)) +>Component1 : Symbol(Component1, Decl(keyofAndIndexedAccess.ts, 400, 1)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 402, 25)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 402, 30)) constructor(options: Options1); ->options : Symbol(options, Decl(keyofAndIndexedAccess.ts, 379, 16)) ->Options1 : Symbol(Options1, Decl(keyofAndIndexedAccess.ts, 369, 52)) ->Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 378, 25)) ->Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 378, 30)) +>options : Symbol(options, Decl(keyofAndIndexedAccess.ts, 403, 16)) +>Options1 : Symbol(Options1, Decl(keyofAndIndexedAccess.ts, 393, 52)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 402, 25)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 402, 30)) get(key: K): (Data & Computed)[K]; ->get : Symbol(Component1.get, Decl(keyofAndIndexedAccess.ts, 379, 51)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 380, 8)) ->Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 378, 25)) ->Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 378, 30)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 380, 43)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 380, 8)) ->Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 378, 25)) ->Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 378, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 380, 8)) +>get : Symbol(Component1.get, Decl(keyofAndIndexedAccess.ts, 403, 51)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 404, 8)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 402, 25)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 402, 30)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 404, 43)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 404, 8)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 402, 25)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 402, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 404, 8)) } let c1 = new Component1({ ->c1 : Symbol(c1, Decl(keyofAndIndexedAccess.ts, 383, 3)) ->Component1 : Symbol(Component1, Decl(keyofAndIndexedAccess.ts, 376, 1)) +>c1 : Symbol(c1, Decl(keyofAndIndexedAccess.ts, 407, 3)) +>Component1 : Symbol(Component1, Decl(keyofAndIndexedAccess.ts, 400, 1)) data: { ->data : Symbol(data, Decl(keyofAndIndexedAccess.ts, 383, 25)) +>data : Symbol(data, Decl(keyofAndIndexedAccess.ts, 407, 25)) hello: "" ->hello : Symbol(hello, Decl(keyofAndIndexedAccess.ts, 384, 11)) +>hello : Symbol(hello, Decl(keyofAndIndexedAccess.ts, 408, 11)) } }); c1.get("hello"); ->c1.get : Symbol(Component1.get, Decl(keyofAndIndexedAccess.ts, 379, 51)) ->c1 : Symbol(c1, Decl(keyofAndIndexedAccess.ts, 383, 3)) ->get : Symbol(Component1.get, Decl(keyofAndIndexedAccess.ts, 379, 51)) +>c1.get : Symbol(Component1.get, Decl(keyofAndIndexedAccess.ts, 403, 51)) +>c1 : Symbol(c1, Decl(keyofAndIndexedAccess.ts, 407, 3)) +>get : Symbol(Component1.get, Decl(keyofAndIndexedAccess.ts, 403, 51)) // Repro from #12625 interface Options2 { ->Options2 : Symbol(Options2, Decl(keyofAndIndexedAccess.ts, 389, 16)) ->Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 393, 19)) ->Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 393, 24)) +>Options2 : Symbol(Options2, Decl(keyofAndIndexedAccess.ts, 413, 16)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 417, 19)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 417, 24)) data?: Data ->data : Symbol(Options2.data, Decl(keyofAndIndexedAccess.ts, 393, 36)) ->Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 393, 19)) +>data : Symbol(Options2.data, Decl(keyofAndIndexedAccess.ts, 417, 36)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 417, 19)) computed?: Computed; ->computed : Symbol(Options2.computed, Decl(keyofAndIndexedAccess.ts, 394, 15)) ->Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 393, 24)) +>computed : Symbol(Options2.computed, Decl(keyofAndIndexedAccess.ts, 418, 15)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 417, 24)) } declare class Component2 { ->Component2 : Symbol(Component2, Decl(keyofAndIndexedAccess.ts, 396, 1)) ->Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 398, 25)) ->Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 398, 30)) +>Component2 : Symbol(Component2, Decl(keyofAndIndexedAccess.ts, 420, 1)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 422, 25)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 422, 30)) constructor(options: Options2); ->options : Symbol(options, Decl(keyofAndIndexedAccess.ts, 399, 16)) ->Options2 : Symbol(Options2, Decl(keyofAndIndexedAccess.ts, 389, 16)) ->Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 398, 25)) ->Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 398, 30)) +>options : Symbol(options, Decl(keyofAndIndexedAccess.ts, 423, 16)) +>Options2 : Symbol(Options2, Decl(keyofAndIndexedAccess.ts, 413, 16)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 422, 25)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 422, 30)) get(key: K): (Data & Computed)[K]; ->get : Symbol(Component2.get, Decl(keyofAndIndexedAccess.ts, 399, 51)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 400, 8)) ->Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 398, 25)) ->Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 398, 30)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 400, 47)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 400, 8)) ->Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 398, 25)) ->Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 398, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 400, 8)) +>get : Symbol(Component2.get, Decl(keyofAndIndexedAccess.ts, 423, 51)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 424, 8)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 422, 25)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 422, 30)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 424, 47)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 424, 8)) +>Data : Symbol(Data, Decl(keyofAndIndexedAccess.ts, 422, 25)) +>Computed : Symbol(Computed, Decl(keyofAndIndexedAccess.ts, 422, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 424, 8)) } // Repro from #12641 interface R { ->R : Symbol(R, Decl(keyofAndIndexedAccess.ts, 401, 1)) +>R : Symbol(R, Decl(keyofAndIndexedAccess.ts, 425, 1)) p: number; ->p : Symbol(R.p, Decl(keyofAndIndexedAccess.ts, 405, 13)) +>p : Symbol(R.p, Decl(keyofAndIndexedAccess.ts, 429, 13)) } function f(p: K) { ->f : Symbol(f, Decl(keyofAndIndexedAccess.ts, 407, 1)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 409, 11)) ->R : Symbol(R, Decl(keyofAndIndexedAccess.ts, 401, 1)) ->p : Symbol(p, Decl(keyofAndIndexedAccess.ts, 409, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 409, 11)) +>f : Symbol(f, Decl(keyofAndIndexedAccess.ts, 431, 1)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 433, 11)) +>R : Symbol(R, Decl(keyofAndIndexedAccess.ts, 425, 1)) +>p : Symbol(p, Decl(keyofAndIndexedAccess.ts, 433, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 433, 11)) let a: any; ->a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 410, 7)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 434, 7)) a[p].add; // any ->a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 410, 7)) ->p : Symbol(p, Decl(keyofAndIndexedAccess.ts, 409, 30)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 434, 7)) +>p : Symbol(p, Decl(keyofAndIndexedAccess.ts, 433, 30)) } // Repro from #12651 type MethodDescriptor = { ->MethodDescriptor : Symbol(MethodDescriptor, Decl(keyofAndIndexedAccess.ts, 412, 1)) +>MethodDescriptor : Symbol(MethodDescriptor, Decl(keyofAndIndexedAccess.ts, 436, 1)) name: string; ->name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 416, 25)) +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 440, 25)) args: any[]; ->args : Symbol(args, Decl(keyofAndIndexedAccess.ts, 417, 14)) +>args : Symbol(args, Decl(keyofAndIndexedAccess.ts, 441, 14)) returnValue: any; ->returnValue : Symbol(returnValue, Decl(keyofAndIndexedAccess.ts, 418, 13)) +>returnValue : Symbol(returnValue, Decl(keyofAndIndexedAccess.ts, 442, 13)) } declare function dispatchMethod(name: M['name'], args: M['args']): M['returnValue']; ->dispatchMethod : Symbol(dispatchMethod, Decl(keyofAndIndexedAccess.ts, 420, 1)) ->M : Symbol(M, Decl(keyofAndIndexedAccess.ts, 422, 32)) ->MethodDescriptor : Symbol(MethodDescriptor, Decl(keyofAndIndexedAccess.ts, 412, 1)) ->name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 422, 60)) ->M : Symbol(M, Decl(keyofAndIndexedAccess.ts, 422, 32)) ->args : Symbol(args, Decl(keyofAndIndexedAccess.ts, 422, 76)) ->M : Symbol(M, Decl(keyofAndIndexedAccess.ts, 422, 32)) ->M : Symbol(M, Decl(keyofAndIndexedAccess.ts, 422, 32)) +>dispatchMethod : Symbol(dispatchMethod, Decl(keyofAndIndexedAccess.ts, 444, 1)) +>M : Symbol(M, Decl(keyofAndIndexedAccess.ts, 446, 32)) +>MethodDescriptor : Symbol(MethodDescriptor, Decl(keyofAndIndexedAccess.ts, 436, 1)) +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 446, 60)) +>M : Symbol(M, Decl(keyofAndIndexedAccess.ts, 446, 32)) +>args : Symbol(args, Decl(keyofAndIndexedAccess.ts, 446, 76)) +>M : Symbol(M, Decl(keyofAndIndexedAccess.ts, 446, 32)) +>M : Symbol(M, Decl(keyofAndIndexedAccess.ts, 446, 32)) type SomeMethodDescriptor = { ->SomeMethodDescriptor : Symbol(SomeMethodDescriptor, Decl(keyofAndIndexedAccess.ts, 422, 112)) +>SomeMethodDescriptor : Symbol(SomeMethodDescriptor, Decl(keyofAndIndexedAccess.ts, 446, 112)) name: "someMethod"; ->name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 424, 29)) +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 448, 29)) args: [string, number]; ->args : Symbol(args, Decl(keyofAndIndexedAccess.ts, 425, 20)) +>args : Symbol(args, Decl(keyofAndIndexedAccess.ts, 449, 20)) returnValue: string[]; ->returnValue : Symbol(returnValue, Decl(keyofAndIndexedAccess.ts, 426, 24)) +>returnValue : Symbol(returnValue, Decl(keyofAndIndexedAccess.ts, 450, 24)) } let result = dispatchMethod("someMethod", ["hello", 35]); ->result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 430, 3)) ->dispatchMethod : Symbol(dispatchMethod, Decl(keyofAndIndexedAccess.ts, 420, 1)) ->SomeMethodDescriptor : Symbol(SomeMethodDescriptor, Decl(keyofAndIndexedAccess.ts, 422, 112)) +>result : Symbol(result, Decl(keyofAndIndexedAccess.ts, 454, 3)) +>dispatchMethod : Symbol(dispatchMethod, Decl(keyofAndIndexedAccess.ts, 444, 1)) +>SomeMethodDescriptor : Symbol(SomeMethodDescriptor, Decl(keyofAndIndexedAccess.ts, 446, 112)) + +// Repro from #13073 + +type KeyTypes = "a" | "b" +>KeyTypes : Symbol(KeyTypes, Decl(keyofAndIndexedAccess.ts, 454, 79)) + +let MyThingy: { [key in KeyTypes]: string[] }; +>MyThingy : Symbol(MyThingy, Decl(keyofAndIndexedAccess.ts, 459, 3)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 459, 17)) +>KeyTypes : Symbol(KeyTypes, Decl(keyofAndIndexedAccess.ts, 454, 79)) + +function addToMyThingy(key: S) { +>addToMyThingy : Symbol(addToMyThingy, Decl(keyofAndIndexedAccess.ts, 459, 46)) +>S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 461, 23)) +>KeyTypes : Symbol(KeyTypes, Decl(keyofAndIndexedAccess.ts, 454, 79)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 461, 43)) +>S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 461, 23)) + + MyThingy[key].push("a"); +>MyThingy[key].push : Symbol(Array.push, Decl(lib.d.ts, --, --)) +>MyThingy : Symbol(MyThingy, Decl(keyofAndIndexedAccess.ts, 459, 3)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 461, 43)) +>push : Symbol(Array.push, Decl(lib.d.ts, --, --)) +} + +// Repro from #13285 + +function updateIds, K extends string>( +>updateIds : Symbol(updateIds, Decl(keyofAndIndexedAccess.ts, 463, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 467, 19)) +>Record : Symbol(Record, Decl(lib.d.ts, --, --)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 467, 47)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 467, 47)) + + obj: T, +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 467, 66)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 467, 19)) + + idFields: K[], +>idFields : Symbol(idFields, Decl(keyofAndIndexedAccess.ts, 468, 11)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 467, 47)) + + idMapping: { [oldId: string]: string } +>idMapping : Symbol(idMapping, Decl(keyofAndIndexedAccess.ts, 469, 18)) +>oldId : Symbol(oldId, Decl(keyofAndIndexedAccess.ts, 470, 18)) + +): Record { +>Record : Symbol(Record, Decl(lib.d.ts, --, --)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 467, 47)) + + for (const idField of idFields) { +>idField : Symbol(idField, Decl(keyofAndIndexedAccess.ts, 472, 14)) +>idFields : Symbol(idFields, Decl(keyofAndIndexedAccess.ts, 468, 11)) + + const newId = idMapping[obj[idField]]; +>newId : Symbol(newId, Decl(keyofAndIndexedAccess.ts, 473, 13)) +>idMapping : Symbol(idMapping, Decl(keyofAndIndexedAccess.ts, 469, 18)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 467, 66)) +>idField : Symbol(idField, Decl(keyofAndIndexedAccess.ts, 472, 14)) + + if (newId) { +>newId : Symbol(newId, Decl(keyofAndIndexedAccess.ts, 473, 13)) + + obj[idField] = newId; +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 467, 66)) +>idField : Symbol(idField, Decl(keyofAndIndexedAccess.ts, 472, 14)) +>newId : Symbol(newId, Decl(keyofAndIndexedAccess.ts, 473, 13)) + } + } + return obj; +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 467, 66)) +} + +// Repro from #13285 + +function updateIds2( +>updateIds2 : Symbol(updateIds2, Decl(keyofAndIndexedAccess.ts, 479, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 483, 20)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 483, 33)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 483, 54)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 483, 20)) + + obj: T, +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 483, 74)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 483, 20)) + + key: K, +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 484, 11)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 483, 54)) + + stringMap: { [oldId: string]: string } +>stringMap : Symbol(stringMap, Decl(keyofAndIndexedAccess.ts, 485, 11)) +>oldId : Symbol(oldId, Decl(keyofAndIndexedAccess.ts, 486, 18)) + +) { + var x = obj[key]; +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 488, 7)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 483, 74)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 484, 11)) + + stringMap[x]; // Should be OK. +>stringMap : Symbol(stringMap, Decl(keyofAndIndexedAccess.ts, 485, 11)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 488, 7)) +} diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types index f94249806f603..920758c8beb49 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.types +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -1385,6 +1385,117 @@ class C1 { } } +type S2 = { +>S2 : S2 + + a: string; +>a : string + + b: string; +>b : string + +}; + +function f90(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K], x4: T[K]) { +>f90 : (x1: string, x2: T["a" | "b"], x3: S2[K], x4: T[K]) => void +>T : T +>S2 : S2 +>K : K +>S2 : S2 +>x1 : string +>S2 : S2 +>S2 : S2 +>x2 : T["a" | "b"] +>T : T +>S2 : S2 +>x3 : S2[K] +>S2 : S2 +>K : K +>x4 : T[K] +>T : T +>K : K + + x1 = x2; +>x1 = x2 : T["a" | "b"] +>x1 : string +>x2 : T["a" | "b"] + + x1 = x3; +>x1 = x3 : S2[K] +>x1 : string +>x3 : S2[K] + + x1 = x4; +>x1 = x4 : T[K] +>x1 : string +>x4 : T[K] + + x2 = x1; +>x2 = x1 : string +>x2 : T["a" | "b"] +>x1 : string + + x2 = x3; +>x2 = x3 : S2[K] +>x2 : T["a" | "b"] +>x3 : S2[K] + + x2 = x4; +>x2 = x4 : T[K] +>x2 : T["a" | "b"] +>x4 : T[K] + + x3 = x1; +>x3 = x1 : string +>x3 : S2[K] +>x1 : string + + x3 = x2; +>x3 = x2 : T["a" | "b"] +>x3 : S2[K] +>x2 : T["a" | "b"] + + x3 = x4; +>x3 = x4 : T[K] +>x3 : S2[K] +>x4 : T[K] + + x4 = x1; +>x4 = x1 : string +>x4 : T[K] +>x1 : string + + x4 = x2; +>x4 = x2 : T["a" | "b"] +>x4 : T[K] +>x2 : T["a" | "b"] + + x4 = x3; +>x4 = x3 : S2[K] +>x4 : T[K] +>x3 : S2[K] + + x1.length; +>x1.length : number +>x1 : string +>length : number + + x2.length; +>x2.length : number +>x2 : T["a" | "b"] +>length : number + + x3.length; +>x3.length : number +>x3 : S2[K] +>length : number + + x4.length; +>x4.length : number +>x4 : T[K] +>length : number +} + // Repros from #12011 class Base { @@ -1875,3 +1986,116 @@ let result = dispatchMethod("someMethod", ["hello", 35]); >"hello" : "hello" >35 : 35 +// Repro from #13073 + +type KeyTypes = "a" | "b" +>KeyTypes : "a" | "b" + +let MyThingy: { [key in KeyTypes]: string[] }; +>MyThingy : { a: string[]; b: string[]; } +>key : key +>KeyTypes : "a" | "b" + +function addToMyThingy(key: S) { +>addToMyThingy : (key: S) => void +>S : S +>KeyTypes : "a" | "b" +>key : S +>S : S + + MyThingy[key].push("a"); +>MyThingy[key].push("a") : number +>MyThingy[key].push : (...items: string[]) => number +>MyThingy[key] : { a: string[]; b: string[]; }[S] +>MyThingy : { a: string[]; b: string[]; } +>key : S +>push : (...items: string[]) => number +>"a" : "a" +} + +// Repro from #13285 + +function updateIds, K extends string>( +>updateIds : , K extends string>(obj: T, idFields: K[], idMapping: { [oldId: string]: string; }) => Record +>T : T +>Record : Record +>K : K +>K : K + + obj: T, +>obj : T +>T : T + + idFields: K[], +>idFields : K[] +>K : K + + idMapping: { [oldId: string]: string } +>idMapping : { [oldId: string]: string; } +>oldId : string + +): Record { +>Record : Record +>K : K + + for (const idField of idFields) { +>idField : K +>idFields : K[] + + const newId = idMapping[obj[idField]]; +>newId : { [oldId: string]: string; }[T[K]] +>idMapping[obj[idField]] : { [oldId: string]: string; }[T[K]] +>idMapping : { [oldId: string]: string; } +>obj[idField] : T[K] +>obj : T +>idField : K + + if (newId) { +>newId : { [oldId: string]: string; }[T[K]] + + obj[idField] = newId; +>obj[idField] = newId : { [oldId: string]: string; }[T[K]] +>obj[idField] : T[K] +>obj : T +>idField : K +>newId : { [oldId: string]: string; }[T[K]] + } + } + return obj; +>obj : T +} + +// Repro from #13285 + +function updateIds2( +>updateIds2 : (obj: T, key: K, stringMap: { [oldId: string]: string; }) => void +>T : T +>x : string +>K : K +>T : T + + obj: T, +>obj : T +>T : T + + key: K, +>key : K +>K : K + + stringMap: { [oldId: string]: string } +>stringMap : { [oldId: string]: string; } +>oldId : string + +) { + var x = obj[key]; +>x : T[K] +>obj[key] : T[K] +>obj : T +>key : K + + stringMap[x]; // Should be OK. +>stringMap[x] : { [oldId: string]: string; }[T[K]] +>stringMap : { [oldId: string]: string; } +>x : T[K] +} + diff --git a/tests/baselines/reference/mappedTypeErrors.errors.txt b/tests/baselines/reference/mappedTypeErrors.errors.txt index 94644a96af9bd..c7571295521c1 100644 --- a/tests/baselines/reference/mappedTypeErrors.errors.txt +++ b/tests/baselines/reference/mappedTypeErrors.errors.txt @@ -45,7 +45,7 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(130,5): error TS2322: T tests/cases/conformance/types/mapped/mappedTypeErrors.ts(131,5): error TS2322: Type '{ a: string; }' is not assignable to type '{ [x: string]: any; a?: number | undefined; }'. Types of property 'a' are incompatible. Type 'string' is not assignable to type 'number | undefined'. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(137,16): error TS2322: Type '{}' is not assignable to type 'string'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(137,16): error TS2322: Type 'T' is not assignable to type 'string'. tests/cases/conformance/types/mapped/mappedTypeErrors.ts(137,21): error TS2536: Type 'P' cannot be used to index type 'T'. @@ -259,7 +259,7 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(137,21): error TS2536: pf: {[P in F]?: T[P]}, pt: {[P in T]?: T[P]}, // note: should be in keyof T ~ -!!! error TS2322: Type '{}' is not assignable to type 'string'. +!!! error TS2322: Type 'T' is not assignable to type 'string'. ~~~~ !!! error TS2536: Type 'P' cannot be used to index type 'T'. }; diff --git a/tests/baselines/reference/mappedTypeRelationships.errors.txt b/tests/baselines/reference/mappedTypeRelationships.errors.txt index e8e0371ed9ae2..ce6ecaa61fab8 100644 --- a/tests/baselines/reference/mappedTypeRelationships.errors.txt +++ b/tests/baselines/reference/mappedTypeRelationships.errors.txt @@ -3,8 +3,12 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(12,5): error TS2 tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(17,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(21,5): error TS2536: Type 'keyof U' cannot be used to index type 'T'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(22,5): error TS2322: Type 'T[keyof U]' is not assignable to type 'U[keyof U]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(22,12): error TS2536: Type 'keyof U' cannot be used to index type 'T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(26,5): error TS2536: Type 'K' cannot be used to index type 'T'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(27,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(27,12): error TS2536: Type 'K' cannot be used to index type 'T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(31,5): error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'. Type 'undefined' is not assignable to type 'T[keyof T]'. @@ -28,7 +32,7 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(71,5): error TS2 tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(76,5): error TS2322: Type 'Partial' is not assignable to type 'T'. -==== tests/cases/conformance/types/mapped/mappedTypeRelationships.ts (18 errors) ==== +==== tests/cases/conformance/types/mapped/mappedTypeRelationships.ts (20 errors) ==== function f1(x: T, k: keyof T) { return x[k]; @@ -59,6 +63,9 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(76,5): error TS2 ~~~~ !!! error TS2536: Type 'keyof U' cannot be used to index type 'T'. y[k] = x[k]; // Error + ~~~~ +!!! error TS2322: Type 'T[keyof U]' is not assignable to type 'U[keyof U]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. ~~~~ !!! error TS2536: Type 'keyof U' cannot be used to index type 'T'. } @@ -68,6 +75,9 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(76,5): error TS2 ~~~~ !!! error TS2536: Type 'K' cannot be used to index type 'T'. y[k] = x[k]; // Error + ~~~~ +!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. ~~~~ !!! error TS2536: Type 'K' cannot be used to index type 'T'. } diff --git a/tests/baselines/reference/typeParameterIndirectlyConstrainedToItself.errors.txt b/tests/baselines/reference/typeParameterIndirectlyConstrainedToItself.errors.txt index 4cfa9da213395..ac7b58bb846b5 100644 --- a/tests/baselines/reference/typeParameterIndirectlyConstrainedToItself.errors.txt +++ b/tests/baselines/reference/typeParameterIndirectlyConstrainedToItself.errors.txt @@ -23,11 +23,12 @@ tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterInd tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(16,21): error TS2313: Type parameter 'T' has a circular constraint. tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(16,34): error TS2313: Type parameter 'U' has a circular constraint. tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(16,47): error TS2313: Type parameter 'V' has a circular constraint. +tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(18,19): error TS2313: Type parameter 'U' has a circular constraint. tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(18,32): error TS2313: Type parameter 'T' has a circular constraint. tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts(18,45): error TS2313: Type parameter 'V' has a circular constraint. -==== tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts (27 errors) ==== +==== tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterIndirectlyConstrainedToItself.ts (28 errors) ==== class C { } ~ !!! error TS2313: Type parameter 'U' has a circular constraint. @@ -96,6 +97,8 @@ tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterInd !!! error TS2313: Type parameter 'V' has a circular constraint. class D { } + ~ +!!! error TS2313: Type parameter 'U' has a circular constraint. ~ !!! error TS2313: Type parameter 'T' has a circular constraint. ~ diff --git a/tests/baselines/reference/typeParameterWithInvalidConstraintType.errors.txt b/tests/baselines/reference/typeParameterWithInvalidConstraintType.errors.txt index 79af423f91753..e9dfb5ba3cd4b 100644 --- a/tests/baselines/reference/typeParameterWithInvalidConstraintType.errors.txt +++ b/tests/baselines/reference/typeParameterWithInvalidConstraintType.errors.txt @@ -1,16 +1,24 @@ tests/cases/compiler/typeParameterWithInvalidConstraintType.ts(1,19): error TS2313: Type parameter 'T' has a circular constraint. +tests/cases/compiler/typeParameterWithInvalidConstraintType.ts(4,19): error TS2339: Property 'foo' does not exist on type 'T'. +tests/cases/compiler/typeParameterWithInvalidConstraintType.ts(5,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/compiler/typeParameterWithInvalidConstraintType.ts(7,17): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '{}' has no compatible call signatures. -==== tests/cases/compiler/typeParameterWithInvalidConstraintType.ts (1 errors) ==== +==== tests/cases/compiler/typeParameterWithInvalidConstraintType.ts (4 errors) ==== class A { ~ !!! error TS2313: Type parameter 'T' has a circular constraint. foo() { var x: T; - // no error expected below this line var a = x.foo(); + ~~~ +!!! error TS2339: Property 'foo' does not exist on type 'T'. var b = new x(123); + ~~~~~~~~~~ +!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. var c = x[1]; var d = x(); + ~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '{}' has no compatible call signatures. } } \ No newline at end of file diff --git a/tests/baselines/reference/typeParameterWithInvalidConstraintType.js b/tests/baselines/reference/typeParameterWithInvalidConstraintType.js index a40056f6a5963..40a2aeacf4b3e 100644 --- a/tests/baselines/reference/typeParameterWithInvalidConstraintType.js +++ b/tests/baselines/reference/typeParameterWithInvalidConstraintType.js @@ -2,7 +2,6 @@ class A { foo() { var x: T; - // no error expected below this line var a = x.foo(); var b = new x(123); var c = x[1]; @@ -16,7 +15,6 @@ var A = (function () { } A.prototype.foo = function () { var x; - // no error expected below this line var a = x.foo(); var b = new x(123); var c = x[1]; diff --git a/tests/cases/compiler/typeParameterWithInvalidConstraintType.ts b/tests/cases/compiler/typeParameterWithInvalidConstraintType.ts index 7c92ad4575ac6..a97876b0ab34c 100644 --- a/tests/cases/compiler/typeParameterWithInvalidConstraintType.ts +++ b/tests/cases/compiler/typeParameterWithInvalidConstraintType.ts @@ -1,7 +1,6 @@ class A { foo() { var x: T; - // no error expected below this line var a = x.foo(); var b = new x(123); var c = x[1]; diff --git a/tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts b/tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts index c01030c7fa9b8..a53fc6fbf7295 100644 --- a/tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts +++ b/tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts @@ -13,7 +13,7 @@ declare let x2: T2<"x">; let x2x = x2.x; interface T3> { - x: T["x"]; // Error + x: T["x"]; } interface T4> { @@ -25,7 +25,16 @@ class C1 { } class C2 { - x: this["y"]; // Error - y: this["z"]; // Error - z: this["x"]; // Error -} \ No newline at end of file + x: this["y"]; + y: this["z"]; + z: this["x"]; +} + +// Repro from #12627 + +interface Foo { + hello: boolean; +} + +function foo() { +} diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts index ea6a3c2358a3a..770dc2ead9809 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts @@ -297,6 +297,30 @@ class C1 { } } +type S2 = { + a: string; + b: string; +}; + +function f90(x1: S2[keyof S2], x2: T[keyof S2], x3: S2[K], x4: T[K]) { + x1 = x2; + x1 = x3; + x1 = x4; + x2 = x1; + x2 = x3; + x2 = x4; + x3 = x1; + x3 = x2; + x3 = x4; + x4 = x1; + x4 = x2; + x4 = x3; + x1.length; + x2.length; + x3.length; + x4.length; +} + // Repros from #12011 class Base { @@ -430,4 +454,40 @@ type SomeMethodDescriptor = { returnValue: string[]; } -let result = dispatchMethod("someMethod", ["hello", 35]); \ No newline at end of file +let result = dispatchMethod("someMethod", ["hello", 35]); + +// Repro from #13073 + +type KeyTypes = "a" | "b" +let MyThingy: { [key in KeyTypes]: string[] }; + +function addToMyThingy(key: S) { + MyThingy[key].push("a"); +} + +// Repro from #13285 + +function updateIds, K extends string>( + obj: T, + idFields: K[], + idMapping: { [oldId: string]: string } +): Record { + for (const idField of idFields) { + const newId = idMapping[obj[idField]]; + if (newId) { + obj[idField] = newId; + } + } + return obj; +} + +// Repro from #13285 + +function updateIds2( + obj: T, + key: K, + stringMap: { [oldId: string]: string } +) { + var x = obj[key]; + stringMap[x]; // Should be OK. +}