From 44116b52419708009eb32f67b49b19ed09f3036d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 11 Dec 2018 12:11:07 -0800 Subject: [PATCH 1/6] Simplify indexed accesses on mapped types up to five levels deep --- src/compiler/checker.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2eeea77e49268..8001165e4910b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -67,6 +67,7 @@ namespace ts { let enumCount = 0; let instantiationDepth = 0; let constraintDepth = 0; + let simplificationDepth = 0; const emptySymbols = createSymbolTable(); const identityMapper: (type: Type) => Type = identity; @@ -9686,24 +9687,29 @@ namespace ts { // 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 - // construct the type Box. We do not further simplify the result because mapped types can be recursive - // and we might never terminate. - if (isGenericMappedType(objectType)) { - return type.simplified = substituteIndexedMappedType(objectType, type); - } - if (objectType.flags & TypeFlags.TypeParameter) { - const constraint = getConstraintOfTypeParameter(objectType as TypeParameter); - if (constraint && isGenericMappedType(constraint)) { - return type.simplified = substituteIndexedMappedType(constraint, type); + // construct the type Box. Mapped types can be recursive so to guard against infinite recursion we + // only perform this simplification up to five levels deep. + if (simplificationDepth < 5) { + if (isGenericMappedType(objectType)) { + return type.simplified = substituteIndexedMappedType(objectType, type); + } + if (objectType.flags & TypeFlags.TypeParameter) { + const constraint = getConstraintOfTypeParameter(objectType as TypeParameter); + if (constraint && isGenericMappedType(constraint)) { + return type.simplified = substituteIndexedMappedType(constraint, type); + } } } return type.simplified = type; } function substituteIndexedMappedType(objectType: MappedType, type: IndexedAccessType) { + simplificationDepth++; const mapper = createTypeMapper([getTypeParameterFromMappedType(objectType)], [type.indexType]); const templateMapper = combineTypeMappers(objectType.mapper, mapper); - return instantiateType(getTemplateTypeFromMappedType(objectType), templateMapper); + const result = mapType(instantiateType(getTemplateTypeFromMappedType(objectType), templateMapper), getSimplifiedType); + simplificationDepth--; + return result; } function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode | PropertyName, missingType = accessNode ? errorType : unknownType): Type { From 2150a64f0cd457a791ac30c8850934cd6ee35704 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 11 Dec 2018 12:11:16 -0800 Subject: [PATCH 2/6] Add tests --- .../types/keyof/keyofAndIndexedAccessErrors.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts index a4ed608d8e71c..a179935d0ecfd 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts @@ -141,3 +141,19 @@ function test1, K extends keyof T>(t: T, k: K) { t[k] = "hello"; // Error t[k] = [10, 20]; // Error } + +// Repro from #28839 + +function f30() { + let x: Partial>[K] = "hello"; +} + +// We simplify indexed accesses applied to mapped types up to five levels deep + +function f31() { + let x: Partial>>>>[K] = "hello"; +} + +function f32() { + let x: Partial>>>>>[K] = "hello"; +} From 02b13a916a07cbd54e3132ea703e0be2035a1866 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 11 Dec 2018 12:12:57 -0800 Subject: [PATCH 3/6] Accept new baselines --- .../keyofAndIndexedAccessErrors.errors.txt | 21 +++++++- .../reference/keyofAndIndexedAccessErrors.js | 27 ++++++++++ .../keyofAndIndexedAccessErrors.symbols | 53 +++++++++++++++++++ .../keyofAndIndexedAccessErrors.types | 28 ++++++++++ 4 files changed, 128 insertions(+), 1 deletion(-) diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt index cba7ab5246925..68669463d9511 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt @@ -66,9 +66,10 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(123,5): error tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(140,5): error TS2322: Type '42' is not assignable to type 'T[K]'. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(141,5): error TS2322: Type '"hello"' is not assignable to type 'T[K]'. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(142,5): error TS2322: Type 'number[]' is not assignable to type 'T[K]'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(158,9): error TS2322: Type '"hello"' is not assignable to type 'Record[K]'. -==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (41 errors) ==== +==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (42 errors) ==== class Shape { name: string; width: number; @@ -321,4 +322,22 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(142,5): error ~~~~ !!! error TS2322: Type 'number[]' is not assignable to type 'T[K]'. } + + // Repro from #28839 + + function f30() { + let x: Partial>[K] = "hello"; + } + + // We simplify indexed accesses applied to mapped types up to five levels deep + + function f31() { + let x: Partial>>>>[K] = "hello"; + } + + function f32() { + let x: Partial>>>>>[K] = "hello"; + ~ +!!! error TS2322: Type '"hello"' is not assignable to type 'Record[K]'. + } \ No newline at end of file diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.js b/tests/baselines/reference/keyofAndIndexedAccessErrors.js index 88a1b74f14d39..0cf77e79ba6ce 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.js +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.js @@ -142,6 +142,22 @@ function test1, K extends keyof T>(t: T, k: K) { t[k] = "hello"; // Error t[k] = [10, 20]; // Error } + +// Repro from #28839 + +function f30() { + let x: Partial>[K] = "hello"; +} + +// We simplify indexed accesses applied to mapped types up to five levels deep + +function f31() { + let x: Partial>>>>[K] = "hello"; +} + +function f32() { + let x: Partial>>>>>[K] = "hello"; +} //// [keyofAndIndexedAccessErrors.js] @@ -215,3 +231,14 @@ function test1(t, k) { t[k] = "hello"; // Error t[k] = [10, 20]; // Error } +// Repro from #28839 +function f30() { + var x = "hello"; +} +// We simplify indexed accesses applied to mapped types up to five levels deep +function f31() { + var x = "hello"; +} +function f32() { + var x = "hello"; +} diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols b/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols index df1707849cb8a..3f32679a81352 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols @@ -486,3 +486,56 @@ function test1, K extends keyof T>(t: T, k: K) { >k : Symbol(k, Decl(keyofAndIndexedAccessErrors.ts, 138, 70)) } +// Repro from #28839 + +function f30() { +>f30 : Symbol(f30, Decl(keyofAndIndexedAccessErrors.ts, 142, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 146, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 146, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 146, 13)) + + let x: Partial>[K] = "hello"; +>x : Symbol(x, Decl(keyofAndIndexedAccessErrors.ts, 147, 7)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 146, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 146, 15)) +} + +// We simplify indexed accesses applied to mapped types up to five levels deep + +function f31() { +>f31 : Symbol(f31, Decl(keyofAndIndexedAccessErrors.ts, 148, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 152, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 152, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 152, 13)) + + let x: Partial>>>>[K] = "hello"; +>x : Symbol(x, Decl(keyofAndIndexedAccessErrors.ts, 153, 7)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 152, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 152, 15)) +} + +function f32() { +>f32 : Symbol(f32, Decl(keyofAndIndexedAccessErrors.ts, 154, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 156, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 156, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 156, 13)) + + let x: Partial>>>>>[K] = "hello"; +>x : Symbol(x, Decl(keyofAndIndexedAccessErrors.ts, 157, 7)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 156, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 156, 15)) +} + diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.types b/tests/baselines/reference/keyofAndIndexedAccessErrors.types index 68dc361c99ee3..b9d17df03417b 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.types +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.types @@ -465,3 +465,31 @@ function test1, K extends keyof T>(t: T, k: K) { >20 : 20 } +// Repro from #28839 + +function f30() { +>f30 : () => void + + let x: Partial>[K] = "hello"; +>x : Partial>[K] +>"hello" : "hello" +} + +// We simplify indexed accesses applied to mapped types up to five levels deep + +function f31() { +>f31 : () => void + + let x: Partial>>>>[K] = "hello"; +>x : Partial>>>>[K] +>"hello" : "hello" +} + +function f32() { +>f32 : () => void + + let x: Partial>>>>>[K] = "hello"; +>x : Partial>>>>>[K] +>"hello" : "hello" +} + From 0dcaaa5c5094ca36138fbcd3b791f5f7de6b71b1 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 11 Dec 2018 15:11:57 -0800 Subject: [PATCH 4/6] Simplify indexed accesses on mapped types with no depth limit --- src/compiler/checker.ts | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8001165e4910b..e7294d3941a8e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -67,7 +67,6 @@ namespace ts { let enumCount = 0; let instantiationDepth = 0; let constraintDepth = 0; - let simplificationDepth = 0; const emptySymbols = createSymbolTable(); const identityMapper: (type: Type) => Type = identity; @@ -9687,31 +9686,15 @@ namespace ts { // 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 - // construct the type Box. Mapped types can be recursive so to guard against infinite recursion we - // only perform this simplification up to five levels deep. - if (simplificationDepth < 5) { - if (isGenericMappedType(objectType)) { - return type.simplified = substituteIndexedMappedType(objectType, type); - } - if (objectType.flags & TypeFlags.TypeParameter) { - const constraint = getConstraintOfTypeParameter(objectType as TypeParameter); - if (constraint && isGenericMappedType(constraint)) { - return type.simplified = substituteIndexedMappedType(constraint, type); - } - } + // construct the type Box. + if (isGenericMappedType(objectType)) { + const mapper = createTypeMapper([getTypeParameterFromMappedType(objectType)], [type.indexType]); + const templateMapper = combineTypeMappers(objectType.mapper, mapper); + return type.simplified = mapType(instantiateType(getTemplateTypeFromMappedType(objectType), templateMapper), getSimplifiedType); } return type.simplified = type; } - function substituteIndexedMappedType(objectType: MappedType, type: IndexedAccessType) { - simplificationDepth++; - const mapper = createTypeMapper([getTypeParameterFromMappedType(objectType)], [type.indexType]); - const templateMapper = combineTypeMappers(objectType.mapper, mapper); - const result = mapType(instantiateType(getTemplateTypeFromMappedType(objectType), templateMapper), getSimplifiedType); - simplificationDepth--; - return result; - } - function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode | PropertyName, missingType = accessNode ? errorType : unknownType): Type { if (objectType === wildcardType || indexType === wildcardType) { return wildcardType; From 77d01ab332bce00322a0c76c5a94e77e45abf9db Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 11 Dec 2018 15:12:47 -0800 Subject: [PATCH 5/6] Update tests --- .../conformance/types/keyof/keyofAndIndexedAccess.ts | 4 ++-- .../types/keyof/keyofAndIndexedAccessErrors.ts | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts index cf05bdfed8130..b498310f13be5 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts @@ -486,10 +486,10 @@ function onChangeGenericFunction(handler: Handler) { function updateIds, K extends string>( obj: T, idFields: K[], - idMapping: { [oldId: string]: string } + idMapping: Partial> ): Record { for (const idField of idFields) { - const newId = idMapping[obj[idField]]; + const newId: T[K] | undefined = idMapping[obj[idField]]; if (newId) { obj[idField] = newId; } diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts index a179935d0ecfd..d5fe7c24b5c66 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts @@ -148,12 +148,6 @@ function f30() { let x: Partial>[K] = "hello"; } -// We simplify indexed accesses applied to mapped types up to five levels deep - function f31() { - let x: Partial>>>>[K] = "hello"; -} - -function f32() { - let x: Partial>>>>>[K] = "hello"; + let x: Partial>>>>>>>[K] = "hello"; } From c3a93944aad2dace975b778df442ad93b13ee6e8 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 11 Dec 2018 15:12:54 -0800 Subject: [PATCH 6/6] Accept new baselines --- .../reference/keyofAndIndexedAccess.js | 8 ++--- .../reference/keyofAndIndexedAccess.symbols | 13 ++++++-- .../reference/keyofAndIndexedAccess.types | 21 ++++++------- .../keyofAndIndexedAccessErrors.errors.txt | 13 ++------ .../reference/keyofAndIndexedAccessErrors.js | 12 +------ .../keyofAndIndexedAccessErrors.symbols | 31 +++++-------------- .../keyofAndIndexedAccessErrors.types | 14 ++------- 7 files changed, 35 insertions(+), 77 deletions(-) diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js index b7d794285fae1..793313fdaa535 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.js +++ b/tests/baselines/reference/keyofAndIndexedAccess.js @@ -484,10 +484,10 @@ function onChangeGenericFunction(handler: Handler) { function updateIds, K extends string>( obj: T, idFields: K[], - idMapping: { [oldId: string]: string } + idMapping: Partial> ): Record { for (const idField of idFields) { - const newId = idMapping[obj[idField]]; + const newId: T[K] | undefined = idMapping[obj[idField]]; if (newId) { obj[idField] = newId; } @@ -1312,9 +1312,7 @@ declare type Handler = { declare function onChangeGenericFunction(handler: Handler): void; -declare function updateIds, K extends string>(obj: T, idFields: K[], idMapping: { - [oldId: string]: string; -}): Record; +declare function updateIds, K extends string>(obj: T, idFields: K[], idMapping: Partial>): Record; declare function updateIds2(obj: T, key: K, stringMap: { diff --git a/tests/baselines/reference/keyofAndIndexedAccess.symbols b/tests/baselines/reference/keyofAndIndexedAccess.symbols index 9881365b470ac..1d26f6dbec3a7 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess.symbols @@ -1767,9 +1767,14 @@ function updateIds, K extends string>( >idFields : Symbol(idFields, Decl(keyofAndIndexedAccess.ts, 483, 11)) >K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 482, 47)) - idMapping: { [oldId: string]: string } + idMapping: Partial> >idMapping : Symbol(idMapping, Decl(keyofAndIndexedAccess.ts, 484, 18)) ->oldId : Symbol(oldId, Decl(keyofAndIndexedAccess.ts, 485, 18)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 482, 19)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 482, 47)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 482, 19)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 482, 47)) ): Record { >Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) @@ -1779,8 +1784,10 @@ function updateIds, K extends string>( >idField : Symbol(idField, Decl(keyofAndIndexedAccess.ts, 487, 14)) >idFields : Symbol(idFields, Decl(keyofAndIndexedAccess.ts, 483, 11)) - const newId = idMapping[obj[idField]]; + const newId: T[K] | undefined = idMapping[obj[idField]]; >newId : Symbol(newId, Decl(keyofAndIndexedAccess.ts, 488, 13)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 482, 19)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 482, 47)) >idMapping : Symbol(idMapping, Decl(keyofAndIndexedAccess.ts, 484, 18)) >obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 482, 66)) >idField : Symbol(idField, Decl(keyofAndIndexedAccess.ts, 487, 14)) diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types index f4c47b26df0c4..bb395c562d6ef 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.types +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -1731,7 +1731,7 @@ function onChangeGenericFunction(handler: Handler) { // Repro from #13285 function updateIds, K extends string>( ->updateIds : , K extends string>(obj: T, idFields: K[], idMapping: { [oldId: string]: string; }) => Record +>updateIds : , K extends string>(obj: T, idFields: K[], idMapping: Partial>) => Record obj: T, >obj : T @@ -1739,32 +1739,31 @@ function updateIds, K extends string>( idFields: K[], >idFields : K[] - idMapping: { [oldId: string]: string } ->idMapping : { [oldId: string]: string; } ->oldId : string + idMapping: Partial> +>idMapping : Partial> ): Record { 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; } + const newId: T[K] | undefined = idMapping[obj[idField]]; +>newId : T[K] | undefined +>idMapping[obj[idField]] : Partial>[T[K]] +>idMapping : Partial> >obj[idField] : T[K] >obj : T >idField : K if (newId) { ->newId : { [oldId: string]: string; }[T[K]] +>newId : T[K] | undefined obj[idField] = newId; ->obj[idField] = newId : { [oldId: string]: string; }[T[K]] +>obj[idField] = newId : T[K] >obj[idField] : T[K] >obj : T >idField : K ->newId : { [oldId: string]: string; }[T[K]] +>newId : T[K] } } return obj; diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt index 68669463d9511..b0eaac39c6d21 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt @@ -66,10 +66,9 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(123,5): error tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(140,5): error TS2322: Type '42' is not assignable to type 'T[K]'. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(141,5): error TS2322: Type '"hello"' is not assignable to type 'T[K]'. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(142,5): error TS2322: Type 'number[]' is not assignable to type 'T[K]'. -tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(158,9): error TS2322: Type '"hello"' is not assignable to type 'Record[K]'. -==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (42 errors) ==== +==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (41 errors) ==== class Shape { name: string; width: number; @@ -329,15 +328,7 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(158,9): error let x: Partial>[K] = "hello"; } - // We simplify indexed accesses applied to mapped types up to five levels deep - function f31() { - let x: Partial>>>>[K] = "hello"; - } - - function f32() { - let x: Partial>>>>>[K] = "hello"; - ~ -!!! error TS2322: Type '"hello"' is not assignable to type 'Record[K]'. + let x: Partial>>>>>>>[K] = "hello"; } \ No newline at end of file diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.js b/tests/baselines/reference/keyofAndIndexedAccessErrors.js index 0cf77e79ba6ce..f262f9a0d3c67 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.js +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.js @@ -149,14 +149,8 @@ function f30() { let x: Partial>[K] = "hello"; } -// We simplify indexed accesses applied to mapped types up to five levels deep - function f31() { - let x: Partial>>>>[K] = "hello"; -} - -function f32() { - let x: Partial>>>>>[K] = "hello"; + let x: Partial>>>>>>>[K] = "hello"; } @@ -235,10 +229,6 @@ function test1(t, k) { function f30() { var x = "hello"; } -// We simplify indexed accesses applied to mapped types up to five levels deep function f31() { var x = "hello"; } -function f32() { - var x = "hello"; -} diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols b/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols index 3f32679a81352..1dd7c0d564828 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols @@ -502,40 +502,23 @@ function f30() { >K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 146, 15)) } -// We simplify indexed accesses applied to mapped types up to five levels deep - function f31() { >f31 : Symbol(f31, Decl(keyofAndIndexedAccessErrors.ts, 148, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 152, 13)) ->K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 152, 15)) ->T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 152, 13)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 150, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 150, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 150, 13)) - let x: Partial>>>>[K] = "hello"; ->x : Symbol(x, Decl(keyofAndIndexedAccessErrors.ts, 153, 7)) ->Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) + let x: Partial>>>>>>>[K] = "hello"; +>x : Symbol(x, Decl(keyofAndIndexedAccessErrors.ts, 151, 7)) >Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) >Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) >Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) ->Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) ->T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 152, 13)) ->K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 152, 15)) -} - -function f32() { ->f32 : Symbol(f32, Decl(keyofAndIndexedAccessErrors.ts, 154, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 156, 13)) ->K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 156, 15)) ->T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 156, 13)) - - let x: Partial>>>>>[K] = "hello"; ->x : Symbol(x, Decl(keyofAndIndexedAccessErrors.ts, 157, 7)) ->Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) >Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) >Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) >Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) >Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) >Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) ->T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 156, 13)) ->K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 156, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 150, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 150, 15)) } diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.types b/tests/baselines/reference/keyofAndIndexedAccessErrors.types index b9d17df03417b..90df0e687a057 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.types +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.types @@ -475,21 +475,11 @@ function f30() { >"hello" : "hello" } -// We simplify indexed accesses applied to mapped types up to five levels deep - function f31() { >f31 : () => void - let x: Partial>>>>[K] = "hello"; ->x : Partial>>>>[K] ->"hello" : "hello" -} - -function f32() { ->f32 : () => void - - let x: Partial>>>>>[K] = "hello"; ->x : Partial>>>>>[K] + let x: Partial>>>>>>>[K] = "hello"; +>x : Partial>>>>>>>[K] >"hello" : "hello" }