From 443abe53730aeaefd2b1f1777dac51cc32f418b3 Mon Sep 17 00:00:00 2001 From: Marius Schulz Date: Sat, 19 Nov 2016 22:30:18 +0100 Subject: [PATCH 01/22] =?UTF-8?q?Allow=20one=20leading=20ignored=20?= =?UTF-8?q?=E2=80=9C|=E2=80=9D=20or=20=E2=80=9C&=E2=80=9D=20in=20a=20type?= =?UTF-8?q?=20position?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/compiler/parser.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b08f75b0f5bbf..55d267cb53a8b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2615,6 +2615,7 @@ namespace ts { } function parseUnionOrIntersectionType(kind: SyntaxKind, parseConstituentType: () => TypeNode, operator: SyntaxKind): TypeNode { + parseOptional(operator); let type = parseConstituentType(); if (token() === operator) { const types = createNodeArray([type], type.pos); From e45c5dbceab76db9932f93dab4dd9aa70dcdf3c3 Mon Sep 17 00:00:00 2001 From: Marius Schulz Date: Sat, 19 Nov 2016 22:30:33 +0100 Subject: [PATCH 02/22] Add tests and accept new baselines --- .../intersectionTypeWithLeadingOperator.js | 8 ++++++++ .../intersectionTypeWithLeadingOperator.symbols | 13 +++++++++++++ .../intersectionTypeWithLeadingOperator.types | 13 +++++++++++++ .../reference/unionTypeWithLeadingOperator.js | 8 ++++++++ .../reference/unionTypeWithLeadingOperator.symbols | 13 +++++++++++++ .../reference/unionTypeWithLeadingOperator.types | 13 +++++++++++++ .../compiler/intersectionTypeWithLeadingOperator.ts | 4 ++++ .../cases/compiler/unionTypeWithLeadingOperator.ts | 4 ++++ 8 files changed, 76 insertions(+) create mode 100644 tests/baselines/reference/intersectionTypeWithLeadingOperator.js create mode 100644 tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols create mode 100644 tests/baselines/reference/intersectionTypeWithLeadingOperator.types create mode 100644 tests/baselines/reference/unionTypeWithLeadingOperator.js create mode 100644 tests/baselines/reference/unionTypeWithLeadingOperator.symbols create mode 100644 tests/baselines/reference/unionTypeWithLeadingOperator.types create mode 100644 tests/cases/compiler/intersectionTypeWithLeadingOperator.ts create mode 100644 tests/cases/compiler/unionTypeWithLeadingOperator.ts diff --git a/tests/baselines/reference/intersectionTypeWithLeadingOperator.js b/tests/baselines/reference/intersectionTypeWithLeadingOperator.js new file mode 100644 index 0000000000000..03f17c0878858 --- /dev/null +++ b/tests/baselines/reference/intersectionTypeWithLeadingOperator.js @@ -0,0 +1,8 @@ +//// [intersectionTypeWithLeadingOperator.ts] +type A = & string; +type B = + & { foo: string } + & { bar: number }; + + +//// [intersectionTypeWithLeadingOperator.js] diff --git a/tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols b/tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols new file mode 100644 index 0000000000000..43e0db684dc4e --- /dev/null +++ b/tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/intersectionTypeWithLeadingOperator.ts === +type A = & string; +>A : Symbol(A, Decl(intersectionTypeWithLeadingOperator.ts, 0, 0)) + +type B = +>B : Symbol(B, Decl(intersectionTypeWithLeadingOperator.ts, 0, 18)) + + & { foo: string } +>foo : Symbol(foo, Decl(intersectionTypeWithLeadingOperator.ts, 2, 5)) + + & { bar: number }; +>bar : Symbol(bar, Decl(intersectionTypeWithLeadingOperator.ts, 3, 5)) + diff --git a/tests/baselines/reference/intersectionTypeWithLeadingOperator.types b/tests/baselines/reference/intersectionTypeWithLeadingOperator.types new file mode 100644 index 0000000000000..f2fad709dce68 --- /dev/null +++ b/tests/baselines/reference/intersectionTypeWithLeadingOperator.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/intersectionTypeWithLeadingOperator.ts === +type A = & string; +>A : string + +type B = +>B : B + + & { foo: string } +>foo : string + + & { bar: number }; +>bar : number + diff --git a/tests/baselines/reference/unionTypeWithLeadingOperator.js b/tests/baselines/reference/unionTypeWithLeadingOperator.js new file mode 100644 index 0000000000000..b6a40440a481f --- /dev/null +++ b/tests/baselines/reference/unionTypeWithLeadingOperator.js @@ -0,0 +1,8 @@ +//// [unionTypeWithLeadingOperator.ts] +type A = | string; +type B = + | { type: "INCREMENT" } + | { type: "DECREMENT" }; + + +//// [unionTypeWithLeadingOperator.js] diff --git a/tests/baselines/reference/unionTypeWithLeadingOperator.symbols b/tests/baselines/reference/unionTypeWithLeadingOperator.symbols new file mode 100644 index 0000000000000..97fdcdda8e0c5 --- /dev/null +++ b/tests/baselines/reference/unionTypeWithLeadingOperator.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/unionTypeWithLeadingOperator.ts === +type A = | string; +>A : Symbol(A, Decl(unionTypeWithLeadingOperator.ts, 0, 0)) + +type B = +>B : Symbol(B, Decl(unionTypeWithLeadingOperator.ts, 0, 18)) + + | { type: "INCREMENT" } +>type : Symbol(type, Decl(unionTypeWithLeadingOperator.ts, 2, 5)) + + | { type: "DECREMENT" }; +>type : Symbol(type, Decl(unionTypeWithLeadingOperator.ts, 3, 5)) + diff --git a/tests/baselines/reference/unionTypeWithLeadingOperator.types b/tests/baselines/reference/unionTypeWithLeadingOperator.types new file mode 100644 index 0000000000000..db92c6e8eb6a7 --- /dev/null +++ b/tests/baselines/reference/unionTypeWithLeadingOperator.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/unionTypeWithLeadingOperator.ts === +type A = | string; +>A : string + +type B = +>B : B + + | { type: "INCREMENT" } +>type : "INCREMENT" + + | { type: "DECREMENT" }; +>type : "DECREMENT" + diff --git a/tests/cases/compiler/intersectionTypeWithLeadingOperator.ts b/tests/cases/compiler/intersectionTypeWithLeadingOperator.ts new file mode 100644 index 0000000000000..9f64cad38dc08 --- /dev/null +++ b/tests/cases/compiler/intersectionTypeWithLeadingOperator.ts @@ -0,0 +1,4 @@ +type A = & string; +type B = + & { foo: string } + & { bar: number }; diff --git a/tests/cases/compiler/unionTypeWithLeadingOperator.ts b/tests/cases/compiler/unionTypeWithLeadingOperator.ts new file mode 100644 index 0000000000000..08a876493d073 --- /dev/null +++ b/tests/cases/compiler/unionTypeWithLeadingOperator.ts @@ -0,0 +1,4 @@ +type A = | string; +type B = + | { type: "INCREMENT" } + | { type: "DECREMENT" }; From cd70f22b8806f519ded4caa4acf33f63bce97d57 Mon Sep 17 00:00:00 2001 From: Marius Schulz Date: Sun, 20 Nov 2016 10:48:03 +0100 Subject: [PATCH 03/22] =?UTF-8?q?Add=20=E2=80=9C|=E2=80=9D=20and=20?= =?UTF-8?q?=E2=80=9C&=E2=80=9D=20to=20list=20of=20tokens=20that=20start=20?= =?UTF-8?q?a=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/compiler/parser.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 55d267cb53a8b..5117129a573e0 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2556,6 +2556,8 @@ namespace ts { case SyntaxKind.OpenBraceToken: case SyntaxKind.OpenBracketToken: case SyntaxKind.LessThanToken: + case SyntaxKind.BarToken: + case SyntaxKind.AmpersandToken: case SyntaxKind.NewKeyword: case SyntaxKind.StringLiteral: case SyntaxKind.NumericLiteral: From d040db42f51593ee5695a6a24a3ae595ee8aec1d Mon Sep 17 00:00:00 2001 From: Marius Schulz Date: Sun, 20 Nov 2016 22:26:32 +0100 Subject: [PATCH 04/22] Add test for proper tuple type handling --- .../reference/intersectionTypeWithLeadingOperator.js | 2 ++ .../reference/intersectionTypeWithLeadingOperator.symbols | 7 +++++++ .../reference/intersectionTypeWithLeadingOperator.types | 7 +++++++ tests/baselines/reference/unionTypeWithLeadingOperator.js | 2 ++ .../reference/unionTypeWithLeadingOperator.symbols | 3 +++ .../baselines/reference/unionTypeWithLeadingOperator.types | 3 +++ .../cases/compiler/intersectionTypeWithLeadingOperator.ts | 2 ++ tests/cases/compiler/unionTypeWithLeadingOperator.ts | 2 ++ 8 files changed, 28 insertions(+) diff --git a/tests/baselines/reference/intersectionTypeWithLeadingOperator.js b/tests/baselines/reference/intersectionTypeWithLeadingOperator.js index 03f17c0878858..61b034f1e0304 100644 --- a/tests/baselines/reference/intersectionTypeWithLeadingOperator.js +++ b/tests/baselines/reference/intersectionTypeWithLeadingOperator.js @@ -3,6 +3,8 @@ type A = & string; type B = & { foo: string } & { bar: number }; + +type C = [& { foo: 1 } & { bar: 2 }, & { foo: 3 } & { bar: 4 }]; //// [intersectionTypeWithLeadingOperator.js] diff --git a/tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols b/tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols index 43e0db684dc4e..f6648183bb67a 100644 --- a/tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols +++ b/tests/baselines/reference/intersectionTypeWithLeadingOperator.symbols @@ -11,3 +11,10 @@ type B = & { bar: number }; >bar : Symbol(bar, Decl(intersectionTypeWithLeadingOperator.ts, 3, 5)) +type C = [& { foo: 1 } & { bar: 2 }, & { foo: 3 } & { bar: 4 }]; +>C : Symbol(C, Decl(intersectionTypeWithLeadingOperator.ts, 3, 20)) +>foo : Symbol(foo, Decl(intersectionTypeWithLeadingOperator.ts, 5, 13)) +>bar : Symbol(bar, Decl(intersectionTypeWithLeadingOperator.ts, 5, 26)) +>foo : Symbol(foo, Decl(intersectionTypeWithLeadingOperator.ts, 5, 40)) +>bar : Symbol(bar, Decl(intersectionTypeWithLeadingOperator.ts, 5, 53)) + diff --git a/tests/baselines/reference/intersectionTypeWithLeadingOperator.types b/tests/baselines/reference/intersectionTypeWithLeadingOperator.types index f2fad709dce68..9961f051f7f38 100644 --- a/tests/baselines/reference/intersectionTypeWithLeadingOperator.types +++ b/tests/baselines/reference/intersectionTypeWithLeadingOperator.types @@ -11,3 +11,10 @@ type B = & { bar: number }; >bar : number +type C = [& { foo: 1 } & { bar: 2 }, & { foo: 3 } & { bar: 4 }]; +>C : [{ foo: 1; } & { bar: 2; }, { foo: 3; } & { bar: 4; }] +>foo : 1 +>bar : 2 +>foo : 3 +>bar : 4 + diff --git a/tests/baselines/reference/unionTypeWithLeadingOperator.js b/tests/baselines/reference/unionTypeWithLeadingOperator.js index b6a40440a481f..0fb366d538e7b 100644 --- a/tests/baselines/reference/unionTypeWithLeadingOperator.js +++ b/tests/baselines/reference/unionTypeWithLeadingOperator.js @@ -3,6 +3,8 @@ type A = | string; type B = | { type: "INCREMENT" } | { type: "DECREMENT" }; + +type C = [| 0 | 1, | "foo" | "bar"]; //// [unionTypeWithLeadingOperator.js] diff --git a/tests/baselines/reference/unionTypeWithLeadingOperator.symbols b/tests/baselines/reference/unionTypeWithLeadingOperator.symbols index 97fdcdda8e0c5..8c15d299c4864 100644 --- a/tests/baselines/reference/unionTypeWithLeadingOperator.symbols +++ b/tests/baselines/reference/unionTypeWithLeadingOperator.symbols @@ -11,3 +11,6 @@ type B = | { type: "DECREMENT" }; >type : Symbol(type, Decl(unionTypeWithLeadingOperator.ts, 3, 5)) +type C = [| 0 | 1, | "foo" | "bar"]; +>C : Symbol(C, Decl(unionTypeWithLeadingOperator.ts, 3, 26)) + diff --git a/tests/baselines/reference/unionTypeWithLeadingOperator.types b/tests/baselines/reference/unionTypeWithLeadingOperator.types index db92c6e8eb6a7..2ca15fb54a298 100644 --- a/tests/baselines/reference/unionTypeWithLeadingOperator.types +++ b/tests/baselines/reference/unionTypeWithLeadingOperator.types @@ -11,3 +11,6 @@ type B = | { type: "DECREMENT" }; >type : "DECREMENT" +type C = [| 0 | 1, | "foo" | "bar"]; +>C : [0 | 1, "foo" | "bar"] + diff --git a/tests/cases/compiler/intersectionTypeWithLeadingOperator.ts b/tests/cases/compiler/intersectionTypeWithLeadingOperator.ts index 9f64cad38dc08..4138dee426110 100644 --- a/tests/cases/compiler/intersectionTypeWithLeadingOperator.ts +++ b/tests/cases/compiler/intersectionTypeWithLeadingOperator.ts @@ -2,3 +2,5 @@ type A = & string; type B = & { foo: string } & { bar: number }; + +type C = [& { foo: 1 } & { bar: 2 }, & { foo: 3 } & { bar: 4 }]; diff --git a/tests/cases/compiler/unionTypeWithLeadingOperator.ts b/tests/cases/compiler/unionTypeWithLeadingOperator.ts index 08a876493d073..9f6d272ce7c03 100644 --- a/tests/cases/compiler/unionTypeWithLeadingOperator.ts +++ b/tests/cases/compiler/unionTypeWithLeadingOperator.ts @@ -2,3 +2,5 @@ type A = | string; type B = | { type: "INCREMENT" } | { type: "DECREMENT" }; + +type C = [| 0 | 1, | "foo" | "bar"]; From cdda5dfd61fd0b3a7288619895ec3f85ebec1c70 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 23 Nov 2016 18:22:57 -0800 Subject: [PATCH 05/22] keyof T is a literal contextual type --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6d5a8b74cb3bd..f0c6e4edb42a8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14870,7 +14870,7 @@ namespace ts { } contextualType = apparentType; } - return maybeTypeOfKind(contextualType, TypeFlags.Literal); + return maybeTypeOfKind(contextualType, (TypeFlags.Literal | TypeFlags.Index)); } return false; } From 2cec4c5ebb2cfde2119f04b299fc91fdf05f183c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 23 Nov 2016 18:28:59 -0800 Subject: [PATCH 06/22] Add regression test --- .../keyofIsLiteralContexualType.errors.txt | 32 +++++++++++++++++++ .../reference/keyofIsLiteralContexualType.js | 23 +++++++++++++ .../compiler/keyofIsLiteralContexualType.ts | 13 ++++++++ 3 files changed, 68 insertions(+) create mode 100644 tests/baselines/reference/keyofIsLiteralContexualType.errors.txt create mode 100644 tests/baselines/reference/keyofIsLiteralContexualType.js create mode 100644 tests/cases/compiler/keyofIsLiteralContexualType.ts diff --git a/tests/baselines/reference/keyofIsLiteralContexualType.errors.txt b/tests/baselines/reference/keyofIsLiteralContexualType.errors.txt new file mode 100644 index 0000000000000..8424d528b2292 --- /dev/null +++ b/tests/baselines/reference/keyofIsLiteralContexualType.errors.txt @@ -0,0 +1,32 @@ +tests/cases/compiler/keyofIsLiteralContexualType.ts(5,9): error TS2322: Type '("a" | "b" | "c")[]' is not assignable to type 'keyof T[]'. + Type '"a" | "b" | "c"' is not assignable to type 'keyof T'. + Type '"a" | "b" | "c"' is not assignable to type '"a" | "b"'. + Type '"c"' is not assignable to type '"a" | "b"'. + Type '"c"' is not assignable to type 'keyof T'. + Type '"c"' is not assignable to type '"a" | "b"'. +tests/cases/compiler/keyofIsLiteralContexualType.ts(13,11): error TS2339: Property 'b' does not exist on type 'Pick<{ a: number; b: number; c: number; }, "a" | "c">'. + + +==== tests/cases/compiler/keyofIsLiteralContexualType.ts (2 errors) ==== + // keyof T is a literal contextual type + + function foo() { + let a: (keyof T)[] = ["a", "b"]; + let b: (keyof T)[] = ["a", "b", "c"]; + ~ +!!! error TS2322: Type '("a" | "b" | "c")[]' is not assignable to type 'keyof T[]'. +!!! error TS2322: Type '"a" | "b" | "c"' is not assignable to type 'keyof T'. +!!! error TS2322: Type '"a" | "b" | "c"' is not assignable to type '"a" | "b"'. +!!! error TS2322: Type '"c"' is not assignable to type '"a" | "b"'. +!!! error TS2322: Type '"c"' is not assignable to type 'keyof T'. +!!! error TS2322: Type '"c"' is not assignable to type '"a" | "b"'. + } + + // Repro from #12455 + + declare function pick(obj: T, propNames: K[]): Pick; + + let x = pick({ a: 10, b: 20, c: 30 }, ["a", "c"]); + let b = x.b; // Error + ~ +!!! error TS2339: Property 'b' does not exist on type 'Pick<{ a: number; b: number; c: number; }, "a" | "c">'. \ No newline at end of file diff --git a/tests/baselines/reference/keyofIsLiteralContexualType.js b/tests/baselines/reference/keyofIsLiteralContexualType.js new file mode 100644 index 0000000000000..5325b97617483 --- /dev/null +++ b/tests/baselines/reference/keyofIsLiteralContexualType.js @@ -0,0 +1,23 @@ +//// [keyofIsLiteralContexualType.ts] +// keyof T is a literal contextual type + +function foo() { + let a: (keyof T)[] = ["a", "b"]; + let b: (keyof T)[] = ["a", "b", "c"]; +} + +// Repro from #12455 + +declare function pick(obj: T, propNames: K[]): Pick; + +let x = pick({ a: 10, b: 20, c: 30 }, ["a", "c"]); +let b = x.b; // Error + +//// [keyofIsLiteralContexualType.js] +// keyof T is a literal contextual type +function foo() { + var a = ["a", "b"]; + var b = ["a", "b", "c"]; +} +var x = pick({ a: 10, b: 20, c: 30 }, ["a", "c"]); +var b = x.b; // Error diff --git a/tests/cases/compiler/keyofIsLiteralContexualType.ts b/tests/cases/compiler/keyofIsLiteralContexualType.ts new file mode 100644 index 0000000000000..dd14de9228947 --- /dev/null +++ b/tests/cases/compiler/keyofIsLiteralContexualType.ts @@ -0,0 +1,13 @@ +// keyof T is a literal contextual type + +function foo() { + let a: (keyof T)[] = ["a", "b"]; + let b: (keyof T)[] = ["a", "b", "c"]; +} + +// Repro from #12455 + +declare function pick(obj: T, propNames: K[]): Pick; + +let x = pick({ a: 10, b: 20, c: 30 }, ["a", "c"]); +let b = x.b; // Error \ No newline at end of file From 36ad772c55cfd73f34ccee4e41a5c5a13ff297b7 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 23 Nov 2016 20:07:53 -0800 Subject: [PATCH 07/22] Type inference for isomorphic mapped types --- src/compiler/checker.ts | 87 +++++++++++++++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6d5a8b74cb3bd..f7d01d5480d27 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8425,7 +8425,7 @@ namespace ts { // results for union and intersection types for performance reasons. function couldContainTypeParameters(type: Type): boolean { const objectFlags = getObjectFlags(type); - return !!(type.flags & TypeFlags.TypeParameter || + return !!(type.flags & (TypeFlags.TypeParameter | TypeFlags.IndexedAccess) || objectFlags & ObjectFlags.Reference && forEach((type).typeArguments, couldContainTypeParameters) || objectFlags & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.Class) || objectFlags & ObjectFlags.Mapped || @@ -8443,8 +8443,57 @@ namespace ts { return type === typeParameter || type.flags & TypeFlags.UnionOrIntersection && forEach((type).types, t => isTypeParameterAtTopLevel(t, typeParameter)); } - function inferTypes(context: InferenceContext, originalSource: Type, originalTarget: Type) { - const typeParameters = context.signature.typeParameters; + // Infer a suitable input type for an isomorphic mapped type { [P in keyof T]: X }. We construct + // an object type with the same set of properties as the source type, where the type of each + // property is computed by inferring from the source property type to X for a synthetic type + // parameter T[P] (i.e. we treat the type T[P] as the type parameter we're inferring for). + function inferTypeForIsomorphicMappedType(source: Type, target: MappedType): Type { + if (!isMappableType(source)) { + return source; + } + const typeParameter = getIndexedAccessType((getConstraintTypeFromMappedType(target)).type, getTypeParameterFromMappedType(target)); + const typeParameterArray = [typeParameter]; + const typeInferences = createTypeInferencesObject(); + const typeInferencesArray = [typeInferences]; + const templateType = getTemplateTypeFromMappedType(target); + const properties = getPropertiesOfType(source); + const members = createSymbolTable(properties); + let hasInferredTypes = false; + for (const prop of properties) { + const inferredPropType = inferTargetType(getTypeOfSymbol(prop)); + if (inferredPropType) { + const inferredProp = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | prop.flags & SymbolFlags.Optional, prop.name); + inferredProp.declarations = prop.declarations; + inferredProp.type = inferredPropType; + inferredProp.isReadonly = isReadonlySymbol(prop); + members[prop.name] = inferredProp; + hasInferredTypes = true; + } + } + let indexInfo = getIndexInfoOfType(source, IndexKind.String); + if (indexInfo) { + const inferredIndexType = inferTargetType(indexInfo.type); + if (inferredIndexType) { + indexInfo = createIndexInfo(inferredIndexType, indexInfo.isReadonly); + hasInferredTypes = true; + } + } + return hasInferredTypes ? createAnonymousType(undefined, members, emptyArray, emptyArray, indexInfo, undefined) : source; + + function inferTargetType(sourceType: Type): Type { + typeInferences.primary = undefined; + typeInferences.secondary = undefined; + inferTypes(typeParameterArray, typeInferencesArray, sourceType, templateType); + const inferences = typeInferences.primary || typeInferences.secondary; + return inferences && getUnionType(inferences, /*subtypeReduction*/ true); + } + } + + function inferTypesWithContext(context: InferenceContext, originalSource: Type, originalTarget: Type) { + inferTypes(context.signature.typeParameters, context.inferences, originalSource, originalTarget); + } + + function inferTypes(typeParameters: Type[], typeInferences: TypeInferences[], originalSource: Type, originalTarget: Type) { let sourceStack: Type[]; let targetStack: Type[]; let depth = 0; @@ -8512,7 +8561,7 @@ namespace ts { target = removeTypesFromUnionOrIntersection(target, matchingTypes); } } - if (target.flags & TypeFlags.TypeParameter) { + if (target.flags & (TypeFlags.TypeParameter | TypeFlags.IndexedAccess)) { // If target is a type parameter, make an inference, unless the source type contains // the anyFunctionType (the wildcard type that's used to avoid contextually typing functions). // Because the anyFunctionType is internal, it should not be exposed to the user by adding @@ -8524,7 +8573,7 @@ namespace ts { } for (let i = 0; i < typeParameters.length; i++) { if (target === typeParameters[i]) { - const inferences = context.inferences[i]; + const inferences = typeInferences[i]; if (!inferences.isFixed) { // Any inferences that are made to a type parameter in a union type are inferior // to inferences made to a flat (non-union) type. This is because if we infer to @@ -8538,7 +8587,7 @@ namespace ts { if (!contains(candidates, source)) { candidates.push(source); } - if (!isTypeParameterAtTopLevel(originalTarget, target)) { + if (target.flags & TypeFlags.TypeParameter && !isTypeParameterAtTopLevel(originalTarget, target)) { inferences.topLevel = false; } } @@ -8589,15 +8638,29 @@ namespace ts { if (getObjectFlags(target) & ObjectFlags.Mapped) { const constraintType = getConstraintTypeFromMappedType(target); if (getObjectFlags(source) & ObjectFlags.Mapped) { + // We're inferring from a mapped type to a mapped type, so simply infer from constraint type to + // constraint type and from template type to template type. inferFromTypes(getConstraintTypeFromMappedType(source), constraintType); inferFromTypes(getTemplateTypeFromMappedType(source), getTemplateTypeFromMappedType(target)); return; } if (constraintType.flags & TypeFlags.TypeParameter) { + // We're inferring from some source type S to a mapped type { [P in T]: X }, where T is a type + // parameter. Infer from 'keyof S' to T and infer from a union of each property type in S to X. inferFromTypes(getIndexType(source), constraintType); inferFromTypes(getUnionType(map(getPropertiesOfType(source), getTypeOfSymbol)), getTemplateTypeFromMappedType(target)); return; } + if (constraintType.flags & TypeFlags.Index) { + // We're inferring from some source type S to an isomorphic mapped type { [P in keyof T]: X }, + // where T is a type parameter. Use inferTypeForIsomorphicMappedType to infer a suitable source + // type and then infer from that type to T. + const index = indexOf(typeParameters, (constraintType).type); + if (index >= 0 && !typeInferences[index].isFixed) { + inferFromTypes(inferTypeForIsomorphicMappedType(source, target), typeParameters[index]); + } + return; + } } source = getApparentType(source); if (source.flags & TypeFlags.Object) { @@ -12458,7 +12521,7 @@ namespace ts { const context = createInferenceContext(signature, /*inferUnionTypes*/ true); forEachMatchingParameterType(contextualSignature, signature, (source, target) => { // Type parameters from outer context referenced by source type are fixed by instantiation of the source type - inferTypes(context, instantiateType(source, contextualMapper), target); + inferTypesWithContext(context, instantiateType(source, contextualMapper), target); }); return getSignatureInstantiation(signature, getInferredTypes(context)); } @@ -12493,7 +12556,7 @@ namespace ts { if (thisType) { const thisArgumentNode = getThisArgumentOfCall(node); const thisArgumentType = thisArgumentNode ? checkExpression(thisArgumentNode) : voidType; - inferTypes(context, thisArgumentType, thisType); + inferTypesWithContext(context, thisArgumentType, thisType); } // We perform two passes over the arguments. In the first pass we infer from all arguments, but use @@ -12515,7 +12578,7 @@ namespace ts { argType = checkExpressionWithContextualType(arg, paramType, mapper); } - inferTypes(context, argType, paramType); + inferTypesWithContext(context, argType, paramType); } } @@ -12530,7 +12593,7 @@ namespace ts { if (excludeArgument[i] === false) { const arg = args[i]; const paramType = getTypeAtPosition(signature, i); - inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType); + inferTypesWithContext(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType); } } } @@ -13617,7 +13680,7 @@ namespace ts { for (let i = 0; i < len; i++) { const declaration = signature.parameters[i].valueDeclaration; if (declaration.type) { - inferTypes(mapper.context, getTypeFromTypeNode(declaration.type), getTypeAtPosition(context, i)); + inferTypesWithContext(mapper.context, getTypeFromTypeNode(declaration.type), getTypeAtPosition(context, i)); } } } @@ -13703,7 +13766,7 @@ namespace ts { // T in the second overload so that we do not infer Base as a candidate for T // (inferring Base would make type argument inference inconsistent between the two // overloads). - inferTypes(mapper.context, links.type, instantiateType(contextualType, mapper)); + inferTypesWithContext(mapper.context, links.type, instantiateType(contextualType, mapper)); } } From 7b37918a1158717d555fcc143aca4b9719ab5e4a Mon Sep 17 00:00:00 2001 From: Charly POLY Date: Thu, 24 Nov 2016 10:16:21 +0100 Subject: [PATCH 08/22] doc(compiler/ts): fix documentation typo about __decorator code generation When __decorator applied to method, the last parameter (descriptor) is null, not undefined --- src/compiler/transformers/ts.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 62b2022b7df55..52717a9499676 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -1353,13 +1353,13 @@ namespace ts { // __metadata("design:type", Function), // __metadata("design:paramtypes", [Object]), // __metadata("design:returntype", void 0) - // ], C.prototype, "method", undefined); + // ], C.prototype, "method", null); // // The emit for an accessor is: // // __decorate([ // dec - // ], C.prototype, "accessor", undefined); + // ], C.prototype, "accessor", null); // // The emit for a property is: // From 46ca0ba41eb5bdcdb15f0cc136aacebb86655519 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 26 Nov 2016 09:58:44 -0800 Subject: [PATCH 09/22] Fix multiple 'keyof' issues with 'for-in' and 'in' operator --- src/compiler/checker.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f0c6e4edb42a8..cf430efcbf568 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3205,7 +3205,7 @@ namespace ts { // right hand expression is of a type parameter type. if (declaration.parent.parent.kind === SyntaxKind.ForInStatement) { const indexType = getIndexType(checkNonNullExpression((declaration.parent.parent).expression)); - return indexType.flags & TypeFlags.Index ? indexType : stringType; + return indexType.flags & (TypeFlags.TypeParameter | TypeFlags.Index) ? indexType : stringType; } if (declaration.parent.parent.kind === SyntaxKind.ForOfStatement) { @@ -5920,6 +5920,11 @@ namespace ts { getLiteralTypeFromPropertyNames(type); } + function getIndexTypeOrString(type: Type): Type { + const indexType = getIndexType(type); + return indexType !== neverType ? indexType : stringType; + } + function getTypeFromTypeOperatorNode(node: TypeOperatorNode) { const links = getNodeLinks(node); if (!links.resolvedType) { @@ -6018,8 +6023,7 @@ namespace ts { // meaningfully access the properties of the object type. In those cases, we first check that the // index type is assignable to 'keyof T' for the object type. if (accessNode) { - const keyType = indexType.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(indexType) || emptyObjectType : indexType; - if (!isTypeAssignableTo(keyType, getIndexType(objectType))) { + if (!isTypeAssignableTo(indexType, getIndexType(objectType))) { error(accessNode, Diagnostics.Type_0_cannot_be_used_to_index_type_1, typeToString(indexType), typeToString(objectType)); return unknownType; } @@ -14275,7 +14279,7 @@ namespace ts { // The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type, // and the right operand to be of type Any, an object type, or a type parameter type. // The result is always of the Boolean primitive type. - if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { + if (!(isTypeComparableTo(leftType, stringType) || isTypeOfKind(leftType, TypeFlags.NumberLike | TypeFlags.ESSymbol))) { error(left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol); } if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.Object | TypeFlags.TypeParameter | TypeFlags.IndexedAccess)) { @@ -17166,6 +17170,7 @@ namespace ts { // Grammar checking checkGrammarForInOrForOfStatement(node); + const rightType = checkNonNullExpression(node.expression); // TypeScript 1.0 spec (April 2014): 5.4 // In a 'for-in' statement of the form // for (let VarDecl in Expr) Statement @@ -17176,7 +17181,6 @@ namespace ts { if (variable && isBindingPattern(variable.name)) { error(variable.name, Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } - checkForInOrForOfVariableDeclaration(node); } else { @@ -17189,7 +17193,7 @@ namespace ts { if (varExpr.kind === SyntaxKind.ArrayLiteralExpression || varExpr.kind === SyntaxKind.ObjectLiteralExpression) { error(varExpr, Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } - else if (!isTypeAnyOrAllConstituentTypesHaveKind(leftType, TypeFlags.StringLike)) { + else if (!isTypeAssignableTo(getIndexTypeOrString(rightType), leftType)) { error(varExpr, Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { @@ -17198,7 +17202,6 @@ namespace ts { } } - const rightType = checkNonNullExpression(node.expression); // unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved // in this case error about missing name is already reported - do not report extra one if (!isTypeAnyOrAllConstituentTypesHaveKind(rightType, TypeFlags.Object | TypeFlags.TypeParameter | TypeFlags.IndexedAccess)) { From a26a3032c8f1d3e9489324a0f3f3e73dea7cf009 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 26 Nov 2016 10:06:21 -0800 Subject: [PATCH 10/22] Accept new baselines --- .../reference/inOperatorWithInvalidOperands.errors.txt | 8 +------- tests/baselines/reference/widenedTypes.errors.txt | 5 +---- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/tests/baselines/reference/inOperatorWithInvalidOperands.errors.txt b/tests/baselines/reference/inOperatorWithInvalidOperands.errors.txt index 0985157e0da73..5aeae5f160e25 100644 --- a/tests/baselines/reference/inOperatorWithInvalidOperands.errors.txt +++ b/tests/baselines/reference/inOperatorWithInvalidOperands.errors.txt @@ -1,8 +1,6 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(12,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(13,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(14,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. -tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(16,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. -tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(17,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(19,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(20,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(30,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter @@ -19,7 +17,7 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(43,17): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter -==== tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts (19 errors) ==== +==== tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts (17 errors) ==== enum E { a } var x: any; @@ -42,11 +40,7 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv !!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. var ra4 = a4 in x; var ra5 = null in x; - ~~~~ -!!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. var ra6 = undefined in x; - ~~~~~~~~~ -!!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. var ra7 = E.a in x; var ra8 = false in x; ~~~~~ diff --git a/tests/baselines/reference/widenedTypes.errors.txt b/tests/baselines/reference/widenedTypes.errors.txt index ea7c2b2f92ac7..5ea097acf2e6b 100644 --- a/tests/baselines/reference/widenedTypes.errors.txt +++ b/tests/baselines/reference/widenedTypes.errors.txt @@ -1,5 +1,4 @@ tests/cases/compiler/widenedTypes.ts(2,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter. -tests/cases/compiler/widenedTypes.ts(5,1): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. tests/cases/compiler/widenedTypes.ts(6,7): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter tests/cases/compiler/widenedTypes.ts(8,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. tests/cases/compiler/widenedTypes.ts(10,14): error TS2695: Left side of comma operator is unused and has no side effects. @@ -12,7 +11,7 @@ tests/cases/compiler/widenedTypes.ts(24,5): error TS2322: Type '{ x: number; y: Type 'number' is not assignable to type 'string'. -==== tests/cases/compiler/widenedTypes.ts (9 errors) ==== +==== tests/cases/compiler/widenedTypes.ts (8 errors) ==== null instanceof (() => { }); ~~~~ @@ -20,8 +19,6 @@ tests/cases/compiler/widenedTypes.ts(24,5): error TS2322: Type '{ x: number; y: ({}) instanceof null; // Ok because null is a subtype of function null in {}; - ~~~~ -!!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'. "" in null; ~~~~ !!! error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter From 12b63d230a1b2afa37ee024a73c39c34e99e6ba3 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 26 Nov 2016 10:06:33 -0800 Subject: [PATCH 11/22] Add regression test --- tests/baselines/reference/keyofAndForIn.js | 81 +++++++++++ .../baselines/reference/keyofAndForIn.symbols | 125 ++++++++++++++++ tests/baselines/reference/keyofAndForIn.types | 134 ++++++++++++++++++ .../conformance/types/keyof/keyofAndForIn.ts | 36 +++++ 4 files changed, 376 insertions(+) create mode 100644 tests/baselines/reference/keyofAndForIn.js create mode 100644 tests/baselines/reference/keyofAndForIn.symbols create mode 100644 tests/baselines/reference/keyofAndForIn.types create mode 100644 tests/cases/conformance/types/keyof/keyofAndForIn.ts diff --git a/tests/baselines/reference/keyofAndForIn.js b/tests/baselines/reference/keyofAndForIn.js new file mode 100644 index 0000000000000..0debf28b75ea2 --- /dev/null +++ b/tests/baselines/reference/keyofAndForIn.js @@ -0,0 +1,81 @@ +//// [keyofAndForIn.ts] + +// Repro from #12513 + +function f1(obj: { [P in K]: T }, k: K) { + const b = k in obj; + let k1: K; + for (k1 in obj) { + let x1 = obj[k1]; + } + for (let k2 in obj) { + let x2 = obj[k2]; + } +} + +function f2(obj: { [P in keyof T]: T[P] }, k: keyof T) { + const b = k in obj; + let k1: keyof T; + for (k1 in obj) { + let x1 = obj[k1]; + } + for (let k2 in obj) { + let x2 = obj[k2]; + } +} + +function f3(obj: { [P in K]: T[P] }, k: K) { + const b = k in obj; + let k1: K; + for (k1 in obj) { + let x1 = obj[k1]; + } + for (let k2 in obj) { + let x2 = obj[k2]; + } +} + +//// [keyofAndForIn.js] +// Repro from #12513 +function f1(obj, k) { + var b = k in obj; + var k1; + for (k1 in obj) { + var x1 = obj[k1]; + } + for (var k2 in obj) { + var x2 = obj[k2]; + } +} +function f2(obj, k) { + var b = k in obj; + var k1; + for (k1 in obj) { + var x1 = obj[k1]; + } + for (var k2 in obj) { + var x2 = obj[k2]; + } +} +function f3(obj, k) { + var b = k in obj; + var k1; + for (k1 in obj) { + var x1 = obj[k1]; + } + for (var k2 in obj) { + var x2 = obj[k2]; + } +} + + +//// [keyofAndForIn.d.ts] +declare function f1(obj: { + [P in K]: T; +}, k: K): void; +declare function f2(obj: { + [P in keyof T]: T[P]; +}, k: keyof T): void; +declare function f3(obj: { + [P in K]: T[P]; +}, k: K): void; diff --git a/tests/baselines/reference/keyofAndForIn.symbols b/tests/baselines/reference/keyofAndForIn.symbols new file mode 100644 index 0000000000000..36b5d3e2d7272 --- /dev/null +++ b/tests/baselines/reference/keyofAndForIn.symbols @@ -0,0 +1,125 @@ +=== tests/cases/conformance/types/keyof/keyofAndForIn.ts === + +// Repro from #12513 + +function f1(obj: { [P in K]: T }, k: K) { +>f1 : Symbol(f1, Decl(keyofAndForIn.ts, 0, 0)) +>K : Symbol(K, Decl(keyofAndForIn.ts, 3, 12)) +>T : Symbol(T, Decl(keyofAndForIn.ts, 3, 29)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 3, 33)) +>P : Symbol(P, Decl(keyofAndForIn.ts, 3, 41)) +>K : Symbol(K, Decl(keyofAndForIn.ts, 3, 12)) +>T : Symbol(T, Decl(keyofAndForIn.ts, 3, 29)) +>k : Symbol(k, Decl(keyofAndForIn.ts, 3, 54)) +>K : Symbol(K, Decl(keyofAndForIn.ts, 3, 12)) + + const b = k in obj; +>b : Symbol(b, Decl(keyofAndForIn.ts, 4, 9)) +>k : Symbol(k, Decl(keyofAndForIn.ts, 3, 54)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 3, 33)) + + let k1: K; +>k1 : Symbol(k1, Decl(keyofAndForIn.ts, 5, 7)) +>K : Symbol(K, Decl(keyofAndForIn.ts, 3, 12)) + + for (k1 in obj) { +>k1 : Symbol(k1, Decl(keyofAndForIn.ts, 5, 7)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 3, 33)) + + let x1 = obj[k1]; +>x1 : Symbol(x1, Decl(keyofAndForIn.ts, 7, 11)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 3, 33)) +>k1 : Symbol(k1, Decl(keyofAndForIn.ts, 5, 7)) + } + for (let k2 in obj) { +>k2 : Symbol(k2, Decl(keyofAndForIn.ts, 9, 12)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 3, 33)) + + let x2 = obj[k2]; +>x2 : Symbol(x2, Decl(keyofAndForIn.ts, 10, 11)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 3, 33)) +>k2 : Symbol(k2, Decl(keyofAndForIn.ts, 9, 12)) + } +} + +function f2(obj: { [P in keyof T]: T[P] }, k: keyof T) { +>f2 : Symbol(f2, Decl(keyofAndForIn.ts, 12, 1)) +>T : Symbol(T, Decl(keyofAndForIn.ts, 14, 12)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 14, 15)) +>P : Symbol(P, Decl(keyofAndForIn.ts, 14, 23)) +>T : Symbol(T, Decl(keyofAndForIn.ts, 14, 12)) +>T : Symbol(T, Decl(keyofAndForIn.ts, 14, 12)) +>P : Symbol(P, Decl(keyofAndForIn.ts, 14, 23)) +>k : Symbol(k, Decl(keyofAndForIn.ts, 14, 45)) +>T : Symbol(T, Decl(keyofAndForIn.ts, 14, 12)) + + const b = k in obj; +>b : Symbol(b, Decl(keyofAndForIn.ts, 15, 9)) +>k : Symbol(k, Decl(keyofAndForIn.ts, 14, 45)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 14, 15)) + + let k1: keyof T; +>k1 : Symbol(k1, Decl(keyofAndForIn.ts, 16, 7)) +>T : Symbol(T, Decl(keyofAndForIn.ts, 14, 12)) + + for (k1 in obj) { +>k1 : Symbol(k1, Decl(keyofAndForIn.ts, 16, 7)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 14, 15)) + + let x1 = obj[k1]; +>x1 : Symbol(x1, Decl(keyofAndForIn.ts, 18, 11)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 14, 15)) +>k1 : Symbol(k1, Decl(keyofAndForIn.ts, 16, 7)) + } + for (let k2 in obj) { +>k2 : Symbol(k2, Decl(keyofAndForIn.ts, 20, 12)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 14, 15)) + + let x2 = obj[k2]; +>x2 : Symbol(x2, Decl(keyofAndForIn.ts, 21, 11)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 14, 15)) +>k2 : Symbol(k2, Decl(keyofAndForIn.ts, 20, 12)) + } +} + +function f3(obj: { [P in K]: T[P] }, k: K) { +>f3 : Symbol(f3, Decl(keyofAndForIn.ts, 23, 1)) +>T : Symbol(T, Decl(keyofAndForIn.ts, 25, 12)) +>K : Symbol(K, Decl(keyofAndForIn.ts, 25, 14)) +>T : Symbol(T, Decl(keyofAndForIn.ts, 25, 12)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 25, 34)) +>P : Symbol(P, Decl(keyofAndForIn.ts, 25, 42)) +>K : Symbol(K, Decl(keyofAndForIn.ts, 25, 14)) +>T : Symbol(T, Decl(keyofAndForIn.ts, 25, 12)) +>P : Symbol(P, Decl(keyofAndForIn.ts, 25, 42)) +>k : Symbol(k, Decl(keyofAndForIn.ts, 25, 58)) +>K : Symbol(K, Decl(keyofAndForIn.ts, 25, 14)) + + const b = k in obj; +>b : Symbol(b, Decl(keyofAndForIn.ts, 26, 9)) +>k : Symbol(k, Decl(keyofAndForIn.ts, 25, 58)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 25, 34)) + + let k1: K; +>k1 : Symbol(k1, Decl(keyofAndForIn.ts, 27, 7)) +>K : Symbol(K, Decl(keyofAndForIn.ts, 25, 14)) + + for (k1 in obj) { +>k1 : Symbol(k1, Decl(keyofAndForIn.ts, 27, 7)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 25, 34)) + + let x1 = obj[k1]; +>x1 : Symbol(x1, Decl(keyofAndForIn.ts, 29, 11)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 25, 34)) +>k1 : Symbol(k1, Decl(keyofAndForIn.ts, 27, 7)) + } + for (let k2 in obj) { +>k2 : Symbol(k2, Decl(keyofAndForIn.ts, 31, 12)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 25, 34)) + + let x2 = obj[k2]; +>x2 : Symbol(x2, Decl(keyofAndForIn.ts, 32, 11)) +>obj : Symbol(obj, Decl(keyofAndForIn.ts, 25, 34)) +>k2 : Symbol(k2, Decl(keyofAndForIn.ts, 31, 12)) + } +} diff --git a/tests/baselines/reference/keyofAndForIn.types b/tests/baselines/reference/keyofAndForIn.types new file mode 100644 index 0000000000000..5e992e5d26103 --- /dev/null +++ b/tests/baselines/reference/keyofAndForIn.types @@ -0,0 +1,134 @@ +=== tests/cases/conformance/types/keyof/keyofAndForIn.ts === + +// Repro from #12513 + +function f1(obj: { [P in K]: T }, k: K) { +>f1 : (obj: { [P in K]: T; }, k: K) => void +>K : K +>T : T +>obj : { [P in K]: T; } +>P : P +>K : K +>T : T +>k : K +>K : K + + const b = k in obj; +>b : boolean +>k in obj : boolean +>k : K +>obj : { [P in K]: T; } + + let k1: K; +>k1 : K +>K : K + + for (k1 in obj) { +>k1 : K +>obj : { [P in K]: T; } + + let x1 = obj[k1]; +>x1 : T +>obj[k1] : T +>obj : { [P in K]: T; } +>k1 : K + } + for (let k2 in obj) { +>k2 : K +>obj : { [P in K]: T; } + + let x2 = obj[k2]; +>x2 : T +>obj[k2] : T +>obj : { [P in K]: T; } +>k2 : K + } +} + +function f2(obj: { [P in keyof T]: T[P] }, k: keyof T) { +>f2 : (obj: { [P in keyof T]: T[P]; }, k: keyof T) => void +>T : T +>obj : { [P in keyof T]: T[P]; } +>P : P +>T : T +>T : T +>P : P +>k : keyof T +>T : T + + const b = k in obj; +>b : boolean +>k in obj : boolean +>k : keyof T +>obj : { [P in keyof T]: T[P]; } + + let k1: keyof T; +>k1 : keyof T +>T : T + + for (k1 in obj) { +>k1 : keyof T +>obj : { [P in keyof T]: T[P]; } + + let x1 = obj[k1]; +>x1 : T[keyof T] +>obj[k1] : T[keyof T] +>obj : { [P in keyof T]: T[P]; } +>k1 : keyof T + } + for (let k2 in obj) { +>k2 : keyof T +>obj : { [P in keyof T]: T[P]; } + + let x2 = obj[k2]; +>x2 : T[keyof T] +>obj[k2] : T[keyof T] +>obj : { [P in keyof T]: T[P]; } +>k2 : keyof T + } +} + +function f3(obj: { [P in K]: T[P] }, k: K) { +>f3 : (obj: { [P in K]: T[P]; }, k: K) => void +>T : T +>K : K +>T : T +>obj : { [P in K]: T[P]; } +>P : P +>K : K +>T : T +>P : P +>k : K +>K : K + + const b = k in obj; +>b : boolean +>k in obj : boolean +>k : K +>obj : { [P in K]: T[P]; } + + let k1: K; +>k1 : K +>K : K + + for (k1 in obj) { +>k1 : K +>obj : { [P in K]: T[P]; } + + let x1 = obj[k1]; +>x1 : T[K] +>obj[k1] : T[K] +>obj : { [P in K]: T[P]; } +>k1 : K + } + for (let k2 in obj) { +>k2 : K +>obj : { [P in K]: T[P]; } + + let x2 = obj[k2]; +>x2 : T[K] +>obj[k2] : T[K] +>obj : { [P in K]: T[P]; } +>k2 : K + } +} diff --git a/tests/cases/conformance/types/keyof/keyofAndForIn.ts b/tests/cases/conformance/types/keyof/keyofAndForIn.ts new file mode 100644 index 0000000000000..97b8587a24326 --- /dev/null +++ b/tests/cases/conformance/types/keyof/keyofAndForIn.ts @@ -0,0 +1,36 @@ +// @declaration: true + +// Repro from #12513 + +function f1(obj: { [P in K]: T }, k: K) { + const b = k in obj; + let k1: K; + for (k1 in obj) { + let x1 = obj[k1]; + } + for (let k2 in obj) { + let x2 = obj[k2]; + } +} + +function f2(obj: { [P in keyof T]: T[P] }, k: keyof T) { + const b = k in obj; + let k1: keyof T; + for (k1 in obj) { + let x1 = obj[k1]; + } + for (let k2 in obj) { + let x2 = obj[k2]; + } +} + +function f3(obj: { [P in K]: T[P] }, k: K) { + const b = k in obj; + let k1: K; + for (k1 in obj) { + let x1 = obj[k1]; + } + for (let k2 in obj) { + let x2 = obj[k2]; + } +} \ No newline at end of file From f2c32d251fe86cd556eea6e749df0db5eb0fde6a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 26 Nov 2016 12:17:19 -0800 Subject: [PATCH 12/22] Include mapped types in type inference infinite recursion check --- src/compiler/checker.ts | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f0c6e4edb42a8..21cbe7afe1d92 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8586,19 +8586,6 @@ namespace ts { } } else { - if (getObjectFlags(target) & ObjectFlags.Mapped) { - const constraintType = getConstraintTypeFromMappedType(target); - if (getObjectFlags(source) & ObjectFlags.Mapped) { - inferFromTypes(getConstraintTypeFromMappedType(source), constraintType); - inferFromTypes(getTemplateTypeFromMappedType(source), getTemplateTypeFromMappedType(target)); - return; - } - if (constraintType.flags & TypeFlags.TypeParameter) { - inferFromTypes(getIndexType(source), constraintType); - inferFromTypes(getUnionType(map(getPropertiesOfType(source), getTypeOfSymbol)), getTemplateTypeFromMappedType(target)); - return; - } - } source = getApparentType(source); if (source.flags & TypeFlags.Object) { if (isInProcess(source, target)) { @@ -8619,15 +8606,32 @@ namespace ts { sourceStack[depth] = source; targetStack[depth] = target; depth++; - inferFromProperties(source, target); - inferFromSignatures(source, target, SignatureKind.Call); - inferFromSignatures(source, target, SignatureKind.Construct); - inferFromIndexTypes(source, target); + inferFromObjectTypes(source, target); depth--; } } } + function inferFromObjectTypes(source: Type, target: Type) { + if (getObjectFlags(target) & ObjectFlags.Mapped) { + const constraintType = getConstraintTypeFromMappedType(target); + if (getObjectFlags(source) & ObjectFlags.Mapped) { + inferFromTypes(getConstraintTypeFromMappedType(source), constraintType); + inferFromTypes(getTemplateTypeFromMappedType(source), getTemplateTypeFromMappedType(target)); + return; + } + if (constraintType.flags & TypeFlags.TypeParameter) { + inferFromTypes(getIndexType(source), constraintType); + inferFromTypes(getUnionType(map(getPropertiesOfType(source), getTypeOfSymbol)), getTemplateTypeFromMappedType(target)); + return; + } + } + inferFromProperties(source, target); + inferFromSignatures(source, target, SignatureKind.Call); + inferFromSignatures(source, target, SignatureKind.Construct); + inferFromIndexTypes(source, target); + } + function inferFromProperties(source: Type, target: Type) { const properties = getPropertiesOfObjectType(target); for (const targetProp of properties) { From d1393a60d48a7420cc7a38ccead8da4751e8a7d8 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 26 Nov 2016 12:22:29 -0800 Subject: [PATCH 13/22] Add regression test --- .../mappedTypeInferenceCircularity.js | 12 +++++++++ .../mappedTypeInferenceCircularity.symbols | 26 ++++++++++++++++++ .../mappedTypeInferenceCircularity.types | 27 +++++++++++++++++++ .../mappedTypeInferenceCircularity.ts | 7 +++++ 4 files changed, 72 insertions(+) create mode 100644 tests/baselines/reference/mappedTypeInferenceCircularity.js create mode 100644 tests/baselines/reference/mappedTypeInferenceCircularity.symbols create mode 100644 tests/baselines/reference/mappedTypeInferenceCircularity.types create mode 100644 tests/cases/compiler/mappedTypeInferenceCircularity.ts diff --git a/tests/baselines/reference/mappedTypeInferenceCircularity.js b/tests/baselines/reference/mappedTypeInferenceCircularity.js new file mode 100644 index 0000000000000..d5918d342f644 --- /dev/null +++ b/tests/baselines/reference/mappedTypeInferenceCircularity.js @@ -0,0 +1,12 @@ +//// [mappedTypeInferenceCircularity.ts] +// Repro from #12511 + +type HTML = { [K in 'div']: Block }; +type Block

= (func: HTML) => {}; + +declare var h: HTML; +h.div(h); + +//// [mappedTypeInferenceCircularity.js] +// Repro from #12511 +h.div(h); diff --git a/tests/baselines/reference/mappedTypeInferenceCircularity.symbols b/tests/baselines/reference/mappedTypeInferenceCircularity.symbols new file mode 100644 index 0000000000000..33dceb5cd7614 --- /dev/null +++ b/tests/baselines/reference/mappedTypeInferenceCircularity.symbols @@ -0,0 +1,26 @@ +=== tests/cases/compiler/mappedTypeInferenceCircularity.ts === +// Repro from #12511 + +type HTML = { [K in 'div']: Block }; +>HTML : Symbol(HTML, Decl(mappedTypeInferenceCircularity.ts, 0, 0)) +>K : Symbol(K, Decl(mappedTypeInferenceCircularity.ts, 2, 15)) +>Block : Symbol(Block, Decl(mappedTypeInferenceCircularity.ts, 2, 42)) +>HTML : Symbol(HTML, Decl(mappedTypeInferenceCircularity.ts, 0, 0)) + +type Block

= (func: HTML) => {}; +>Block : Symbol(Block, Decl(mappedTypeInferenceCircularity.ts, 2, 42)) +>P : Symbol(P, Decl(mappedTypeInferenceCircularity.ts, 3, 11)) +>T : Symbol(T, Decl(mappedTypeInferenceCircularity.ts, 3, 17)) +>func : Symbol(func, Decl(mappedTypeInferenceCircularity.ts, 3, 20)) +>HTML : Symbol(HTML, Decl(mappedTypeInferenceCircularity.ts, 0, 0)) + +declare var h: HTML; +>h : Symbol(h, Decl(mappedTypeInferenceCircularity.ts, 5, 11)) +>HTML : Symbol(HTML, Decl(mappedTypeInferenceCircularity.ts, 0, 0)) + +h.div(h); +>h.div : Symbol(div) +>h : Symbol(h, Decl(mappedTypeInferenceCircularity.ts, 5, 11)) +>div : Symbol(div) +>h : Symbol(h, Decl(mappedTypeInferenceCircularity.ts, 5, 11)) + diff --git a/tests/baselines/reference/mappedTypeInferenceCircularity.types b/tests/baselines/reference/mappedTypeInferenceCircularity.types new file mode 100644 index 0000000000000..451da47475689 --- /dev/null +++ b/tests/baselines/reference/mappedTypeInferenceCircularity.types @@ -0,0 +1,27 @@ +=== tests/cases/compiler/mappedTypeInferenceCircularity.ts === +// Repro from #12511 + +type HTML = { [K in 'div']: Block }; +>HTML : HTML +>K : K +>Block : Block

+>HTML : HTML + +type Block

= (func: HTML) => {}; +>Block : Block

+>P : P +>T : T +>func : HTML +>HTML : HTML + +declare var h: HTML; +>h : HTML +>HTML : HTML + +h.div(h); +>h.div(h) : {} +>h.div : Block +>h : HTML +>div : Block +>h : HTML + diff --git a/tests/cases/compiler/mappedTypeInferenceCircularity.ts b/tests/cases/compiler/mappedTypeInferenceCircularity.ts new file mode 100644 index 0000000000000..56fe08c5fe2e6 --- /dev/null +++ b/tests/cases/compiler/mappedTypeInferenceCircularity.ts @@ -0,0 +1,7 @@ +// Repro from #12511 + +type HTML = { [K in 'div']: Block }; +type Block

= (func: HTML) => {}; + +declare var h: HTML; +h.div(h); \ No newline at end of file From ecd10be1775e12f1e921654cec4a60cb067b5740 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 27 Nov 2016 12:48:59 -0800 Subject: [PATCH 14/22] Reorder type inference cases --- src/compiler/checker.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fcf90a11da2ff..2feb6b3f9c3cd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8668,11 +8668,14 @@ namespace ts { function inferFromObjectTypes(source: Type, target: Type) { if (getObjectFlags(target) & ObjectFlags.Mapped) { const constraintType = getConstraintTypeFromMappedType(target); - if (getObjectFlags(source) & ObjectFlags.Mapped) { - // We're inferring from a mapped type to a mapped type, so simply infer from constraint type to - // constraint type and from template type to template type. - inferFromTypes(getConstraintTypeFromMappedType(source), constraintType); - inferFromTypes(getTemplateTypeFromMappedType(source), getTemplateTypeFromMappedType(target)); + if (constraintType.flags & TypeFlags.Index) { + // We're inferring from some source type S to an isomorphic mapped type { [P in keyof T]: X }, + // where T is a type parameter. Use inferTypeForIsomorphicMappedType to infer a suitable source + // type and then infer from that type to T. + const index = indexOf(typeParameters, (constraintType).type); + if (index >= 0 && !typeInferences[index].isFixed) { + inferFromTypes(inferTypeForIsomorphicMappedType(source, target), typeParameters[index]); + } return; } if (constraintType.flags & TypeFlags.TypeParameter) { @@ -8682,14 +8685,11 @@ namespace ts { inferFromTypes(getUnionType(map(getPropertiesOfType(source), getTypeOfSymbol)), getTemplateTypeFromMappedType(target)); return; } - if (constraintType.flags & TypeFlags.Index) { - // We're inferring from some source type S to an isomorphic mapped type { [P in keyof T]: X }, - // where T is a type parameter. Use inferTypeForIsomorphicMappedType to infer a suitable source - // type and then infer from that type to T. - const index = indexOf(typeParameters, (constraintType).type); - if (index >= 0 && !typeInferences[index].isFixed) { - inferFromTypes(inferTypeForIsomorphicMappedType(source, target), typeParameters[index]); - } + if (getObjectFlags(source) & ObjectFlags.Mapped) { + // We're inferring from a mapped type to a mapped type, so simply infer from constraint type to + // constraint type and from template type to template type. + inferFromTypes(getConstraintTypeFromMappedType(source), constraintType); + inferFromTypes(getTemplateTypeFromMappedType(source), getTemplateTypeFromMappedType(target)); return; } } From 997184708dd8df4e410f6c8d4d56badef83b427b Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 27 Nov 2016 12:49:27 -0800 Subject: [PATCH 15/22] Add tests --- .../isomorphicMappedTypeInference.js | 222 ++++++++++ .../isomorphicMappedTypeInference.symbols | 334 +++++++++++++++ .../isomorphicMappedTypeInference.types | 405 ++++++++++++++++++ .../mapped/isomorphicMappedTypeInference.ts | 107 +++++ 4 files changed, 1068 insertions(+) create mode 100644 tests/baselines/reference/isomorphicMappedTypeInference.js create mode 100644 tests/baselines/reference/isomorphicMappedTypeInference.symbols create mode 100644 tests/baselines/reference/isomorphicMappedTypeInference.types create mode 100644 tests/cases/conformance/types/mapped/isomorphicMappedTypeInference.ts diff --git a/tests/baselines/reference/isomorphicMappedTypeInference.js b/tests/baselines/reference/isomorphicMappedTypeInference.js new file mode 100644 index 0000000000000..0fc646043dcb7 --- /dev/null +++ b/tests/baselines/reference/isomorphicMappedTypeInference.js @@ -0,0 +1,222 @@ +//// [isomorphicMappedTypeInference.ts] + +type Box = { + value: T; +} + +type Boxified = { + [P in keyof T]: Box; +} + +function box(x: T): Box { + return { value: x }; +} + +function unbox(x: Box): T { + return x.value; +} + +function boxify(obj: T): Boxified { + let result = {} as Boxified; + for (let k in obj) { + result[k] = box(obj[k]); + } + return result; +} + +function unboxify(obj: Boxified): T { + let result = {} as T; + for (let k in obj) { + result[k] = unbox(obj[k]); + } + return result; +} + +function assignBoxified(obj: Boxified, values: T) { + for (let k in values) { + obj[k].value = values[k]; + } +} + +function f1() { + let v = { + a: 42, + b: "hello", + c: true + }; + let b = boxify(v); + let x: number = b.a.value; +} + +function f2() { + let b = { + a: box(42), + b: box("hello"), + c: box(true) + }; + let v = unboxify(b); + let x: number = v.a; +} + +function f3() { + let b = { + a: box(42), + b: box("hello"), + c: box(true) + }; + assignBoxified(b, { c: false }); +} + +function f4() { + let b = { + a: box(42), + b: box("hello"), + c: box(true) + }; + b = boxify(unboxify(b)); + b = unboxify(boxify(b)); +} + +function makeRecord(obj: { [P in K]: T }) { + return obj; +} + +function f5(s: string) { + let b = makeRecord({ + a: box(42), + b: box("hello"), + c: box(true) + }); + let v = unboxify(b); + let x: string | number | boolean = v.a; +} + +function makeDictionary(obj: { [x: string]: T }) { + return obj; +} + +function f6(s: string) { + let b = makeDictionary({ + a: box(42), + b: box("hello"), + c: box(true) + }); + let v = unboxify(b); + let x: string | number | boolean = v[s]; +} + +//// [isomorphicMappedTypeInference.js] +function box(x) { + return { value: x }; +} +function unbox(x) { + return x.value; +} +function boxify(obj) { + var result = {}; + for (var k in obj) { + result[k] = box(obj[k]); + } + return result; +} +function unboxify(obj) { + var result = {}; + for (var k in obj) { + result[k] = unbox(obj[k]); + } + return result; +} +function assignBoxified(obj, values) { + for (var k in values) { + obj[k].value = values[k]; + } +} +function f1() { + var v = { + a: 42, + b: "hello", + c: true + }; + var b = boxify(v); + var x = b.a.value; +} +function f2() { + var b = { + a: box(42), + b: box("hello"), + c: box(true) + }; + var v = unboxify(b); + var x = v.a; +} +function f3() { + var b = { + a: box(42), + b: box("hello"), + c: box(true) + }; + assignBoxified(b, { c: false }); +} +function f4() { + var b = { + a: box(42), + b: box("hello"), + c: box(true) + }; + b = boxify(unboxify(b)); + b = unboxify(boxify(b)); +} +function makeRecord(obj) { + return obj; +} +function f5(s) { + var b = makeRecord({ + a: box(42), + b: box("hello"), + c: box(true) + }); + var v = unboxify(b); + var x = v.a; +} +function makeDictionary(obj) { + return obj; +} +function f6(s) { + var b = makeDictionary({ + a: box(42), + b: box("hello"), + c: box(true) + }); + var v = unboxify(b); + var x = v[s]; +} + + +//// [isomorphicMappedTypeInference.d.ts] +declare type Box = { + value: T; +}; +declare type Boxified = { + [P in keyof T]: Box; +}; +declare function box(x: T): Box; +declare function unbox(x: Box): T; +declare function boxify(obj: T): Boxified; +declare function unboxify(obj: Boxified): T; +declare function assignBoxified(obj: Boxified, values: T): void; +declare function f1(): void; +declare function f2(): void; +declare function f3(): void; +declare function f4(): void; +declare function makeRecord(obj: { + [P in K]: T; +}): { + [P in K]: T; +}; +declare function f5(s: string): void; +declare function makeDictionary(obj: { + [x: string]: T; +}): { + [x: string]: T; +}; +declare function f6(s: string): void; diff --git a/tests/baselines/reference/isomorphicMappedTypeInference.symbols b/tests/baselines/reference/isomorphicMappedTypeInference.symbols new file mode 100644 index 0000000000000..62dcc6316bcf7 --- /dev/null +++ b/tests/baselines/reference/isomorphicMappedTypeInference.symbols @@ -0,0 +1,334 @@ +=== tests/cases/conformance/types/mapped/isomorphicMappedTypeInference.ts === + +type Box = { +>Box : Symbol(Box, Decl(isomorphicMappedTypeInference.ts, 0, 0)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 1, 9)) + + value: T; +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 1, 15)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 1, 9)) +} + +type Boxified = { +>Boxified : Symbol(Boxified, Decl(isomorphicMappedTypeInference.ts, 3, 1)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 5, 14)) + + [P in keyof T]: Box; +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 6, 5)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 5, 14)) +>Box : Symbol(Box, Decl(isomorphicMappedTypeInference.ts, 0, 0)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 5, 14)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 6, 5)) +} + +function box(x: T): Box { +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 9, 13)) +>x : Symbol(x, Decl(isomorphicMappedTypeInference.ts, 9, 16)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 9, 13)) +>Box : Symbol(Box, Decl(isomorphicMappedTypeInference.ts, 0, 0)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 9, 13)) + + return { value: x }; +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 10, 12)) +>x : Symbol(x, Decl(isomorphicMappedTypeInference.ts, 9, 16)) +} + +function unbox(x: Box): T { +>unbox : Symbol(unbox, Decl(isomorphicMappedTypeInference.ts, 11, 1)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 13, 15)) +>x : Symbol(x, Decl(isomorphicMappedTypeInference.ts, 13, 18)) +>Box : Symbol(Box, Decl(isomorphicMappedTypeInference.ts, 0, 0)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 13, 15)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 13, 15)) + + return x.value; +>x.value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 1, 15)) +>x : Symbol(x, Decl(isomorphicMappedTypeInference.ts, 13, 18)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 1, 15)) +} + +function boxify(obj: T): Boxified { +>boxify : Symbol(boxify, Decl(isomorphicMappedTypeInference.ts, 15, 1)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 17, 16)) +>obj : Symbol(obj, Decl(isomorphicMappedTypeInference.ts, 17, 19)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 17, 16)) +>Boxified : Symbol(Boxified, Decl(isomorphicMappedTypeInference.ts, 3, 1)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 17, 16)) + + let result = {} as Boxified; +>result : Symbol(result, Decl(isomorphicMappedTypeInference.ts, 18, 7)) +>Boxified : Symbol(Boxified, Decl(isomorphicMappedTypeInference.ts, 3, 1)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 17, 16)) + + for (let k in obj) { +>k : Symbol(k, Decl(isomorphicMappedTypeInference.ts, 19, 12)) +>obj : Symbol(obj, Decl(isomorphicMappedTypeInference.ts, 17, 19)) + + result[k] = box(obj[k]); +>result : Symbol(result, Decl(isomorphicMappedTypeInference.ts, 18, 7)) +>k : Symbol(k, Decl(isomorphicMappedTypeInference.ts, 19, 12)) +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) +>obj : Symbol(obj, Decl(isomorphicMappedTypeInference.ts, 17, 19)) +>k : Symbol(k, Decl(isomorphicMappedTypeInference.ts, 19, 12)) + } + return result; +>result : Symbol(result, Decl(isomorphicMappedTypeInference.ts, 18, 7)) +} + +function unboxify(obj: Boxified): T { +>unboxify : Symbol(unboxify, Decl(isomorphicMappedTypeInference.ts, 23, 1)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 25, 18)) +>obj : Symbol(obj, Decl(isomorphicMappedTypeInference.ts, 25, 21)) +>Boxified : Symbol(Boxified, Decl(isomorphicMappedTypeInference.ts, 3, 1)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 25, 18)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 25, 18)) + + let result = {} as T; +>result : Symbol(result, Decl(isomorphicMappedTypeInference.ts, 26, 7)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 25, 18)) + + for (let k in obj) { +>k : Symbol(k, Decl(isomorphicMappedTypeInference.ts, 27, 12)) +>obj : Symbol(obj, Decl(isomorphicMappedTypeInference.ts, 25, 21)) + + result[k] = unbox(obj[k]); +>result : Symbol(result, Decl(isomorphicMappedTypeInference.ts, 26, 7)) +>k : Symbol(k, Decl(isomorphicMappedTypeInference.ts, 27, 12)) +>unbox : Symbol(unbox, Decl(isomorphicMappedTypeInference.ts, 11, 1)) +>obj : Symbol(obj, Decl(isomorphicMappedTypeInference.ts, 25, 21)) +>k : Symbol(k, Decl(isomorphicMappedTypeInference.ts, 27, 12)) + } + return result; +>result : Symbol(result, Decl(isomorphicMappedTypeInference.ts, 26, 7)) +} + +function assignBoxified(obj: Boxified, values: T) { +>assignBoxified : Symbol(assignBoxified, Decl(isomorphicMappedTypeInference.ts, 31, 1)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 33, 24)) +>obj : Symbol(obj, Decl(isomorphicMappedTypeInference.ts, 33, 27)) +>Boxified : Symbol(Boxified, Decl(isomorphicMappedTypeInference.ts, 3, 1)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 33, 24)) +>values : Symbol(values, Decl(isomorphicMappedTypeInference.ts, 33, 44)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 33, 24)) + + for (let k in values) { +>k : Symbol(k, Decl(isomorphicMappedTypeInference.ts, 34, 12)) +>values : Symbol(values, Decl(isomorphicMappedTypeInference.ts, 33, 44)) + + obj[k].value = values[k]; +>obj[k].value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 1, 15)) +>obj : Symbol(obj, Decl(isomorphicMappedTypeInference.ts, 33, 27)) +>k : Symbol(k, Decl(isomorphicMappedTypeInference.ts, 34, 12)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 1, 15)) +>values : Symbol(values, Decl(isomorphicMappedTypeInference.ts, 33, 44)) +>k : Symbol(k, Decl(isomorphicMappedTypeInference.ts, 34, 12)) + } +} + +function f1() { +>f1 : Symbol(f1, Decl(isomorphicMappedTypeInference.ts, 37, 1)) + + let v = { +>v : Symbol(v, Decl(isomorphicMappedTypeInference.ts, 40, 7)) + + a: 42, +>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 40, 13)) + + b: "hello", +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 41, 14)) + + c: true +>c : Symbol(c, Decl(isomorphicMappedTypeInference.ts, 42, 19)) + + }; + let b = boxify(v); +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 45, 7)) +>boxify : Symbol(boxify, Decl(isomorphicMappedTypeInference.ts, 15, 1)) +>v : Symbol(v, Decl(isomorphicMappedTypeInference.ts, 40, 7)) + + let x: number = b.a.value; +>x : Symbol(x, Decl(isomorphicMappedTypeInference.ts, 46, 7)) +>b.a.value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 1, 15)) +>b.a : Symbol(a) +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 45, 7)) +>a : Symbol(a) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 1, 15)) +} + +function f2() { +>f2 : Symbol(f2, Decl(isomorphicMappedTypeInference.ts, 47, 1)) + + let b = { +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 50, 7)) + + a: box(42), +>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 50, 13)) +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) + + b: box("hello"), +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 51, 19)) +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) + + c: box(true) +>c : Symbol(c, Decl(isomorphicMappedTypeInference.ts, 52, 24)) +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) + + }; + let v = unboxify(b); +>v : Symbol(v, Decl(isomorphicMappedTypeInference.ts, 55, 7)) +>unboxify : Symbol(unboxify, Decl(isomorphicMappedTypeInference.ts, 23, 1)) +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 50, 7)) + + let x: number = v.a; +>x : Symbol(x, Decl(isomorphicMappedTypeInference.ts, 56, 7)) +>v.a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 50, 13)) +>v : Symbol(v, Decl(isomorphicMappedTypeInference.ts, 55, 7)) +>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 50, 13)) +} + +function f3() { +>f3 : Symbol(f3, Decl(isomorphicMappedTypeInference.ts, 57, 1)) + + let b = { +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 60, 7)) + + a: box(42), +>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 60, 13)) +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) + + b: box("hello"), +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 61, 19)) +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) + + c: box(true) +>c : Symbol(c, Decl(isomorphicMappedTypeInference.ts, 62, 24)) +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) + + }; + assignBoxified(b, { c: false }); +>assignBoxified : Symbol(assignBoxified, Decl(isomorphicMappedTypeInference.ts, 31, 1)) +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 60, 7)) +>c : Symbol(c, Decl(isomorphicMappedTypeInference.ts, 65, 23)) +} + +function f4() { +>f4 : Symbol(f4, Decl(isomorphicMappedTypeInference.ts, 66, 1)) + + let b = { +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 69, 7)) + + a: box(42), +>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 69, 13)) +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) + + b: box("hello"), +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 70, 19)) +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) + + c: box(true) +>c : Symbol(c, Decl(isomorphicMappedTypeInference.ts, 71, 24)) +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) + + }; + b = boxify(unboxify(b)); +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 69, 7)) +>boxify : Symbol(boxify, Decl(isomorphicMappedTypeInference.ts, 15, 1)) +>unboxify : Symbol(unboxify, Decl(isomorphicMappedTypeInference.ts, 23, 1)) +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 69, 7)) + + b = unboxify(boxify(b)); +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 69, 7)) +>unboxify : Symbol(unboxify, Decl(isomorphicMappedTypeInference.ts, 23, 1)) +>boxify : Symbol(boxify, Decl(isomorphicMappedTypeInference.ts, 15, 1)) +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 69, 7)) +} + +function makeRecord(obj: { [P in K]: T }) { +>makeRecord : Symbol(makeRecord, Decl(isomorphicMappedTypeInference.ts, 76, 1)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 78, 20)) +>K : Symbol(K, Decl(isomorphicMappedTypeInference.ts, 78, 22)) +>obj : Symbol(obj, Decl(isomorphicMappedTypeInference.ts, 78, 41)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 78, 49)) +>K : Symbol(K, Decl(isomorphicMappedTypeInference.ts, 78, 22)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 78, 20)) + + return obj; +>obj : Symbol(obj, Decl(isomorphicMappedTypeInference.ts, 78, 41)) +} + +function f5(s: string) { +>f5 : Symbol(f5, Decl(isomorphicMappedTypeInference.ts, 80, 1)) +>s : Symbol(s, Decl(isomorphicMappedTypeInference.ts, 82, 12)) + + let b = makeRecord({ +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 83, 7)) +>makeRecord : Symbol(makeRecord, Decl(isomorphicMappedTypeInference.ts, 76, 1)) + + a: box(42), +>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 83, 24)) +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) + + b: box("hello"), +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 84, 19)) +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) + + c: box(true) +>c : Symbol(c, Decl(isomorphicMappedTypeInference.ts, 85, 24)) +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) + + }); + let v = unboxify(b); +>v : Symbol(v, Decl(isomorphicMappedTypeInference.ts, 88, 7)) +>unboxify : Symbol(unboxify, Decl(isomorphicMappedTypeInference.ts, 23, 1)) +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 83, 7)) + + let x: string | number | boolean = v.a; +>x : Symbol(x, Decl(isomorphicMappedTypeInference.ts, 89, 7)) +>v.a : Symbol(a) +>v : Symbol(v, Decl(isomorphicMappedTypeInference.ts, 88, 7)) +>a : Symbol(a) +} + +function makeDictionary(obj: { [x: string]: T }) { +>makeDictionary : Symbol(makeDictionary, Decl(isomorphicMappedTypeInference.ts, 90, 1)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 92, 24)) +>obj : Symbol(obj, Decl(isomorphicMappedTypeInference.ts, 92, 27)) +>x : Symbol(x, Decl(isomorphicMappedTypeInference.ts, 92, 35)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 92, 24)) + + return obj; +>obj : Symbol(obj, Decl(isomorphicMappedTypeInference.ts, 92, 27)) +} + +function f6(s: string) { +>f6 : Symbol(f6, Decl(isomorphicMappedTypeInference.ts, 94, 1)) +>s : Symbol(s, Decl(isomorphicMappedTypeInference.ts, 96, 12)) + + let b = makeDictionary({ +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 97, 7)) +>makeDictionary : Symbol(makeDictionary, Decl(isomorphicMappedTypeInference.ts, 90, 1)) + + a: box(42), +>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 97, 28)) +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) + + b: box("hello"), +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 98, 19)) +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) + + c: box(true) +>c : Symbol(c, Decl(isomorphicMappedTypeInference.ts, 99, 24)) +>box : Symbol(box, Decl(isomorphicMappedTypeInference.ts, 7, 1)) + + }); + let v = unboxify(b); +>v : Symbol(v, Decl(isomorphicMappedTypeInference.ts, 102, 7)) +>unboxify : Symbol(unboxify, Decl(isomorphicMappedTypeInference.ts, 23, 1)) +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 97, 7)) + + let x: string | number | boolean = v[s]; +>x : Symbol(x, Decl(isomorphicMappedTypeInference.ts, 103, 7)) +>v : Symbol(v, Decl(isomorphicMappedTypeInference.ts, 102, 7)) +>s : Symbol(s, Decl(isomorphicMappedTypeInference.ts, 96, 12)) +} diff --git a/tests/baselines/reference/isomorphicMappedTypeInference.types b/tests/baselines/reference/isomorphicMappedTypeInference.types new file mode 100644 index 0000000000000..00a80639f732c --- /dev/null +++ b/tests/baselines/reference/isomorphicMappedTypeInference.types @@ -0,0 +1,405 @@ +=== tests/cases/conformance/types/mapped/isomorphicMappedTypeInference.ts === + +type Box = { +>Box : Box +>T : T + + value: T; +>value : T +>T : T +} + +type Boxified = { +>Boxified : Boxified +>T : T + + [P in keyof T]: Box; +>P : P +>T : T +>Box : Box +>T : T +>P : P +} + +function box(x: T): Box { +>box : (x: T) => Box +>T : T +>x : T +>T : T +>Box : Box +>T : T + + return { value: x }; +>{ value: x } : { value: T; } +>value : T +>x : T +} + +function unbox(x: Box): T { +>unbox : (x: Box) => T +>T : T +>x : Box +>Box : Box +>T : T +>T : T + + return x.value; +>x.value : T +>x : Box +>value : T +} + +function boxify(obj: T): Boxified { +>boxify : (obj: T) => Boxified +>T : T +>obj : T +>T : T +>Boxified : Boxified +>T : T + + let result = {} as Boxified; +>result : Boxified +>{} as Boxified : Boxified +>{} : {} +>Boxified : Boxified +>T : T + + for (let k in obj) { +>k : keyof T +>obj : T + + result[k] = box(obj[k]); +>result[k] = box(obj[k]) : Box +>result[k] : Box +>result : Boxified +>k : keyof T +>box(obj[k]) : Box +>box : (x: T) => Box +>obj[k] : T[keyof T] +>obj : T +>k : keyof T + } + return result; +>result : Boxified +} + +function unboxify(obj: Boxified): T { +>unboxify : (obj: Boxified) => T +>T : T +>obj : Boxified +>Boxified : Boxified +>T : T +>T : T + + let result = {} as T; +>result : T +>{} as T : T +>{} : {} +>T : T + + for (let k in obj) { +>k : keyof T +>obj : Boxified + + result[k] = unbox(obj[k]); +>result[k] = unbox(obj[k]) : T[keyof T] +>result[k] : T[keyof T] +>result : T +>k : keyof T +>unbox(obj[k]) : T[keyof T] +>unbox : (x: Box) => T +>obj[k] : Box +>obj : Boxified +>k : keyof T + } + return result; +>result : T +} + +function assignBoxified(obj: Boxified, values: T) { +>assignBoxified : (obj: Boxified, values: T) => void +>T : T +>obj : Boxified +>Boxified : Boxified +>T : T +>values : T +>T : T + + for (let k in values) { +>k : keyof T +>values : T + + obj[k].value = values[k]; +>obj[k].value = values[k] : T[keyof T] +>obj[k].value : T[keyof T] +>obj[k] : Box +>obj : Boxified +>k : keyof T +>value : T[keyof T] +>values[k] : T[keyof T] +>values : T +>k : keyof T + } +} + +function f1() { +>f1 : () => void + + let v = { +>v : { a: number; b: string; c: boolean; } +>{ a: 42, b: "hello", c: true } : { a: number; b: string; c: boolean; } + + a: 42, +>a : number +>42 : 42 + + b: "hello", +>b : string +>"hello" : "hello" + + c: true +>c : boolean +>true : true + + }; + let b = boxify(v); +>b : Boxified<{ a: number; b: string; c: boolean; }> +>boxify(v) : Boxified<{ a: number; b: string; c: boolean; }> +>boxify : (obj: T) => Boxified +>v : { a: number; b: string; c: boolean; } + + let x: number = b.a.value; +>x : number +>b.a.value : number +>b.a : Box +>b : Boxified<{ a: number; b: string; c: boolean; }> +>a : Box +>value : number +} + +function f2() { +>f2 : () => void + + let b = { +>b : { a: Box; b: Box; c: Box; } +>{ a: box(42), b: box("hello"), c: box(true) } : { a: Box; b: Box; c: Box; } + + a: box(42), +>a : Box +>box(42) : Box +>box : (x: T) => Box +>42 : 42 + + b: box("hello"), +>b : Box +>box("hello") : Box +>box : (x: T) => Box +>"hello" : "hello" + + c: box(true) +>c : Box +>box(true) : Box +>box : (x: T) => Box +>true : true + + }; + let v = unboxify(b); +>v : { a: number; b: string; c: boolean; } +>unboxify(b) : { a: number; b: string; c: boolean; } +>unboxify : (obj: Boxified) => T +>b : { a: Box; b: Box; c: Box; } + + let x: number = v.a; +>x : number +>v.a : number +>v : { a: number; b: string; c: boolean; } +>a : number +} + +function f3() { +>f3 : () => void + + let b = { +>b : { a: Box; b: Box; c: Box; } +>{ a: box(42), b: box("hello"), c: box(true) } : { a: Box; b: Box; c: Box; } + + a: box(42), +>a : Box +>box(42) : Box +>box : (x: T) => Box +>42 : 42 + + b: box("hello"), +>b : Box +>box("hello") : Box +>box : (x: T) => Box +>"hello" : "hello" + + c: box(true) +>c : Box +>box(true) : Box +>box : (x: T) => Box +>true : true + + }; + assignBoxified(b, { c: false }); +>assignBoxified(b, { c: false }) : void +>assignBoxified : (obj: Boxified, values: T) => void +>b : { a: Box; b: Box; c: Box; } +>{ c: false } : { c: false; } +>c : boolean +>false : false +} + +function f4() { +>f4 : () => void + + let b = { +>b : { a: Box; b: Box; c: Box; } +>{ a: box(42), b: box("hello"), c: box(true) } : { a: Box; b: Box; c: Box; } + + a: box(42), +>a : Box +>box(42) : Box +>box : (x: T) => Box +>42 : 42 + + b: box("hello"), +>b : Box +>box("hello") : Box +>box : (x: T) => Box +>"hello" : "hello" + + c: box(true) +>c : Box +>box(true) : Box +>box : (x: T) => Box +>true : true + + }; + b = boxify(unboxify(b)); +>b = boxify(unboxify(b)) : Boxified<{ a: number; b: string; c: boolean; }> +>b : { a: Box; b: Box; c: Box; } +>boxify(unboxify(b)) : Boxified<{ a: number; b: string; c: boolean; }> +>boxify : (obj: T) => Boxified +>unboxify(b) : { a: number; b: string; c: boolean; } +>unboxify : (obj: Boxified) => T +>b : { a: Box; b: Box; c: Box; } + + b = unboxify(boxify(b)); +>b = unboxify(boxify(b)) : { a: Box; b: Box; c: Box; } +>b : { a: Box; b: Box; c: Box; } +>unboxify(boxify(b)) : { a: Box; b: Box; c: Box; } +>unboxify : (obj: Boxified) => T +>boxify(b) : Boxified<{ a: Box; b: Box; c: Box; }> +>boxify : (obj: T) => Boxified +>b : { a: Box; b: Box; c: Box; } +} + +function makeRecord(obj: { [P in K]: T }) { +>makeRecord : (obj: { [P in K]: T; }) => { [P in K]: T; } +>T : T +>K : K +>obj : { [P in K]: T; } +>P : P +>K : K +>T : T + + return obj; +>obj : { [P in K]: T; } +} + +function f5(s: string) { +>f5 : (s: string) => void +>s : string + + let b = makeRecord({ +>b : { a: Box | Box | Box; b: Box | Box | Box; c: Box | Box | Box; } +>makeRecord({ a: box(42), b: box("hello"), c: box(true) }) : { a: Box | Box | Box; b: Box | Box | Box; c: Box | Box | Box; } +>makeRecord : (obj: { [P in K]: T; }) => { [P in K]: T; } +>{ a: box(42), b: box("hello"), c: box(true) } : { a: Box; b: Box; c: Box; } + + a: box(42), +>a : Box +>box(42) : Box +>box : (x: T) => Box +>42 : 42 + + b: box("hello"), +>b : Box +>box("hello") : Box +>box : (x: T) => Box +>"hello" : "hello" + + c: box(true) +>c : Box +>box(true) : Box +>box : (x: T) => Box +>true : true + + }); + let v = unboxify(b); +>v : { a: string | number | boolean; b: string | number | boolean; c: string | number | boolean; } +>unboxify(b) : { a: string | number | boolean; b: string | number | boolean; c: string | number | boolean; } +>unboxify : (obj: Boxified) => T +>b : { a: Box | Box | Box; b: Box | Box | Box; c: Box | Box | Box; } + + let x: string | number | boolean = v.a; +>x : string | number | boolean +>v.a : string | number | boolean +>v : { a: string | number | boolean; b: string | number | boolean; c: string | number | boolean; } +>a : string | number | boolean +} + +function makeDictionary(obj: { [x: string]: T }) { +>makeDictionary : (obj: { [x: string]: T; }) => { [x: string]: T; } +>T : T +>obj : { [x: string]: T; } +>x : string +>T : T + + return obj; +>obj : { [x: string]: T; } +} + +function f6(s: string) { +>f6 : (s: string) => void +>s : string + + let b = makeDictionary({ +>b : { [x: string]: Box | Box | Box; } +>makeDictionary({ a: box(42), b: box("hello"), c: box(true) }) : { [x: string]: Box | Box | Box; } +>makeDictionary : (obj: { [x: string]: T; }) => { [x: string]: T; } +>{ a: box(42), b: box("hello"), c: box(true) } : { a: Box; b: Box; c: Box; } + + a: box(42), +>a : Box +>box(42) : Box +>box : (x: T) => Box +>42 : 42 + + b: box("hello"), +>b : Box +>box("hello") : Box +>box : (x: T) => Box +>"hello" : "hello" + + c: box(true) +>c : Box +>box(true) : Box +>box : (x: T) => Box +>true : true + + }); + let v = unboxify(b); +>v : { [x: string]: string | number | boolean; } +>unboxify(b) : { [x: string]: string | number | boolean; } +>unboxify : (obj: Boxified) => T +>b : { [x: string]: Box | Box | Box; } + + let x: string | number | boolean = v[s]; +>x : string | number | boolean +>v[s] : string | number | boolean +>v : { [x: string]: string | number | boolean; } +>s : string +} diff --git a/tests/cases/conformance/types/mapped/isomorphicMappedTypeInference.ts b/tests/cases/conformance/types/mapped/isomorphicMappedTypeInference.ts new file mode 100644 index 0000000000000..19a0c4889a50f --- /dev/null +++ b/tests/cases/conformance/types/mapped/isomorphicMappedTypeInference.ts @@ -0,0 +1,107 @@ +// @noimplicitany: true +// @declaration: true + +type Box = { + value: T; +} + +type Boxified = { + [P in keyof T]: Box; +} + +function box(x: T): Box { + return { value: x }; +} + +function unbox(x: Box): T { + return x.value; +} + +function boxify(obj: T): Boxified { + let result = {} as Boxified; + for (let k in obj) { + result[k] = box(obj[k]); + } + return result; +} + +function unboxify(obj: Boxified): T { + let result = {} as T; + for (let k in obj) { + result[k] = unbox(obj[k]); + } + return result; +} + +function assignBoxified(obj: Boxified, values: T) { + for (let k in values) { + obj[k].value = values[k]; + } +} + +function f1() { + let v = { + a: 42, + b: "hello", + c: true + }; + let b = boxify(v); + let x: number = b.a.value; +} + +function f2() { + let b = { + a: box(42), + b: box("hello"), + c: box(true) + }; + let v = unboxify(b); + let x: number = v.a; +} + +function f3() { + let b = { + a: box(42), + b: box("hello"), + c: box(true) + }; + assignBoxified(b, { c: false }); +} + +function f4() { + let b = { + a: box(42), + b: box("hello"), + c: box(true) + }; + b = boxify(unboxify(b)); + b = unboxify(boxify(b)); +} + +function makeRecord(obj: { [P in K]: T }) { + return obj; +} + +function f5(s: string) { + let b = makeRecord({ + a: box(42), + b: box("hello"), + c: box(true) + }); + let v = unboxify(b); + let x: string | number | boolean = v.a; +} + +function makeDictionary(obj: { [x: string]: T }) { + return obj; +} + +function f6(s: string) { + let b = makeDictionary({ + a: box(42), + b: box("hello"), + c: box(true) + }); + let v = unboxify(b); + let x: string | number | boolean = v[s]; +} \ No newline at end of file From 8ee5f7d64f1ede8d16d01d1ca4d1004e8d68f25b Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 27 Nov 2016 19:49:57 -0800 Subject: [PATCH 16/22] Remove unused case in type inference --- src/compiler/checker.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2feb6b3f9c3cd..71dc4ec826e2c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8685,13 +8685,6 @@ namespace ts { inferFromTypes(getUnionType(map(getPropertiesOfType(source), getTypeOfSymbol)), getTemplateTypeFromMappedType(target)); return; } - if (getObjectFlags(source) & ObjectFlags.Mapped) { - // We're inferring from a mapped type to a mapped type, so simply infer from constraint type to - // constraint type and from template type to template type. - inferFromTypes(getConstraintTypeFromMappedType(source), constraintType); - inferFromTypes(getTemplateTypeFromMappedType(source), getTemplateTypeFromMappedType(target)); - return; - } } inferFromProperties(source, target); inferFromSignatures(source, target, SignatureKind.Call); From 9970606f355bd1fdc2ce0a5ce03716415f8391ef Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 27 Nov 2016 19:58:05 -0800 Subject: [PATCH 17/22] Remove unused code in resolveMappedTypeMembers --- src/compiler/checker.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 71dc4ec826e2c..d454465a7caca 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4494,7 +4494,6 @@ namespace ts { function resolveMappedTypeMembers(type: MappedType) { const members: SymbolTable = createMap(); let stringIndexInfo: IndexInfo; - let numberIndexInfo: IndexInfo; // Resolve upfront such that recursive references see an empty object type. setStructuredTypeMembers(type, emptySymbols, emptyArray, emptyArray, undefined, undefined); // In { [P in K]: T }, we refer to P as the type parameter type, K as the constraint type, @@ -4529,16 +4528,8 @@ namespace ts { else if (t.flags & TypeFlags.String) { stringIndexInfo = createIndexInfo(propType, isReadonly); } - else if (t.flags & TypeFlags.Number) { - numberIndexInfo = createIndexInfo(propType, isReadonly); - } }); - // If we created both a string and a numeric string index signature, and if the two index - // signatures have identical types, discard the redundant numeric index signature. - if (stringIndexInfo && numberIndexInfo && isTypeIdenticalTo(stringIndexInfo.type, numberIndexInfo.type)) { - numberIndexInfo = undefined; - } - setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); + setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, undefined); } function getTypeParameterFromMappedType(type: MappedType) { From 8b7252c4b0faad318a37dd609bfcf7db71154236 Mon Sep 17 00:00:00 2001 From: Ethan Resnick Date: Mon, 28 Nov 2016 04:21:33 -0800 Subject: [PATCH 18/22] Update keyof tests to reflect #12425 Removes number from all the keyof types, and adds a test that numeric indexes are ignored. --- .../reference/keyofAndIndexedAccess.js | 21 +- .../reference/keyofAndIndexedAccess.symbols | 864 +++++++++--------- .../reference/keyofAndIndexedAccess.types | 24 +- .../types/keyof/keyofAndIndexedAccess.ts | 16 +- 4 files changed, 479 insertions(+), 446 deletions(-) diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js index 1cc8846bbbdd3..8d8f125f39e55 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.js +++ b/tests/baselines/reference/keyofAndIndexedAccess.js @@ -21,11 +21,12 @@ class Options { } type Dictionary = { [x: string]: T }; +type NumericallyIndexed = { [x: number]: T }; const enum E { A, B, C } -type K00 = keyof any; // string | number -type K01 = keyof string; // number | "toString" | "charAt" | ... +type K00 = keyof any; // string +type K01 = keyof string; // "toString" | "charAt" | ... type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ... type K03 = keyof boolean; // "valueOf" type K04 = keyof void; // never @@ -34,19 +35,20 @@ type K06 = keyof null; // never type K07 = keyof never; // never type K10 = keyof Shape; // "name" | "width" | "height" | "visible" -type K11 = keyof Shape[]; // number | "length" | "toString" | ... -type K12 = keyof Dictionary; // string | number +type K11 = keyof Shape[]; // "length" | "toString" | ... +type K12 = keyof Dictionary; // string type K13 = keyof {}; // never type K14 = keyof Object; // "constructor" | "toString" | ... type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ... -type K16 = keyof [string, number]; // number | "0" | "1" | "length" | "toString" | ... +type K16 = keyof [string, number]; // "0" | "1" | "length" | "toString" | ... type K17 = keyof (Shape | Item); // "name" type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | "price" +type K19 = keyof NumericallyIndexed // never type KeyOf = keyof T; type K20 = KeyOf; // "name" | "width" | "height" | "visible" -type K21 = KeyOf>; // string | number +type K21 = KeyOf>; // string type NAME = "name"; type WIDTH_OR_HEIGHT = "width" | "height"; @@ -247,7 +249,8 @@ class OtherPerson { getParts() { return getProperty(this, "parts") } -} +} + //// [keyofAndIndexedAccess.js] var __extends = (this && this.__extends) || function (d, b) { @@ -449,6 +452,9 @@ declare class Options { declare type Dictionary = { [x: string]: T; }; +declare type NumericallyIndexed = { + [x: number]: T; +}; declare const enum E { A = 0, B = 1, @@ -471,6 +477,7 @@ declare type K15 = keyof E; declare type K16 = keyof [string, number]; declare type K17 = keyof (Shape | Item); declare type K18 = keyof (Shape & Item); +declare type K19 = keyof NumericallyIndexed; declare type KeyOf = keyof T; declare type K20 = KeyOf; declare type K21 = KeyOf>; diff --git a/tests/baselines/reference/keyofAndIndexedAccess.symbols b/tests/baselines/reference/keyofAndIndexedAccess.symbols index 634dfe09da9e9..2371bf419c854 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess.symbols @@ -47,792 +47,804 @@ type Dictionary = { [x: string]: T }; >x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 21, 24)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 21, 16)) +type NumericallyIndexed = { [x: number]: T }; +>NumericallyIndexed : Symbol(NumericallyIndexed, Decl(keyofAndIndexedAccess.ts, 21, 40)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 22, 24)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 22, 32)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 22, 24)) + const enum E { A, B, C } ->E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 21, 40)) ->A : Symbol(E.A, Decl(keyofAndIndexedAccess.ts, 23, 14)) ->B : Symbol(E.B, Decl(keyofAndIndexedAccess.ts, 23, 17)) ->C : Symbol(E.C, Decl(keyofAndIndexedAccess.ts, 23, 20)) +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 22, 48)) +>A : Symbol(E.A, Decl(keyofAndIndexedAccess.ts, 24, 14)) +>B : Symbol(E.B, Decl(keyofAndIndexedAccess.ts, 24, 17)) +>C : Symbol(E.C, Decl(keyofAndIndexedAccess.ts, 24, 20)) -type K00 = keyof any; // string | number ->K00 : Symbol(K00, Decl(keyofAndIndexedAccess.ts, 23, 24)) +type K00 = keyof any; // string +>K00 : Symbol(K00, Decl(keyofAndIndexedAccess.ts, 24, 24)) -type K01 = keyof string; // number | "toString" | "charAt" | ... ->K01 : Symbol(K01, Decl(keyofAndIndexedAccess.ts, 25, 21)) +type K01 = keyof string; // "toString" | "charAt" | ... +>K01 : Symbol(K01, Decl(keyofAndIndexedAccess.ts, 26, 21)) type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ... ->K02 : Symbol(K02, Decl(keyofAndIndexedAccess.ts, 26, 24)) +>K02 : Symbol(K02, Decl(keyofAndIndexedAccess.ts, 27, 24)) type K03 = keyof boolean; // "valueOf" ->K03 : Symbol(K03, Decl(keyofAndIndexedAccess.ts, 27, 24)) +>K03 : Symbol(K03, Decl(keyofAndIndexedAccess.ts, 28, 24)) type K04 = keyof void; // never ->K04 : Symbol(K04, Decl(keyofAndIndexedAccess.ts, 28, 25)) +>K04 : Symbol(K04, Decl(keyofAndIndexedAccess.ts, 29, 25)) type K05 = keyof undefined; // never ->K05 : Symbol(K05, Decl(keyofAndIndexedAccess.ts, 29, 22)) +>K05 : Symbol(K05, Decl(keyofAndIndexedAccess.ts, 30, 22)) type K06 = keyof null; // never ->K06 : Symbol(K06, Decl(keyofAndIndexedAccess.ts, 30, 27)) +>K06 : Symbol(K06, Decl(keyofAndIndexedAccess.ts, 31, 27)) type K07 = keyof never; // never ->K07 : Symbol(K07, Decl(keyofAndIndexedAccess.ts, 31, 22)) +>K07 : Symbol(K07, Decl(keyofAndIndexedAccess.ts, 32, 22)) type K10 = keyof Shape; // "name" | "width" | "height" | "visible" ->K10 : Symbol(K10, Decl(keyofAndIndexedAccess.ts, 32, 23)) +>K10 : Symbol(K10, Decl(keyofAndIndexedAccess.ts, 33, 23)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) -type K11 = keyof Shape[]; // number | "length" | "toString" | ... ->K11 : Symbol(K11, Decl(keyofAndIndexedAccess.ts, 34, 23)) +type K11 = keyof Shape[]; // "length" | "toString" | ... +>K11 : Symbol(K11, Decl(keyofAndIndexedAccess.ts, 35, 23)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) -type K12 = keyof Dictionary; // string | number ->K12 : Symbol(K12, Decl(keyofAndIndexedAccess.ts, 35, 25)) +type K12 = keyof Dictionary; // string +>K12 : Symbol(K12, Decl(keyofAndIndexedAccess.ts, 36, 25)) >Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 19, 1)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) type K13 = keyof {}; // never ->K13 : Symbol(K13, Decl(keyofAndIndexedAccess.ts, 36, 35)) +>K13 : Symbol(K13, Decl(keyofAndIndexedAccess.ts, 37, 35)) type K14 = keyof Object; // "constructor" | "toString" | ... ->K14 : Symbol(K14, Decl(keyofAndIndexedAccess.ts, 37, 20)) +>K14 : Symbol(K14, Decl(keyofAndIndexedAccess.ts, 38, 20)) >Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ... ->K15 : Symbol(K15, Decl(keyofAndIndexedAccess.ts, 38, 24)) ->E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 21, 40)) +>K15 : Symbol(K15, Decl(keyofAndIndexedAccess.ts, 39, 24)) +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 22, 48)) -type K16 = keyof [string, number]; // number | "0" | "1" | "length" | "toString" | ... ->K16 : Symbol(K16, Decl(keyofAndIndexedAccess.ts, 39, 19)) +type K16 = keyof [string, number]; // "0" | "1" | "length" | "toString" | ... +>K16 : Symbol(K16, Decl(keyofAndIndexedAccess.ts, 40, 19)) type K17 = keyof (Shape | Item); // "name" ->K17 : Symbol(K17, Decl(keyofAndIndexedAccess.ts, 40, 34)) +>K17 : Symbol(K17, Decl(keyofAndIndexedAccess.ts, 41, 34)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) >Item : Symbol(Item, Decl(keyofAndIndexedAccess.ts, 10, 1)) type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | "price" ->K18 : Symbol(K18, Decl(keyofAndIndexedAccess.ts, 41, 32)) +>K18 : Symbol(K18, Decl(keyofAndIndexedAccess.ts, 42, 32)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) >Item : Symbol(Item, Decl(keyofAndIndexedAccess.ts, 10, 1)) +type K19 = keyof NumericallyIndexed // never +>K19 : Symbol(K19, Decl(keyofAndIndexedAccess.ts, 43, 32)) +>NumericallyIndexed : Symbol(NumericallyIndexed, Decl(keyofAndIndexedAccess.ts, 21, 40)) +>Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) + type KeyOf = keyof T; ->KeyOf : Symbol(KeyOf, Decl(keyofAndIndexedAccess.ts, 42, 32)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 44, 11)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 44, 11)) +>KeyOf : Symbol(KeyOf, Decl(keyofAndIndexedAccess.ts, 44, 42)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 46, 11)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 46, 11)) type K20 = KeyOf; // "name" | "width" | "height" | "visible" ->K20 : Symbol(K20, Decl(keyofAndIndexedAccess.ts, 44, 24)) ->KeyOf : Symbol(KeyOf, Decl(keyofAndIndexedAccess.ts, 42, 32)) +>K20 : Symbol(K20, Decl(keyofAndIndexedAccess.ts, 46, 24)) +>KeyOf : Symbol(KeyOf, Decl(keyofAndIndexedAccess.ts, 44, 42)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) -type K21 = KeyOf>; // string | number ->K21 : Symbol(K21, Decl(keyofAndIndexedAccess.ts, 46, 24)) ->KeyOf : Symbol(KeyOf, Decl(keyofAndIndexedAccess.ts, 42, 32)) +type K21 = KeyOf>; // string +>K21 : Symbol(K21, Decl(keyofAndIndexedAccess.ts, 48, 24)) +>KeyOf : Symbol(KeyOf, Decl(keyofAndIndexedAccess.ts, 44, 42)) >Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 19, 1)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) type NAME = "name"; ->NAME : Symbol(NAME, Decl(keyofAndIndexedAccess.ts, 47, 36)) +>NAME : Symbol(NAME, Decl(keyofAndIndexedAccess.ts, 49, 36)) type WIDTH_OR_HEIGHT = "width" | "height"; ->WIDTH_OR_HEIGHT : Symbol(WIDTH_OR_HEIGHT, Decl(keyofAndIndexedAccess.ts, 49, 19)) +>WIDTH_OR_HEIGHT : Symbol(WIDTH_OR_HEIGHT, Decl(keyofAndIndexedAccess.ts, 51, 19)) type Q10 = Shape["name"]; // string ->Q10 : Symbol(Q10, Decl(keyofAndIndexedAccess.ts, 50, 42)) +>Q10 : Symbol(Q10, Decl(keyofAndIndexedAccess.ts, 52, 42)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) type Q11 = Shape["width" | "height"]; // number ->Q11 : Symbol(Q11, Decl(keyofAndIndexedAccess.ts, 52, 25)) +>Q11 : Symbol(Q11, Decl(keyofAndIndexedAccess.ts, 54, 25)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) type Q12 = Shape["name" | "visible"]; // string | boolean ->Q12 : Symbol(Q12, Decl(keyofAndIndexedAccess.ts, 53, 37)) +>Q12 : Symbol(Q12, Decl(keyofAndIndexedAccess.ts, 55, 37)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) type Q20 = Shape[NAME]; // string ->Q20 : Symbol(Q20, Decl(keyofAndIndexedAccess.ts, 54, 37)) +>Q20 : Symbol(Q20, Decl(keyofAndIndexedAccess.ts, 56, 37)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) ->NAME : Symbol(NAME, Decl(keyofAndIndexedAccess.ts, 47, 36)) +>NAME : Symbol(NAME, Decl(keyofAndIndexedAccess.ts, 49, 36)) type Q21 = Shape[WIDTH_OR_HEIGHT]; // number ->Q21 : Symbol(Q21, Decl(keyofAndIndexedAccess.ts, 56, 23)) +>Q21 : Symbol(Q21, Decl(keyofAndIndexedAccess.ts, 58, 23)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) ->WIDTH_OR_HEIGHT : Symbol(WIDTH_OR_HEIGHT, Decl(keyofAndIndexedAccess.ts, 49, 19)) +>WIDTH_OR_HEIGHT : Symbol(WIDTH_OR_HEIGHT, Decl(keyofAndIndexedAccess.ts, 51, 19)) type Q30 = [string, number][0]; // string ->Q30 : Symbol(Q30, Decl(keyofAndIndexedAccess.ts, 57, 34)) +>Q30 : Symbol(Q30, Decl(keyofAndIndexedAccess.ts, 59, 34)) type Q31 = [string, number][1]; // number ->Q31 : Symbol(Q31, Decl(keyofAndIndexedAccess.ts, 59, 31)) +>Q31 : Symbol(Q31, Decl(keyofAndIndexedAccess.ts, 61, 31)) type Q32 = [string, number][2]; // string | number ->Q32 : Symbol(Q32, Decl(keyofAndIndexedAccess.ts, 60, 31)) +>Q32 : Symbol(Q32, Decl(keyofAndIndexedAccess.ts, 62, 31)) type Q33 = [string, number][E.A]; // string ->Q33 : Symbol(Q33, Decl(keyofAndIndexedAccess.ts, 61, 31)) ->E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 21, 40)) ->A : Symbol(E.A, Decl(keyofAndIndexedAccess.ts, 23, 14)) +>Q33 : Symbol(Q33, Decl(keyofAndIndexedAccess.ts, 63, 31)) +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 22, 48)) +>A : Symbol(E.A, Decl(keyofAndIndexedAccess.ts, 24, 14)) type Q34 = [string, number][E.B]; // number ->Q34 : Symbol(Q34, Decl(keyofAndIndexedAccess.ts, 62, 33)) ->E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 21, 40)) ->B : Symbol(E.B, Decl(keyofAndIndexedAccess.ts, 23, 17)) +>Q34 : Symbol(Q34, Decl(keyofAndIndexedAccess.ts, 64, 33)) +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 22, 48)) +>B : Symbol(E.B, Decl(keyofAndIndexedAccess.ts, 24, 17)) type Q35 = [string, number][E.C]; // string | number ->Q35 : Symbol(Q35, Decl(keyofAndIndexedAccess.ts, 63, 33)) ->E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 21, 40)) ->C : Symbol(E.C, Decl(keyofAndIndexedAccess.ts, 23, 20)) +>Q35 : Symbol(Q35, Decl(keyofAndIndexedAccess.ts, 65, 33)) +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 22, 48)) +>C : Symbol(E.C, Decl(keyofAndIndexedAccess.ts, 24, 20)) type Q36 = [string, number]["0"]; // string ->Q36 : Symbol(Q36, Decl(keyofAndIndexedAccess.ts, 64, 33)) +>Q36 : Symbol(Q36, Decl(keyofAndIndexedAccess.ts, 66, 33)) type Q37 = [string, number]["1"]; // string ->Q37 : Symbol(Q37, Decl(keyofAndIndexedAccess.ts, 65, 33)) +>Q37 : Symbol(Q37, Decl(keyofAndIndexedAccess.ts, 67, 33)) type Q40 = (Shape | Options)["visible"]; // boolean | "yes" | "no" ->Q40 : Symbol(Q40, Decl(keyofAndIndexedAccess.ts, 66, 33)) +>Q40 : Symbol(Q40, Decl(keyofAndIndexedAccess.ts, 68, 33)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) >Options : Symbol(Options, Decl(keyofAndIndexedAccess.ts, 15, 1)) type Q41 = (Shape & Options)["visible"]; // true & "yes" | true & "no" | false & "yes" | false & "no" ->Q41 : Symbol(Q41, Decl(keyofAndIndexedAccess.ts, 68, 40)) +>Q41 : Symbol(Q41, Decl(keyofAndIndexedAccess.ts, 70, 40)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) >Options : Symbol(Options, Decl(keyofAndIndexedAccess.ts, 15, 1)) type Q50 = Dictionary["howdy"]; // Shape ->Q50 : Symbol(Q50, Decl(keyofAndIndexedAccess.ts, 69, 40)) +>Q50 : Symbol(Q50, Decl(keyofAndIndexedAccess.ts, 71, 40)) >Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 19, 1)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) type Q51 = Dictionary[123]; // Shape ->Q51 : Symbol(Q51, Decl(keyofAndIndexedAccess.ts, 71, 38)) +>Q51 : Symbol(Q51, Decl(keyofAndIndexedAccess.ts, 73, 38)) >Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 19, 1)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) type Q52 = Dictionary[E.B]; // Shape ->Q52 : Symbol(Q52, Decl(keyofAndIndexedAccess.ts, 72, 34)) +>Q52 : Symbol(Q52, Decl(keyofAndIndexedAccess.ts, 74, 34)) >Dictionary : Symbol(Dictionary, Decl(keyofAndIndexedAccess.ts, 19, 1)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) ->E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 21, 40)) ->B : Symbol(E.B, Decl(keyofAndIndexedAccess.ts, 23, 17)) +>E : Symbol(E, Decl(keyofAndIndexedAccess.ts, 22, 48)) +>B : Symbol(E.B, Decl(keyofAndIndexedAccess.ts, 24, 17)) declare let cond: boolean; ->cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 77, 11)) function getProperty(obj: T, key: K) { ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 77, 21)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 77, 23)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 77, 21)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 77, 43)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 77, 21)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 77, 50)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 77, 23)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 79, 21)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 79, 23)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 79, 21)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 79, 43)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 79, 21)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 79, 50)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 79, 23)) return obj[key]; ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 77, 43)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 77, 50)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 79, 43)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 79, 50)) } function setProperty(obj: T, key: K, value: T[K]) { ->setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 81, 21)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 81, 23)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 81, 21)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 81, 43)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 81, 21)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 81, 50)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 81, 23)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 81, 58)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 81, 21)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 81, 23)) +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 81, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 83, 21)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 83, 23)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 83, 21)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 83, 43)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 83, 21)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 83, 50)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 83, 23)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 83, 58)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 83, 21)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 83, 23)) obj[key] = value; ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 81, 43)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 81, 50)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 81, 58)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 83, 43)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 83, 50)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 83, 58)) } function f10(shape: Shape) { ->f10 : Symbol(f10, Decl(keyofAndIndexedAccess.ts, 83, 1)) ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 85, 13)) +>f10 : Symbol(f10, Decl(keyofAndIndexedAccess.ts, 85, 1)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 87, 13)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) let name = getProperty(shape, "name"); // string ->name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 86, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 85, 13)) +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 88, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 87, 13)) let widthOrHeight = getProperty(shape, cond ? "width" : "height"); // number ->widthOrHeight : Symbol(widthOrHeight, Decl(keyofAndIndexedAccess.ts, 87, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 85, 13)) ->cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) +>widthOrHeight : Symbol(widthOrHeight, Decl(keyofAndIndexedAccess.ts, 89, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 87, 13)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 77, 11)) let nameOrVisible = getProperty(shape, cond ? "name" : "visible"); // string | boolean ->nameOrVisible : Symbol(nameOrVisible, Decl(keyofAndIndexedAccess.ts, 88, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 85, 13)) ->cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) +>nameOrVisible : Symbol(nameOrVisible, Decl(keyofAndIndexedAccess.ts, 90, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 87, 13)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 77, 11)) setProperty(shape, "name", "rectangle"); ->setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 85, 13)) +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 81, 1)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 87, 13)) setProperty(shape, cond ? "width" : "height", 10); ->setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 85, 13)) ->cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 81, 1)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 87, 13)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 77, 11)) setProperty(shape, cond ? "name" : "visible", true); // Technically not safe ->setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 85, 13)) ->cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 81, 1)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 87, 13)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 77, 11)) } function f11(a: Shape[]) { ->f11 : Symbol(f11, Decl(keyofAndIndexedAccess.ts, 92, 1)) ->a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 94, 13)) +>f11 : Symbol(f11, Decl(keyofAndIndexedAccess.ts, 94, 1)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 96, 13)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) let len = getProperty(a, "length"); // number ->len : Symbol(len, Decl(keyofAndIndexedAccess.ts, 95, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 94, 13)) +>len : Symbol(len, Decl(keyofAndIndexedAccess.ts, 97, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 96, 13)) setProperty(a, "length", len); ->setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) ->a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 94, 13)) ->len : Symbol(len, Decl(keyofAndIndexedAccess.ts, 95, 7)) +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 81, 1)) +>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 96, 13)) +>len : Symbol(len, Decl(keyofAndIndexedAccess.ts, 97, 7)) } function f12(t: [Shape, boolean]) { ->f12 : Symbol(f12, Decl(keyofAndIndexedAccess.ts, 97, 1)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 99, 13)) +>f12 : Symbol(f12, Decl(keyofAndIndexedAccess.ts, 99, 1)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 101, 13)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) let len = getProperty(t, "length"); ->len : Symbol(len, Decl(keyofAndIndexedAccess.ts, 100, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 99, 13)) +>len : Symbol(len, Decl(keyofAndIndexedAccess.ts, 102, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 101, 13)) let s2 = getProperty(t, "0"); // Shape ->s2 : Symbol(s2, Decl(keyofAndIndexedAccess.ts, 101, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 99, 13)) +>s2 : Symbol(s2, Decl(keyofAndIndexedAccess.ts, 103, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 101, 13)) let b2 = getProperty(t, "1"); // boolean ->b2 : Symbol(b2, Decl(keyofAndIndexedAccess.ts, 102, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 99, 13)) +>b2 : Symbol(b2, Decl(keyofAndIndexedAccess.ts, 104, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 101, 13)) } function f13(foo: any, bar: any) { ->f13 : Symbol(f13, Decl(keyofAndIndexedAccess.ts, 103, 1)) ->foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 105, 13)) ->bar : Symbol(bar, Decl(keyofAndIndexedAccess.ts, 105, 22)) +>f13 : Symbol(f13, Decl(keyofAndIndexedAccess.ts, 105, 1)) +>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 107, 13)) +>bar : Symbol(bar, Decl(keyofAndIndexedAccess.ts, 107, 22)) let x = getProperty(foo, "x"); // any ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 106, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 105, 13)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 108, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) +>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 107, 13)) let y = getProperty(foo, "100"); // any ->y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 107, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 105, 13)) +>y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 109, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) +>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 107, 13)) let z = getProperty(foo, bar); // any ->z : Symbol(z, Decl(keyofAndIndexedAccess.ts, 108, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 105, 13)) ->bar : Symbol(bar, Decl(keyofAndIndexedAccess.ts, 105, 22)) +>z : Symbol(z, Decl(keyofAndIndexedAccess.ts, 110, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) +>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 107, 13)) +>bar : Symbol(bar, Decl(keyofAndIndexedAccess.ts, 107, 22)) } class Component { ->Component : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 109, 1)) ->PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 111, 16)) +>Component : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 111, 1)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 113, 16)) props: PropType; ->props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 111, 27)) ->PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 111, 16)) +>props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 113, 27)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 113, 16)) getProperty(key: K) { ->getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 113, 16)) ->PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 111, 16)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 113, 42)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 113, 16)) +>getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 114, 20)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 115, 16)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 113, 16)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 115, 42)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 115, 16)) return this.props[key]; ->this.props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 111, 27)) ->this : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 109, 1)) ->props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 111, 27)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 113, 42)) +>this.props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 113, 27)) +>this : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 111, 1)) +>props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 113, 27)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 115, 42)) } setProperty(key: K, value: PropType[K]) { ->setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 116, 16)) ->PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 111, 16)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 116, 42)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 116, 16)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 116, 49)) ->PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 111, 16)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 116, 16)) +>setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 117, 5)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 118, 16)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 113, 16)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 118, 42)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 118, 16)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 118, 49)) +>PropType : Symbol(PropType, Decl(keyofAndIndexedAccess.ts, 113, 16)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 118, 16)) this.props[key] = value; ->this.props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 111, 27)) ->this : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 109, 1)) ->props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 111, 27)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 116, 42)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 116, 49)) +>this.props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 113, 27)) +>this : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 111, 1)) +>props : Symbol(Component.props, Decl(keyofAndIndexedAccess.ts, 113, 27)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 118, 42)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 118, 49)) } } function f20(component: Component) { ->f20 : Symbol(f20, Decl(keyofAndIndexedAccess.ts, 119, 1)) ->component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) ->Component : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 109, 1)) +>f20 : Symbol(f20, Decl(keyofAndIndexedAccess.ts, 121, 1)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 123, 13)) +>Component : Symbol(Component, Decl(keyofAndIndexedAccess.ts, 111, 1)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) let name = component.getProperty("name"); // string ->name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 122, 7)) ->component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) ->component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) ->getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 124, 7)) +>component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 114, 20)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 123, 13)) +>getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 114, 20)) let widthOrHeight = component.getProperty(cond ? "width" : "height"); // number ->widthOrHeight : Symbol(widthOrHeight, Decl(keyofAndIndexedAccess.ts, 123, 7)) ->component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) ->component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) ->getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) ->cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) +>widthOrHeight : Symbol(widthOrHeight, Decl(keyofAndIndexedAccess.ts, 125, 7)) +>component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 114, 20)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 123, 13)) +>getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 114, 20)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 77, 11)) let nameOrVisible = component.getProperty(cond ? "name" : "visible"); // string | boolean ->nameOrVisible : Symbol(nameOrVisible, Decl(keyofAndIndexedAccess.ts, 124, 7)) ->component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) ->component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) ->getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 112, 20)) ->cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) +>nameOrVisible : Symbol(nameOrVisible, Decl(keyofAndIndexedAccess.ts, 126, 7)) +>component.getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 114, 20)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 123, 13)) +>getProperty : Symbol(Component.getProperty, Decl(keyofAndIndexedAccess.ts, 114, 20)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 77, 11)) component.setProperty("name", "rectangle"); ->component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) ->component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) ->setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) +>component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 117, 5)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 123, 13)) +>setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 117, 5)) component.setProperty(cond ? "width" : "height", 10) ->component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) ->component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) ->setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) ->cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) +>component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 117, 5)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 123, 13)) +>setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 117, 5)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 77, 11)) component.setProperty(cond ? "name" : "visible", true); // Technically not safe ->component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) ->component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 121, 13)) ->setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 115, 5)) ->cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) +>component.setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 117, 5)) +>component : Symbol(component, Decl(keyofAndIndexedAccess.ts, 123, 13)) +>setProperty : Symbol(Component.setProperty, Decl(keyofAndIndexedAccess.ts, 117, 5)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 77, 11)) } function pluck(array: T[], key: K) { ->pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 128, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 130, 15)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 130, 17)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 130, 15)) ->array : Symbol(array, Decl(keyofAndIndexedAccess.ts, 130, 37)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 130, 15)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 130, 48)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 130, 17)) +>pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 130, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 132, 15)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 132, 17)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 132, 15)) +>array : Symbol(array, Decl(keyofAndIndexedAccess.ts, 132, 37)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 132, 15)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 132, 48)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 132, 17)) return array.map(x => x[key]); >array.map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->array : Symbol(array, Decl(keyofAndIndexedAccess.ts, 130, 37)) +>array : Symbol(array, Decl(keyofAndIndexedAccess.ts, 132, 37)) >map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 131, 21)) ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 131, 21)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 130, 48)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 133, 21)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 133, 21)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 132, 48)) } function f30(shapes: Shape[]) { ->f30 : Symbol(f30, Decl(keyofAndIndexedAccess.ts, 132, 1)) ->shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 134, 13)) +>f30 : Symbol(f30, Decl(keyofAndIndexedAccess.ts, 134, 1)) +>shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 136, 13)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) let names = pluck(shapes, "name"); // string[] ->names : Symbol(names, Decl(keyofAndIndexedAccess.ts, 135, 7)) ->pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 128, 1)) ->shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 134, 13)) +>names : Symbol(names, Decl(keyofAndIndexedAccess.ts, 137, 7)) +>pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 130, 1)) +>shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 136, 13)) let widths = pluck(shapes, "width"); // number[] ->widths : Symbol(widths, Decl(keyofAndIndexedAccess.ts, 136, 7)) ->pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 128, 1)) ->shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 134, 13)) +>widths : Symbol(widths, Decl(keyofAndIndexedAccess.ts, 138, 7)) +>pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 130, 1)) +>shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 136, 13)) let nameOrVisibles = pluck(shapes, cond ? "name" : "visible"); // (string | boolean)[] ->nameOrVisibles : Symbol(nameOrVisibles, Decl(keyofAndIndexedAccess.ts, 137, 7)) ->pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 128, 1)) ->shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 134, 13)) ->cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 75, 11)) +>nameOrVisibles : Symbol(nameOrVisibles, Decl(keyofAndIndexedAccess.ts, 139, 7)) +>pluck : Symbol(pluck, Decl(keyofAndIndexedAccess.ts, 130, 1)) +>shapes : Symbol(shapes, Decl(keyofAndIndexedAccess.ts, 136, 13)) +>cond : Symbol(cond, Decl(keyofAndIndexedAccess.ts, 77, 11)) } function f31(key: K) { ->f31 : Symbol(f31, Decl(keyofAndIndexedAccess.ts, 138, 1)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 140, 13)) +>f31 : Symbol(f31, Decl(keyofAndIndexedAccess.ts, 140, 1)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 142, 13)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 140, 36)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 140, 13)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 142, 36)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 142, 13)) const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 141, 9)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 143, 9)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) ->name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 141, 26)) ->width : Symbol(width, Decl(keyofAndIndexedAccess.ts, 141, 39)) ->height : Symbol(height, Decl(keyofAndIndexedAccess.ts, 141, 49)) ->visible : Symbol(visible, Decl(keyofAndIndexedAccess.ts, 141, 61)) +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 143, 26)) +>width : Symbol(width, Decl(keyofAndIndexedAccess.ts, 143, 39)) +>height : Symbol(height, Decl(keyofAndIndexedAccess.ts, 143, 49)) +>visible : Symbol(visible, Decl(keyofAndIndexedAccess.ts, 143, 61)) return shape[key]; // Shape[K] ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 141, 9)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 140, 36)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 143, 9)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 142, 36)) } function f32(key: K) { ->f32 : Symbol(f32, Decl(keyofAndIndexedAccess.ts, 143, 1)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 145, 13)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 145, 43)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 145, 13)) +>f32 : Symbol(f32, Decl(keyofAndIndexedAccess.ts, 145, 1)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 147, 13)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 147, 43)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 147, 13)) const shape: Shape = { name: "foo", width: 5, height: 10, visible: true }; ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 146, 9)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 148, 9)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) ->name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 146, 26)) ->width : Symbol(width, Decl(keyofAndIndexedAccess.ts, 146, 39)) ->height : Symbol(height, Decl(keyofAndIndexedAccess.ts, 146, 49)) ->visible : Symbol(visible, Decl(keyofAndIndexedAccess.ts, 146, 61)) +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 148, 26)) +>width : Symbol(width, Decl(keyofAndIndexedAccess.ts, 148, 39)) +>height : Symbol(height, Decl(keyofAndIndexedAccess.ts, 148, 49)) +>visible : Symbol(visible, Decl(keyofAndIndexedAccess.ts, 148, 61)) return shape[key]; // Shape[K] ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 146, 9)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 145, 43)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 148, 9)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 147, 43)) } function f33(shape: S, key: K) { ->f33 : Symbol(f33, Decl(keyofAndIndexedAccess.ts, 148, 1)) ->S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 150, 13)) +>f33 : Symbol(f33, Decl(keyofAndIndexedAccess.ts, 150, 1)) +>S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 152, 13)) >Shape : Symbol(Shape, Decl(keyofAndIndexedAccess.ts, 0, 0)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 150, 29)) ->S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 150, 13)) ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 150, 49)) ->S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 150, 13)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 150, 58)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 150, 29)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 152, 29)) +>S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 152, 13)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 152, 49)) +>S : Symbol(S, Decl(keyofAndIndexedAccess.ts, 152, 13)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 152, 58)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 152, 29)) let name = getProperty(shape, "name"); ->name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 151, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 150, 49)) +>name : Symbol(name, Decl(keyofAndIndexedAccess.ts, 153, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 152, 49)) let prop = getProperty(shape, key); ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 152, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 150, 49)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 150, 58)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 154, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) +>shape : Symbol(shape, Decl(keyofAndIndexedAccess.ts, 152, 49)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 152, 58)) return prop; ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 152, 7)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 154, 7)) } function f34(ts: TaggedShape) { ->f34 : Symbol(f34, Decl(keyofAndIndexedAccess.ts, 154, 1)) ->ts : Symbol(ts, Decl(keyofAndIndexedAccess.ts, 156, 13)) +>f34 : Symbol(f34, Decl(keyofAndIndexedAccess.ts, 156, 1)) +>ts : Symbol(ts, Decl(keyofAndIndexedAccess.ts, 158, 13)) >TaggedShape : Symbol(TaggedShape, Decl(keyofAndIndexedAccess.ts, 6, 1)) let tag1 = f33(ts, "tag"); ->tag1 : Symbol(tag1, Decl(keyofAndIndexedAccess.ts, 157, 7)) ->f33 : Symbol(f33, Decl(keyofAndIndexedAccess.ts, 148, 1)) ->ts : Symbol(ts, Decl(keyofAndIndexedAccess.ts, 156, 13)) +>tag1 : Symbol(tag1, Decl(keyofAndIndexedAccess.ts, 159, 7)) +>f33 : Symbol(f33, Decl(keyofAndIndexedAccess.ts, 150, 1)) +>ts : Symbol(ts, Decl(keyofAndIndexedAccess.ts, 158, 13)) let tag2 = getProperty(ts, "tag"); ->tag2 : Symbol(tag2, Decl(keyofAndIndexedAccess.ts, 158, 7)) ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->ts : Symbol(ts, Decl(keyofAndIndexedAccess.ts, 156, 13)) +>tag2 : Symbol(tag2, Decl(keyofAndIndexedAccess.ts, 160, 7)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) +>ts : Symbol(ts, Decl(keyofAndIndexedAccess.ts, 158, 13)) } class C { ->C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 159, 1)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 161, 1)) public x: string; ->x : Symbol(C.x, Decl(keyofAndIndexedAccess.ts, 161, 9)) +>x : Symbol(C.x, Decl(keyofAndIndexedAccess.ts, 163, 9)) protected y: string; ->y : Symbol(C.y, Decl(keyofAndIndexedAccess.ts, 162, 21)) +>y : Symbol(C.y, Decl(keyofAndIndexedAccess.ts, 164, 21)) private z: string; ->z : Symbol(C.z, Decl(keyofAndIndexedAccess.ts, 163, 24)) +>z : Symbol(C.z, Decl(keyofAndIndexedAccess.ts, 165, 24)) } // Indexed access expressions have always permitted access to private and protected members. // For consistency we also permit such access in indexed access types. function f40(c: C) { ->f40 : Symbol(f40, Decl(keyofAndIndexedAccess.ts, 165, 1)) ->c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 169, 13)) ->C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 159, 1)) +>f40 : Symbol(f40, Decl(keyofAndIndexedAccess.ts, 167, 1)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 171, 13)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 161, 1)) type X = C["x"]; ->X : Symbol(X, Decl(keyofAndIndexedAccess.ts, 169, 20)) ->C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 159, 1)) +>X : Symbol(X, Decl(keyofAndIndexedAccess.ts, 171, 20)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 161, 1)) type Y = C["y"]; ->Y : Symbol(Y, Decl(keyofAndIndexedAccess.ts, 170, 20)) ->C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 159, 1)) +>Y : Symbol(Y, Decl(keyofAndIndexedAccess.ts, 172, 20)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 161, 1)) type Z = C["z"]; ->Z : Symbol(Z, Decl(keyofAndIndexedAccess.ts, 171, 20)) ->C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 159, 1)) +>Z : Symbol(Z, Decl(keyofAndIndexedAccess.ts, 173, 20)) +>C : Symbol(C, Decl(keyofAndIndexedAccess.ts, 161, 1)) let x: X = c["x"]; ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 173, 7)) ->X : Symbol(X, Decl(keyofAndIndexedAccess.ts, 169, 20)) ->c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 169, 13)) ->"x" : Symbol(C.x, Decl(keyofAndIndexedAccess.ts, 161, 9)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 175, 7)) +>X : Symbol(X, Decl(keyofAndIndexedAccess.ts, 171, 20)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 171, 13)) +>"x" : Symbol(C.x, Decl(keyofAndIndexedAccess.ts, 163, 9)) let y: Y = c["y"]; ->y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 174, 7)) ->Y : Symbol(Y, Decl(keyofAndIndexedAccess.ts, 170, 20)) ->c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 169, 13)) ->"y" : Symbol(C.y, Decl(keyofAndIndexedAccess.ts, 162, 21)) +>y : Symbol(y, Decl(keyofAndIndexedAccess.ts, 176, 7)) +>Y : Symbol(Y, Decl(keyofAndIndexedAccess.ts, 172, 20)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 171, 13)) +>"y" : Symbol(C.y, Decl(keyofAndIndexedAccess.ts, 164, 21)) let z: Z = c["z"]; ->z : Symbol(z, Decl(keyofAndIndexedAccess.ts, 175, 7)) ->Z : Symbol(Z, Decl(keyofAndIndexedAccess.ts, 171, 20)) ->c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 169, 13)) ->"z" : Symbol(C.z, Decl(keyofAndIndexedAccess.ts, 163, 24)) +>z : Symbol(z, Decl(keyofAndIndexedAccess.ts, 177, 7)) +>Z : Symbol(Z, Decl(keyofAndIndexedAccess.ts, 173, 20)) +>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 171, 13)) +>"z" : Symbol(C.z, Decl(keyofAndIndexedAccess.ts, 165, 24)) } function f50(k: keyof T, s: string) { ->f50 : Symbol(f50, Decl(keyofAndIndexedAccess.ts, 176, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 178, 13)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 178, 16)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 178, 13)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 178, 27)) +>f50 : Symbol(f50, Decl(keyofAndIndexedAccess.ts, 178, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 180, 13)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 180, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 180, 13)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 180, 27)) const x1 = s as keyof T; ->x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 179, 9)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 178, 27)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 178, 13)) +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 181, 9)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 180, 27)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 180, 13)) const x2 = k as string; ->x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 180, 9)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 178, 16)) +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 182, 9)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 180, 16)) } function f51(k: K, s: string) { ->f51 : Symbol(f51, Decl(keyofAndIndexedAccess.ts, 181, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 183, 13)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 183, 15)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 183, 13)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 183, 35)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 183, 15)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 183, 40)) +>f51 : Symbol(f51, Decl(keyofAndIndexedAccess.ts, 183, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 185, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 185, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 185, 13)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 185, 35)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 185, 15)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 185, 40)) const x1 = s as keyof T; ->x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 184, 9)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 183, 40)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 183, 13)) +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 186, 9)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 185, 40)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 185, 13)) const x2 = k as string; ->x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 185, 9)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 183, 35)) +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 187, 9)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 185, 35)) } function f52(obj: { [x: string]: boolean }, k: keyof T, s: string, n: number) { ->f52 : Symbol(f52, Decl(keyofAndIndexedAccess.ts, 186, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 188, 13)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 188, 16)) ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 188, 24)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 188, 46)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 188, 13)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 188, 58)) ->n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 188, 69)) +>f52 : Symbol(f52, Decl(keyofAndIndexedAccess.ts, 188, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 190, 13)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 190, 16)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 190, 24)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 190, 46)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 190, 13)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 190, 58)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 190, 69)) const x1 = obj[s]; ->x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 189, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 188, 16)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 188, 58)) +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 191, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 190, 16)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 190, 58)) const x2 = obj[n]; ->x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 190, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 188, 16)) ->n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 188, 69)) +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 192, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 190, 16)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 190, 69)) const x3 = obj[k]; ->x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 191, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 188, 16)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 188, 46)) +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 193, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 190, 16)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 190, 46)) } function f53(obj: { [x: string]: boolean }, k: K, s: string, n: number) { ->f53 : Symbol(f53, Decl(keyofAndIndexedAccess.ts, 192, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 194, 13)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 194, 15)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 194, 13)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 194, 35)) ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 194, 43)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 194, 65)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 194, 15)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 194, 71)) ->n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 194, 82)) +>f53 : Symbol(f53, Decl(keyofAndIndexedAccess.ts, 194, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 196, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 196, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 196, 13)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 196, 35)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 196, 43)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 196, 65)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 196, 15)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 196, 71)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 196, 82)) const x1 = obj[s]; ->x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 195, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 194, 35)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 194, 71)) +>x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 197, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 196, 35)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 196, 71)) const x2 = obj[n]; ->x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 196, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 194, 35)) ->n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 194, 82)) +>x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 198, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 196, 35)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 196, 82)) const x3 = obj[k]; ->x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 197, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 194, 35)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 194, 65)) +>x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 199, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 196, 35)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 196, 65)) } function f54(obj: T, key: keyof T) { ->f54 : Symbol(f54, Decl(keyofAndIndexedAccess.ts, 198, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 200, 13)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 200, 16)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 200, 13)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 200, 23)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 200, 13)) +>f54 : Symbol(f54, Decl(keyofAndIndexedAccess.ts, 200, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 202, 13)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 202, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 202, 13)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 202, 23)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 202, 13)) for (let s in obj[key]) { ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 201, 12)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 200, 16)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 200, 23)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 203, 12)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 202, 16)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 202, 23)) } const b = "foo" in obj[key]; ->b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 203, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 200, 16)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 200, 23)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 205, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 202, 16)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 202, 23)) } function f55(obj: T, key: K) { ->f55 : Symbol(f55, Decl(keyofAndIndexedAccess.ts, 204, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 206, 13)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 206, 15)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 206, 13)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 206, 35)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 206, 13)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 206, 42)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 206, 15)) +>f55 : Symbol(f55, Decl(keyofAndIndexedAccess.ts, 206, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 208, 13)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 208, 15)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 208, 13)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 208, 35)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 208, 13)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 208, 42)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 208, 15)) for (let s in obj[key]) { ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 207, 12)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 206, 35)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 206, 42)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 209, 12)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 208, 35)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 208, 42)) } const b = "foo" in obj[key]; ->b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 209, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 206, 35)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 206, 42)) +>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 211, 9)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 208, 35)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 208, 42)) } function f60(source: T, target: T) { ->f60 : Symbol(f60, Decl(keyofAndIndexedAccess.ts, 210, 1)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 212, 13)) ->source : Symbol(source, Decl(keyofAndIndexedAccess.ts, 212, 16)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 212, 13)) ->target : Symbol(target, Decl(keyofAndIndexedAccess.ts, 212, 26)) ->T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 212, 13)) +>f60 : Symbol(f60, Decl(keyofAndIndexedAccess.ts, 212, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 214, 13)) +>source : Symbol(source, Decl(keyofAndIndexedAccess.ts, 214, 16)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 214, 13)) +>target : Symbol(target, Decl(keyofAndIndexedAccess.ts, 214, 26)) +>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 214, 13)) for (let k in source) { ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 213, 12)) ->source : Symbol(source, Decl(keyofAndIndexedAccess.ts, 212, 16)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 215, 12)) +>source : Symbol(source, Decl(keyofAndIndexedAccess.ts, 214, 16)) target[k] = source[k]; ->target : Symbol(target, Decl(keyofAndIndexedAccess.ts, 212, 26)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 213, 12)) ->source : Symbol(source, Decl(keyofAndIndexedAccess.ts, 212, 16)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 213, 12)) +>target : Symbol(target, Decl(keyofAndIndexedAccess.ts, 214, 26)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 215, 12)) +>source : Symbol(source, Decl(keyofAndIndexedAccess.ts, 214, 16)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 215, 12)) } } // Repros from #12011 class Base { ->Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1)) +>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 218, 1)) get(prop: K) { ->get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 220, 12)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 221, 8)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 221, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 221, 8)) +>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 222, 12)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 223, 8)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 223, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 223, 8)) return this[prop]; ->this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 221, 30)) +>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 218, 1)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 223, 30)) } set(prop: K, value: this[K]) { ->set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 223, 5)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 224, 8)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 224, 30)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 224, 8)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 224, 38)) ->K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 224, 8)) +>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 225, 5)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 226, 8)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 226, 30)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 226, 8)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 226, 38)) +>K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 226, 8)) this[prop] = value; ->this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1)) ->prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 224, 30)) ->value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 224, 38)) +>this : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 218, 1)) +>prop : Symbol(prop, Decl(keyofAndIndexedAccess.ts, 226, 30)) +>value : Symbol(value, Decl(keyofAndIndexedAccess.ts, 226, 38)) } } class Person extends Base { ->Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 227, 1)) ->Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1)) +>Person : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 229, 1)) +>Base : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 218, 1)) parts: number; ->parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 229, 27)) +>parts : Symbol(Person.parts, Decl(keyofAndIndexedAccess.ts, 231, 27)) constructor(parts: number) { ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 231, 16)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 233, 16)) super(); ->super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 216, 1)) +>super : Symbol(Base, Decl(keyofAndIndexedAccess.ts, 218, 1)) this.set("parts", parts); ->this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 223, 5)) ->this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 227, 1)) ->set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 223, 5)) ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 231, 16)) +>this.set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 225, 5)) +>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 229, 1)) +>set : Symbol(Base.set, Decl(keyofAndIndexedAccess.ts, 225, 5)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 233, 16)) } getParts() { ->getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 234, 5)) +>getParts : Symbol(Person.getParts, Decl(keyofAndIndexedAccess.ts, 236, 5)) return this.get("parts") ->this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 220, 12)) ->this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 227, 1)) ->get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 220, 12)) +>this.get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 222, 12)) +>this : Symbol(Person, Decl(keyofAndIndexedAccess.ts, 229, 1)) +>get : Symbol(Base.get, Decl(keyofAndIndexedAccess.ts, 222, 12)) } } class OtherPerson { ->OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 238, 1)) +>OtherPerson : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 240, 1)) parts: number; ->parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 240, 19)) +>parts : Symbol(OtherPerson.parts, Decl(keyofAndIndexedAccess.ts, 242, 19)) constructor(parts: number) { ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 242, 16)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 244, 16)) setProperty(this, "parts", parts); ->setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 79, 1)) ->this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 238, 1)) ->parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 242, 16)) +>setProperty : Symbol(setProperty, Decl(keyofAndIndexedAccess.ts, 81, 1)) +>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 240, 1)) +>parts : Symbol(parts, Decl(keyofAndIndexedAccess.ts, 244, 16)) } getParts() { ->getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 244, 5)) +>getParts : Symbol(OtherPerson.getParts, Decl(keyofAndIndexedAccess.ts, 246, 5)) return getProperty(this, "parts") ->getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 75, 26)) ->this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 238, 1)) +>getProperty : Symbol(getProperty, Decl(keyofAndIndexedAccess.ts, 77, 26)) +>this : Symbol(OtherPerson, Decl(keyofAndIndexedAccess.ts, 240, 1)) } } + diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types index 916b82aaf40d0..587100496e9ee 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.types +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -47,16 +47,22 @@ type Dictionary = { [x: string]: T }; >x : string >T : T +type NumericallyIndexed = { [x: number]: T }; +>NumericallyIndexed : NumericallyIndexed +>T : T +>x : number +>T : T + const enum E { A, B, C } >E : E >A : E.A >B : E.B >C : E.C -type K00 = keyof any; // string | number +type K00 = keyof any; // string >K00 : string -type K01 = keyof string; // number | "toString" | "charAt" | ... +type K01 = keyof string; // "toString" | "charAt" | ... >K01 : "length" | "toString" | "concat" | "slice" | "indexOf" | "lastIndexOf" | "charAt" | "charCodeAt" | "localeCompare" | "match" | "replace" | "search" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" | "valueOf" type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ... @@ -82,11 +88,11 @@ type K10 = keyof Shape; // "name" | "width" | "height" | "visible" >K10 : "name" | "width" | "height" | "visible" >Shape : Shape -type K11 = keyof Shape[]; // number | "length" | "toString" | ... +type K11 = keyof Shape[]; // "length" | "toString" | ... >K11 : "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" >Shape : Shape -type K12 = keyof Dictionary; // string | number +type K12 = keyof Dictionary; // string >K12 : string >Dictionary : Dictionary >Shape : Shape @@ -102,7 +108,7 @@ type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ... >K15 : "toString" | "toLocaleString" | "valueOf" | "toFixed" | "toExponential" | "toPrecision" >E : E -type K16 = keyof [string, number]; // number | "0" | "1" | "length" | "toString" | ... +type K16 = keyof [string, number]; // "0" | "1" | "length" | "toString" | ... >K16 : "0" | "1" | "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" type K17 = keyof (Shape | Item); // "name" @@ -115,6 +121,11 @@ type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | " >Shape : Shape >Item : Item +type K19 = keyof NumericallyIndexed // never +>K19 : never +>NumericallyIndexed : NumericallyIndexed +>Shape : Shape + type KeyOf = keyof T; >KeyOf : keyof T >T : T @@ -125,7 +136,7 @@ type K20 = KeyOf; // "name" | "width" | "height" | "visible" >KeyOf : keyof T >Shape : Shape -type K21 = KeyOf>; // string | number +type K21 = KeyOf>; // string >K21 : string >KeyOf : keyof T >Dictionary : Dictionary @@ -970,3 +981,4 @@ class OtherPerson { >"parts" : "parts" } } + diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts index b0451b8d55cd6..9aa057986078e 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts @@ -21,11 +21,12 @@ class Options { } type Dictionary = { [x: string]: T }; +type NumericallyIndexed = { [x: number]: T }; const enum E { A, B, C } -type K00 = keyof any; // string | number -type K01 = keyof string; // number | "toString" | "charAt" | ... +type K00 = keyof any; // string +type K01 = keyof string; // "toString" | "charAt" | ... type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ... type K03 = keyof boolean; // "valueOf" type K04 = keyof void; // never @@ -34,19 +35,20 @@ type K06 = keyof null; // never type K07 = keyof never; // never type K10 = keyof Shape; // "name" | "width" | "height" | "visible" -type K11 = keyof Shape[]; // number | "length" | "toString" | ... -type K12 = keyof Dictionary; // string | number +type K11 = keyof Shape[]; // "length" | "toString" | ... +type K12 = keyof Dictionary; // string type K13 = keyof {}; // never type K14 = keyof Object; // "constructor" | "toString" | ... type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ... -type K16 = keyof [string, number]; // number | "0" | "1" | "length" | "toString" | ... +type K16 = keyof [string, number]; // "0" | "1" | "length" | "toString" | ... type K17 = keyof (Shape | Item); // "name" type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | "price" +type K19 = keyof NumericallyIndexed // never type KeyOf = keyof T; type K20 = KeyOf; // "name" | "width" | "height" | "visible" -type K21 = KeyOf>; // string | number +type K21 = KeyOf>; // string type NAME = "name"; type WIDTH_OR_HEIGHT = "width" | "height"; @@ -247,4 +249,4 @@ class OtherPerson { getParts() { return getProperty(this, "parts") } -} \ No newline at end of file +} From 3e1b443d77f732c402be3241190704933c0bf892 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 28 Nov 2016 09:34:50 -0800 Subject: [PATCH 19/22] Deduplicate intersection types before distributing over union types --- src/compiler/checker.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e016d493046fb..7101d0b3d61d7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5637,6 +5637,7 @@ namespace ts { containsString?: boolean; containsNumber?: boolean; containsStringOrNumberLiteral?: boolean; + unionIndex?: number; } function binarySearchTypes(types: Type[], type: Type): number { @@ -5831,6 +5832,9 @@ namespace ts { typeSet.containsAny = true; } else if (!(type.flags & TypeFlags.Never) && (strictNullChecks || !(type.flags & TypeFlags.Nullable)) && !contains(typeSet, type)) { + if (type.flags & TypeFlags.Union && typeSet.unionIndex === undefined) { + typeSet.unionIndex = typeSet.length; + } typeSet.push(type); } } @@ -5857,15 +5861,6 @@ namespace ts { if (types.length === 0) { return emptyObjectType; } - for (let i = 0; i < types.length; i++) { - const type = types[i]; - if (type.flags & TypeFlags.Union) { - // We are attempting to construct a type of the form X & (A | B) & Y. Transform this into a type of - // the form X & A & Y | X & B & Y and recursively reduce until no union type constituents remain. - return getUnionType(map((type).types, t => getIntersectionType(replaceElement(types, i, t))), - /*subtypeReduction*/ false, aliasSymbol, aliasTypeArguments); - } - } const typeSet = [] as TypeSet; addTypesToIntersection(typeSet, types); if (typeSet.containsAny) { @@ -5874,6 +5869,14 @@ namespace ts { if (typeSet.length === 1) { return typeSet[0]; } + const unionIndex = typeSet.unionIndex; + if (unionIndex !== undefined) { + // We are attempting to construct a type of the form X & (A | B) & Y. Transform this into a type of + // the form X & A & Y | X & B & Y and recursively reduce until no union type constituents remain. + const unionType = typeSet[unionIndex]; + return getUnionType(map(unionType.types, t => getIntersectionType(replaceElement(typeSet, unionIndex, t))), + /*subtypeReduction*/ false, aliasSymbol, aliasTypeArguments); + } const id = getTypeListId(typeSet); let type = intersectionTypes[id]; if (!type) { From 0be4edefca502037390f0eaee3cd88823a4e3556 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 28 Nov 2016 09:35:03 -0800 Subject: [PATCH 20/22] Add regression test --- .../intersectionTypeNormalization.js | 50 ++++++++ .../intersectionTypeNormalization.symbols | 110 +++++++++++++++++ .../intersectionTypeNormalization.types | 111 ++++++++++++++++++ .../compiler/intersectionTypeNormalization.ts | 45 +++++++ 4 files changed, 316 insertions(+) diff --git a/tests/baselines/reference/intersectionTypeNormalization.js b/tests/baselines/reference/intersectionTypeNormalization.js index 8309b17f19868..f6eea23e98e40 100644 --- a/tests/baselines/reference/intersectionTypeNormalization.js +++ b/tests/baselines/reference/intersectionTypeNormalization.js @@ -58,6 +58,51 @@ function getValueAsString(value: IntersectionFail): string { return '' + value.num; } return value.str; +} + +// Repro from #12535 + +namespace enums { + export const enum A { + a1, + a2, + a3, + // ... elements omitted for the sake of clarity + a75, + a76, + a77, + } + export const enum B { + b1, + b2, + // ... elements omitted for the sake of clarity + b86, + b87, + } + export const enum C { + c1, + c2, + // ... elements omitted for the sake of clarity + c210, + c211, + } + export type Genre = A | B | C; +} + +type Foo = { + genreId: enums.Genre; +}; + +type Bar = { + genreId: enums.Genre; +}; + +type FooBar = Foo & Bar; + +function foo(so: any) { + const val = so as FooBar; + const isGenre = val.genreId; + return isGenre; } //// [intersectionTypeNormalization.js] @@ -77,3 +122,8 @@ function getValueAsString(value) { } return value.str; } +function foo(so) { + var val = so; + var isGenre = val.genreId; + return isGenre; +} diff --git a/tests/baselines/reference/intersectionTypeNormalization.symbols b/tests/baselines/reference/intersectionTypeNormalization.symbols index a5a00c7040788..fd81eac6d185e 100644 --- a/tests/baselines/reference/intersectionTypeNormalization.symbols +++ b/tests/baselines/reference/intersectionTypeNormalization.symbols @@ -240,3 +240,113 @@ function getValueAsString(value: IntersectionFail): string { >value : Symbol(value, Decl(intersectionTypeNormalization.ts, 54, 26)) >str : Symbol(str, Decl(intersectionTypeNormalization.ts, 47, 35)) } + +// Repro from #12535 + +namespace enums { +>enums : Symbol(enums, Decl(intersectionTypeNormalization.ts, 59, 1)) + + export const enum A { +>A : Symbol(A, Decl(intersectionTypeNormalization.ts, 63, 17)) + + a1, +>a1 : Symbol(A.a1, Decl(intersectionTypeNormalization.ts, 64, 25)) + + a2, +>a2 : Symbol(A.a2, Decl(intersectionTypeNormalization.ts, 65, 11)) + + a3, +>a3 : Symbol(A.a3, Decl(intersectionTypeNormalization.ts, 66, 11)) + + // ... elements omitted for the sake of clarity + a75, +>a75 : Symbol(A.a75, Decl(intersectionTypeNormalization.ts, 67, 11)) + + a76, +>a76 : Symbol(A.a76, Decl(intersectionTypeNormalization.ts, 69, 12)) + + a77, +>a77 : Symbol(A.a77, Decl(intersectionTypeNormalization.ts, 70, 12)) + } + export const enum B { +>B : Symbol(B, Decl(intersectionTypeNormalization.ts, 72, 5)) + + b1, +>b1 : Symbol(B.b1, Decl(intersectionTypeNormalization.ts, 73, 25)) + + b2, +>b2 : Symbol(B.b2, Decl(intersectionTypeNormalization.ts, 74, 11)) + + // ... elements omitted for the sake of clarity + b86, +>b86 : Symbol(B.b86, Decl(intersectionTypeNormalization.ts, 75, 11)) + + b87, +>b87 : Symbol(B.b87, Decl(intersectionTypeNormalization.ts, 77, 12)) + } + export const enum C { +>C : Symbol(C, Decl(intersectionTypeNormalization.ts, 79, 5)) + + c1, +>c1 : Symbol(C.c1, Decl(intersectionTypeNormalization.ts, 80, 25)) + + c2, +>c2 : Symbol(C.c2, Decl(intersectionTypeNormalization.ts, 81, 11)) + + // ... elements omitted for the sake of clarity + c210, +>c210 : Symbol(C.c210, Decl(intersectionTypeNormalization.ts, 82, 11)) + + c211, +>c211 : Symbol(C.c211, Decl(intersectionTypeNormalization.ts, 84, 13)) + } + export type Genre = A | B | C; +>Genre : Symbol(Genre, Decl(intersectionTypeNormalization.ts, 86, 5)) +>A : Symbol(A, Decl(intersectionTypeNormalization.ts, 63, 17)) +>B : Symbol(B, Decl(intersectionTypeNormalization.ts, 72, 5)) +>C : Symbol(C, Decl(intersectionTypeNormalization.ts, 79, 5)) +} + +type Foo = { +>Foo : Symbol(Foo, Decl(intersectionTypeNormalization.ts, 88, 1)) + + genreId: enums.Genre; +>genreId : Symbol(genreId, Decl(intersectionTypeNormalization.ts, 90, 12)) +>enums : Symbol(enums, Decl(intersectionTypeNormalization.ts, 59, 1)) +>Genre : Symbol(enums.Genre, Decl(intersectionTypeNormalization.ts, 86, 5)) + +}; + +type Bar = { +>Bar : Symbol(Bar, Decl(intersectionTypeNormalization.ts, 92, 2)) + + genreId: enums.Genre; +>genreId : Symbol(genreId, Decl(intersectionTypeNormalization.ts, 94, 12)) +>enums : Symbol(enums, Decl(intersectionTypeNormalization.ts, 59, 1)) +>Genre : Symbol(enums.Genre, Decl(intersectionTypeNormalization.ts, 86, 5)) + +}; + +type FooBar = Foo & Bar; +>FooBar : Symbol(FooBar, Decl(intersectionTypeNormalization.ts, 96, 2)) +>Foo : Symbol(Foo, Decl(intersectionTypeNormalization.ts, 88, 1)) +>Bar : Symbol(Bar, Decl(intersectionTypeNormalization.ts, 92, 2)) + +function foo(so: any) { +>foo : Symbol(foo, Decl(intersectionTypeNormalization.ts, 98, 24)) +>so : Symbol(so, Decl(intersectionTypeNormalization.ts, 100, 13)) + + const val = so as FooBar; +>val : Symbol(val, Decl(intersectionTypeNormalization.ts, 101, 9)) +>so : Symbol(so, Decl(intersectionTypeNormalization.ts, 100, 13)) +>FooBar : Symbol(FooBar, Decl(intersectionTypeNormalization.ts, 96, 2)) + + const isGenre = val.genreId; +>isGenre : Symbol(isGenre, Decl(intersectionTypeNormalization.ts, 102, 9)) +>val.genreId : Symbol(genreId, Decl(intersectionTypeNormalization.ts, 90, 12), Decl(intersectionTypeNormalization.ts, 94, 12)) +>val : Symbol(val, Decl(intersectionTypeNormalization.ts, 101, 9)) +>genreId : Symbol(genreId, Decl(intersectionTypeNormalization.ts, 90, 12), Decl(intersectionTypeNormalization.ts, 94, 12)) + + return isGenre; +>isGenre : Symbol(isGenre, Decl(intersectionTypeNormalization.ts, 102, 9)) +} diff --git a/tests/baselines/reference/intersectionTypeNormalization.types b/tests/baselines/reference/intersectionTypeNormalization.types index 99d0ecb1f3ab0..3ffe7484afecd 100644 --- a/tests/baselines/reference/intersectionTypeNormalization.types +++ b/tests/baselines/reference/intersectionTypeNormalization.types @@ -244,3 +244,114 @@ function getValueAsString(value: IntersectionFail): string { >value : { kind: "string"; str: string; } & ToString >str : string } + +// Repro from #12535 + +namespace enums { +>enums : typeof enums + + export const enum A { +>A : A + + a1, +>a1 : A.a1 + + a2, +>a2 : A.a2 + + a3, +>a3 : A.a3 + + // ... elements omitted for the sake of clarity + a75, +>a75 : A.a75 + + a76, +>a76 : A.a76 + + a77, +>a77 : A.a77 + } + export const enum B { +>B : B + + b1, +>b1 : B.b1 + + b2, +>b2 : B.b2 + + // ... elements omitted for the sake of clarity + b86, +>b86 : B.b86 + + b87, +>b87 : B.b87 + } + export const enum C { +>C : C + + c1, +>c1 : C.c1 + + c2, +>c2 : C.c2 + + // ... elements omitted for the sake of clarity + c210, +>c210 : C.c210 + + c211, +>c211 : C.c211 + } + export type Genre = A | B | C; +>Genre : Genre +>A : A +>B : B +>C : C +} + +type Foo = { +>Foo : Foo + + genreId: enums.Genre; +>genreId : enums.Genre +>enums : any +>Genre : enums.Genre + +}; + +type Bar = { +>Bar : Bar + + genreId: enums.Genre; +>genreId : enums.Genre +>enums : any +>Genre : enums.Genre + +}; + +type FooBar = Foo & Bar; +>FooBar : FooBar +>Foo : Foo +>Bar : Bar + +function foo(so: any) { +>foo : (so: any) => enums.Genre +>so : any + + const val = so as FooBar; +>val : FooBar +>so as FooBar : FooBar +>so : any +>FooBar : FooBar + + const isGenre = val.genreId; +>isGenre : enums.Genre +>val.genreId : enums.Genre +>val : FooBar +>genreId : enums.Genre + + return isGenre; +>isGenre : enums.Genre +} diff --git a/tests/cases/compiler/intersectionTypeNormalization.ts b/tests/cases/compiler/intersectionTypeNormalization.ts index f31c3d49014b4..3d07aeb1a2339 100644 --- a/tests/cases/compiler/intersectionTypeNormalization.ts +++ b/tests/cases/compiler/intersectionTypeNormalization.ts @@ -57,4 +57,49 @@ function getValueAsString(value: IntersectionFail): string { return '' + value.num; } return value.str; +} + +// Repro from #12535 + +namespace enums { + export const enum A { + a1, + a2, + a3, + // ... elements omitted for the sake of clarity + a75, + a76, + a77, + } + export const enum B { + b1, + b2, + // ... elements omitted for the sake of clarity + b86, + b87, + } + export const enum C { + c1, + c2, + // ... elements omitted for the sake of clarity + c210, + c211, + } + export type Genre = A | B | C; +} + +type Foo = { + genreId: enums.Genre; +}; + +type Bar = { + genreId: enums.Genre; +}; + +type FooBar = Foo & Bar; + +function foo(so: any) { + const val = so as FooBar; + const isGenre = val.genreId; + return isGenre; } \ No newline at end of file From 9065b501723fbd57a2baa9f1be0a938c85606fd6 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 28 Nov 2016 10:53:25 -0800 Subject: [PATCH 21/22] getRegularTypeOfLiteralType before exhaustive switch check --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7101d0b3d61d7..719ba724f4237 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13850,7 +13850,7 @@ namespace ts { if (!switchTypes.length) { return false; } - return eachTypeContainedIn(type, switchTypes); + return eachTypeContainedIn(mapType(type, getRegularTypeOfLiteralType), switchTypes); } function functionHasImplicitReturn(func: FunctionLikeDeclaration) { From 2b0721672ce46cbd42fdfc70656e3ea277ee8c22 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 28 Nov 2016 11:01:19 -0800 Subject: [PATCH 22/22] Add regression test --- ...xhaustiveSwitchWithWideningLiteralTypes.js | 39 ++++++++++++++++++ ...tiveSwitchWithWideningLiteralTypes.symbols | 33 +++++++++++++++ ...ustiveSwitchWithWideningLiteralTypes.types | 40 +++++++++++++++++++ ...xhaustiveSwitchWithWideningLiteralTypes.ts | 18 +++++++++ 4 files changed, 130 insertions(+) create mode 100644 tests/baselines/reference/exhaustiveSwitchWithWideningLiteralTypes.js create mode 100644 tests/baselines/reference/exhaustiveSwitchWithWideningLiteralTypes.symbols create mode 100644 tests/baselines/reference/exhaustiveSwitchWithWideningLiteralTypes.types create mode 100644 tests/cases/compiler/exhaustiveSwitchWithWideningLiteralTypes.ts diff --git a/tests/baselines/reference/exhaustiveSwitchWithWideningLiteralTypes.js b/tests/baselines/reference/exhaustiveSwitchWithWideningLiteralTypes.js new file mode 100644 index 0000000000000..218d760d6c51a --- /dev/null +++ b/tests/baselines/reference/exhaustiveSwitchWithWideningLiteralTypes.js @@ -0,0 +1,39 @@ +//// [exhaustiveSwitchWithWideningLiteralTypes.ts] + +// Repro from #12529 + +class A { + readonly kind = "A"; // (property) A.kind: "A" +} + +class B { + readonly kind = "B"; // (property) B.kind: "B" +} + +function f(value: A | B): number { + switch(value.kind) { + case "A": return 0; + case "B": return 1; + } +} + +//// [exhaustiveSwitchWithWideningLiteralTypes.js] +// Repro from #12529 +var A = (function () { + function A() { + this.kind = "A"; // (property) A.kind: "A" + } + return A; +}()); +var B = (function () { + function B() { + this.kind = "B"; // (property) B.kind: "B" + } + return B; +}()); +function f(value) { + switch (value.kind) { + case "A": return 0; + case "B": return 1; + } +} diff --git a/tests/baselines/reference/exhaustiveSwitchWithWideningLiteralTypes.symbols b/tests/baselines/reference/exhaustiveSwitchWithWideningLiteralTypes.symbols new file mode 100644 index 0000000000000..929a394dc7bee --- /dev/null +++ b/tests/baselines/reference/exhaustiveSwitchWithWideningLiteralTypes.symbols @@ -0,0 +1,33 @@ +=== tests/cases/compiler/exhaustiveSwitchWithWideningLiteralTypes.ts === + +// Repro from #12529 + +class A { +>A : Symbol(A, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 0, 0)) + + readonly kind = "A"; // (property) A.kind: "A" +>kind : Symbol(A.kind, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 3, 9)) +} + +class B { +>B : Symbol(B, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 5, 1)) + + readonly kind = "B"; // (property) B.kind: "B" +>kind : Symbol(B.kind, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 7, 9)) +} + +function f(value: A | B): number { +>f : Symbol(f, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 9, 1)) +>value : Symbol(value, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 11, 11)) +>A : Symbol(A, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 0, 0)) +>B : Symbol(B, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 5, 1)) + + switch(value.kind) { +>value.kind : Symbol(kind, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 3, 9), Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 7, 9)) +>value : Symbol(value, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 11, 11)) +>kind : Symbol(kind, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 3, 9), Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 7, 9)) + + case "A": return 0; + case "B": return 1; + } +} diff --git a/tests/baselines/reference/exhaustiveSwitchWithWideningLiteralTypes.types b/tests/baselines/reference/exhaustiveSwitchWithWideningLiteralTypes.types new file mode 100644 index 0000000000000..3955c80ff1e88 --- /dev/null +++ b/tests/baselines/reference/exhaustiveSwitchWithWideningLiteralTypes.types @@ -0,0 +1,40 @@ +=== tests/cases/compiler/exhaustiveSwitchWithWideningLiteralTypes.ts === + +// Repro from #12529 + +class A { +>A : A + + readonly kind = "A"; // (property) A.kind: "A" +>kind : "A" +>"A" : "A" +} + +class B { +>B : B + + readonly kind = "B"; // (property) B.kind: "B" +>kind : "B" +>"B" : "B" +} + +function f(value: A | B): number { +>f : (value: A | B) => number +>value : A | B +>A : A +>B : B + + switch(value.kind) { +>value.kind : "A" | "B" +>value : A | B +>kind : "A" | "B" + + case "A": return 0; +>"A" : "A" +>0 : 0 + + case "B": return 1; +>"B" : "B" +>1 : 1 + } +} diff --git a/tests/cases/compiler/exhaustiveSwitchWithWideningLiteralTypes.ts b/tests/cases/compiler/exhaustiveSwitchWithWideningLiteralTypes.ts new file mode 100644 index 0000000000000..14183a5de59bc --- /dev/null +++ b/tests/cases/compiler/exhaustiveSwitchWithWideningLiteralTypes.ts @@ -0,0 +1,18 @@ +// @strictNullChecks: true + +// Repro from #12529 + +class A { + readonly kind = "A"; // (property) A.kind: "A" +} + +class B { + readonly kind = "B"; // (property) B.kind: "B" +} + +function f(value: A | B): number { + switch(value.kind) { + case "A": return 0; + case "B": return 1; + } +} \ No newline at end of file