diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 770e1a7c1c60a..f6b5ad3901e04 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18299,6 +18299,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function shouldDeferIndexType(type: Type, indexFlags = IndexFlags.None) { return !!(type.flags & TypeFlags.InstantiableNonPrimitive || + type.flags & TypeFlags.Index && isUnconstrainedTypeParameter((type as IndexType).type) || isGenericTupleType(type) || isGenericMappedType(type) && (!hasDistributiveNameType(type) || getMappedTypeNameTypeKind(type) === MappedTypeNameTypeKind.Remapping) || type.flags & TypeFlags.Union && !(indexFlags & IndexFlags.NoReducibleCheck) && isGenericReducibleType(type) || @@ -18987,7 +18988,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { isGenericTupleType(objectType) && !indexTypeLessThan(indexType, getTotalFixedElementCount(objectType.target)) : isGenericObjectType(objectType) && !(isTupleType(objectType) && indexTypeLessThan(indexType, getTotalFixedElementCount(objectType.target))) || isGenericReducibleType(objectType)) ) { - if (objectType.flags & TypeFlags.AnyOrUnknown) { + if (objectType.flags & TypeFlags.AnyOrUnknown || (strictNullChecks && (objectType.flags & TypeFlags.Union) && isUnknownLikeUnionType(objectType))) { return objectType; } // Defer the operation by creating an indexed access type. @@ -27343,7 +27344,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function getTypeFactsWorker(type: Type, callerOnlyNeeds: TypeFacts): TypeFacts { if (type.flags & (TypeFlags.Intersection | TypeFlags.Instantiable)) { - type = getBaseConstraintOfType(type) || unknownType; + const constraintType = getBaseConstraintOfType(type) || unknownType; + if (strictNullChecks && type.flags & TypeFlags.Instantiable && constraintType === unknownType) { + return callerOnlyNeeds; + } + type = constraintType; } const flags = type.flags; if (flags & (TypeFlags.String | TypeFlags.StringMapping)) { @@ -27477,7 +27482,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // For each constituent type that can compare equal to the target nullable, intersect with the above union // if the type doesn't already include the opppsite nullable and the constituent can compare equal to the // opposite nullable; otherwise, just intersect with {}. - return mapType(type, t => hasTypeFacts(t, targetFacts) ? getIntersectionType([t, !(facts & otherIncludesFacts) && hasTypeFacts(t, otherFacts) ? emptyAndOtherUnion : emptyObjectType]) : t); + return mapType(type, t => hasTypeFacts(t, targetFacts) ? getIntersectionType([t, (strictNullChecks || !(facts & otherIncludesFacts)) && hasTypeFacts(t, otherFacts) ? emptyAndOtherUnion : emptyObjectType]) : t); } function recombineUnknownType(type: Type) { @@ -34556,8 +34561,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function checkIndexedAccess(node: ElementAccessExpression, checkMode: CheckMode | undefined): Type { - return node.flags & NodeFlags.OptionalChain ? checkElementAccessChain(node as ElementAccessChain, checkMode) : - checkElementAccessExpression(node, checkNonNullExpression(node.expression), checkMode); + if (node.flags & NodeFlags.OptionalChain) { + return checkElementAccessChain(node as ElementAccessChain, checkMode); + } + if (shouldDeferIndexType(getTypeOfNode(node.argumentExpression))) { + return checkElementAccessExpression(node, checkExpression(node.expression), checkMode, /*deferredIndexCheck*/ true); + } + return checkElementAccessExpression(node, checkNonNullExpression(node.expression), checkMode); } function checkElementAccessChain(node: ElementAccessChain, checkMode: CheckMode | undefined) { @@ -34566,7 +34576,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return propagateOptionalTypeMarker(checkElementAccessExpression(node, checkNonNullType(nonOptionalType, node.expression), checkMode), node, nonOptionalType !== exprType); } - function checkElementAccessExpression(node: ElementAccessExpression, exprType: Type, checkMode: CheckMode | undefined): Type { + function checkElementAccessExpression(node: ElementAccessExpression, exprType: Type, checkMode: CheckMode | undefined, deferredIndexCheck: boolean = false): Type { const objectType = getAssignmentTargetKind(node) !== AssignmentKind.None || isMethodAccessForCall(node) ? getWidenedType(exprType) : exprType; const indexExpression = node.argumentExpression; const indexType = checkExpression(indexExpression); @@ -34593,7 +34603,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } const indexedAccessType = getIndexedAccessTypeOrUndefined(objectType, effectiveIndexType, accessFlags, node) || errorType; - return checkIndexedAccessIndexType(getFlowTypeOfAccessExpression(node, getNodeLinks(node).resolvedSymbol, indexedAccessType, indexExpression, checkMode), node); + return checkIndexedAccessIndexType(getFlowTypeOfAccessExpression(node, getNodeLinks(node).resolvedSymbol, indexedAccessType, indexExpression, checkMode), node, deferredIndexCheck); } function callLikeExpressionMayHaveTypeArguments(node: CallLikeExpression): node is CallExpression | NewExpression | TaggedTemplateExpression | JsxOpeningElement { @@ -41556,7 +41566,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { getTypeFromTypeNode(node); } - function checkIndexedAccessIndexType(type: Type, accessNode: IndexedAccessTypeNode | ElementAccessExpression) { + function checkIndexedAccessIndexType(type: Type, accessNode: IndexedAccessTypeNode | ElementAccessExpression, deferredIndexCheck: boolean = false) { if (!(type.flags & TypeFlags.IndexedAccess)) { return type; } @@ -41587,6 +41597,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } } + if (deferredIndexCheck && isAccessExpression(accessNode) && isErrorType(checkNonNullExpression(accessNode.expression))) { + return errorType; + } error(accessNode, Diagnostics.Type_0_cannot_be_used_to_index_type_1, typeToString(indexType), typeToString(objectType)); return errorType; } diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 83abf06ff6b99..e82e9a62a2235 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -1738,7 +1738,7 @@ export class TestState { for (const key in actual) { if (ts.hasProperty(actual as any, key)) { - const ak = actual[key], ek = expected[key]; + const ak = actual[key], ek = (expected as typeof actual)[key]; if (typeof ak === "object" && typeof ek === "object") { recur(ak, ek, path ? path + "." + key : key); } diff --git a/tests/baselines/reference/controlFlowGenericTypes.errors.txt b/tests/baselines/reference/controlFlowGenericTypes.errors.txt index 27101aaa81cc4..7968952ede743 100644 --- a/tests/baselines/reference/controlFlowGenericTypes.errors.txt +++ b/tests/baselines/reference/controlFlowGenericTypes.errors.txt @@ -6,11 +6,12 @@ controlFlowGenericTypes.ts(90,44): error TS2355: A function whose declared type controlFlowGenericTypes.ts(91,11): error TS2339: Property 'foo' does not exist on type 'MyUnion'. Property 'foo' does not exist on type 'AA'. controlFlowGenericTypes.ts(156,16): error TS18048: 'obj' is possibly 'undefined'. +controlFlowGenericTypes.ts(156,16): error TS2536: Type 'K' cannot be used to index type 'Record | undefined'. controlFlowGenericTypes.ts(167,9): error TS18048: 'iSpec' is possibly 'undefined'. controlFlowGenericTypes.ts(168,9): error TS18048: 'iSpec' is possibly 'undefined'. -==== controlFlowGenericTypes.ts (8 errors) ==== +==== controlFlowGenericTypes.ts (9 errors) ==== function f1(x: T, y: { a: T }, z: [T]): string { if (x) { x; @@ -181,6 +182,8 @@ controlFlowGenericTypes.ts(168,9): error TS18048: 'iSpec' is possibly 'undefined const x1 = obj[key]; // Error ~~~ !!! error TS18048: 'obj' is possibly 'undefined'. + ~~~~~~~~ +!!! error TS2536: Type 'K' cannot be used to index type 'Record | undefined'. const x2 = obj && obj[key]; } diff --git a/tests/baselines/reference/controlFlowGenericTypes.types b/tests/baselines/reference/controlFlowGenericTypes.types index 34aaf80709138..2d636f3608edc 100644 --- a/tests/baselines/reference/controlFlowGenericTypes.types +++ b/tests/baselines/reference/controlFlowGenericTypes.types @@ -662,10 +662,10 @@ function fx3 | undefined, K extends keyof T>(o > : ^ const x1 = obj[key]; // Error ->x1 : Record[K] -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ ->obj[key] : Record[K] -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>x1 : any +> : ^^^ +>obj[key] : any +> : ^^^ >obj : Record | undefined > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >key : K diff --git a/tests/baselines/reference/genericUnboundedTypeParamAssignability.errors.txt b/tests/baselines/reference/genericUnboundedTypeParamAssignability.errors.txt index 8dad05aa147fd..eef2f0d6ba0f6 100644 --- a/tests/baselines/reference/genericUnboundedTypeParamAssignability.errors.txt +++ b/tests/baselines/reference/genericUnboundedTypeParamAssignability.errors.txt @@ -1,14 +1,14 @@ -genericUnboundedTypeParamAssignability.ts(2,5): error TS2339: Property 'toString' does not exist on type 'T'. +genericUnboundedTypeParamAssignability.ts(2,3): error TS18049: 'o' is possibly 'null' or 'undefined'. genericUnboundedTypeParamAssignability.ts(15,6): error TS2345: Argument of type 'T' is not assignable to parameter of type '{}'. genericUnboundedTypeParamAssignability.ts(16,6): error TS2345: Argument of type 'T' is not assignable to parameter of type 'Record'. -genericUnboundedTypeParamAssignability.ts(17,5): error TS2339: Property 'toString' does not exist on type 'T'. +genericUnboundedTypeParamAssignability.ts(17,3): error TS18049: 't' is possibly 'null' or 'undefined'. ==== genericUnboundedTypeParamAssignability.ts (4 errors) ==== function f1(o: T) { o.toString(); // error - ~~~~~~~~ -!!! error TS2339: Property 'toString' does not exist on type 'T'. + ~ +!!! error TS18049: 'o' is possibly 'null' or 'undefined'. } function f2(o: T) { @@ -30,7 +30,7 @@ genericUnboundedTypeParamAssignability.ts(17,5): error TS2339: Property 'toStrin !!! error TS2345: Argument of type 'T' is not assignable to parameter of type 'Record'. !!! related TS2208 genericUnboundedTypeParamAssignability.ts:13:15: This type parameter might need an `extends Record` constraint. t.toString(); // error, for the same reason as f1() - ~~~~~~~~ -!!! error TS2339: Property 'toString' does not exist on type 'T'. + ~ +!!! error TS18049: 't' is possibly 'null' or 'undefined'. } \ No newline at end of file diff --git a/tests/baselines/reference/genericUnboundedTypeParamAssignability.symbols b/tests/baselines/reference/genericUnboundedTypeParamAssignability.symbols index 6e5f0187940c6..0125bfed73ff2 100644 --- a/tests/baselines/reference/genericUnboundedTypeParamAssignability.symbols +++ b/tests/baselines/reference/genericUnboundedTypeParamAssignability.symbols @@ -8,7 +8,9 @@ function f1(o: T) { >T : Symbol(T, Decl(genericUnboundedTypeParamAssignability.ts, 0, 12)) o.toString(); // error +>o.toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --)) >o : Symbol(o, Decl(genericUnboundedTypeParamAssignability.ts, 0, 15)) +>toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --)) } function f2(o: T) { @@ -55,6 +57,8 @@ function user(t: T) { >t : Symbol(t, Decl(genericUnboundedTypeParamAssignability.ts, 12, 17)) t.toString(); // error, for the same reason as f1() +>t.toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --)) >t : Symbol(t, Decl(genericUnboundedTypeParamAssignability.ts, 12, 17)) +>toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --)) } diff --git a/tests/baselines/reference/genericUnboundedTypeParamAssignability.types b/tests/baselines/reference/genericUnboundedTypeParamAssignability.types index 92816a1a292db..54480f3bd9e03 100644 --- a/tests/baselines/reference/genericUnboundedTypeParamAssignability.types +++ b/tests/baselines/reference/genericUnboundedTypeParamAssignability.types @@ -8,14 +8,14 @@ function f1(o: T) { > : ^ o.toString(); // error ->o.toString() : any -> : ^^^ ->o.toString : any -> : ^^^ +>o.toString() : string +> : ^^^^^^ +>o.toString : () => string +> : ^^^^^^ >o : T > : ^ ->toString : any -> : ^^^ +>toString : () => string +> : ^^^^^^ } function f2(o: T) { @@ -83,13 +83,13 @@ function user(t: T) { > : ^ t.toString(); // error, for the same reason as f1() ->t.toString() : any -> : ^^^ ->t.toString : any -> : ^^^ +>t.toString() : string +> : ^^^^^^ +>t.toString : () => string +> : ^^^^^^ >t : T > : ^ ->toString : any -> : ^^^ +>toString : () => string +> : ^^^^^^ } diff --git a/tests/baselines/reference/inKeywordTypeguard(strict=true).errors.txt b/tests/baselines/reference/inKeywordTypeguard(strict=true).errors.txt index 7b998070848b9..f1221aae3e3fd 100644 --- a/tests/baselines/reference/inKeywordTypeguard(strict=true).errors.txt +++ b/tests/baselines/reference/inKeywordTypeguard(strict=true).errors.txt @@ -30,7 +30,7 @@ inKeywordTypeguard.ts(90,5): error TS2564: Property 'a' has no initializer and i inKeywordTypeguard.ts(94,26): error TS2339: Property 'a' does not exist on type 'never'. inKeywordTypeguard.ts(155,16): error TS18046: 'x' is of type 'unknown'. inKeywordTypeguard.ts(158,21): error TS2638: Type '{}' may represent a primitive value, which is not permitted as the right operand of the 'in' operator. -inKeywordTypeguard.ts(183,16): error TS2322: Type 'T' is not assignable to type 'object'. +inKeywordTypeguard.ts(183,16): error TS18049: 'x' is possibly 'null' or 'undefined'. inKeywordTypeguard.ts(186,21): error TS2638: Type 'NonNullable' may represent a primitive value, which is not permitted as the right operand of the 'in' operator. @@ -277,8 +277,7 @@ inKeywordTypeguard.ts(186,21): error TS2638: Type 'NonNullable' may represent function f3(x: T) { if ("a" in x) { ~ -!!! error TS2322: Type 'T' is not assignable to type 'object'. -!!! related TS2208 inKeywordTypeguard.ts:182:13: This type parameter might need an `extends object` constraint. +!!! error TS18049: 'x' is possibly 'null' or 'undefined'. x.a; } if (x && "a" in x) { diff --git a/tests/baselines/reference/isomorphicMappedTypeInference.errors.txt b/tests/baselines/reference/isomorphicMappedTypeInference.errors.txt new file mode 100644 index 0000000000000..b0edd9966d74f --- /dev/null +++ b/tests/baselines/reference/isomorphicMappedTypeInference.errors.txt @@ -0,0 +1,188 @@ +isomorphicMappedTypeInference.ts(20,9): error TS2536: Type 'Extract, string>' cannot be used to index type 'Boxified'. +isomorphicMappedTypeInference.ts(35,9): error TS2536: Type 'Extract, string>' cannot be used to index type 'Boxified'. + + +==== isomorphicMappedTypeInference.ts (2 errors) ==== + 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]); + ~~~~~~~~~ +!!! error TS2536: Type 'Extract, string>' cannot be used to index type 'Boxified'. + } + 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]; + ~~~~~~ +!!! error TS2536: Type 'Extract, string>' cannot be used to index type 'Boxified'. + } + } + + 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]; + } + + declare function validate(obj: { [P in keyof T]?: T[P] }): T; + declare function clone(obj: { readonly [P in keyof T]: T[P] }): T; + declare function validateAndClone(obj: { readonly [P in keyof T]?: T[P] }): T; + + type Foo = { + a?: number; + readonly b: string; + } + + function f10(foo: Foo) { + let x = validate(foo); // { a: number, readonly b: string } + let y = clone(foo); // { a?: number, b: string } + let z = validateAndClone(foo); // { a: number, b: string } + } + + // Repro from #12606 + + type Func = (...args: any[]) => T; + type Spec = { + [P in keyof T]: Func | Spec ; + }; + + /** + * Given a spec object recursively mapping properties to functions, creates a function + * producing an object of the same structure, by mapping each property to the result + * of calling its associated function with the supplied arguments. + */ + declare function applySpec(obj: Spec): (...args: any[]) => T; + + // Infers g1: (...args: any[]) => { sum: number, nested: { mul: string } } + var g1 = applySpec({ + sum: (a: any) => 3, + nested: { + mul: (b: any) => "n" + } + }); + + // Infers g2: (...args: any[]) => { foo: { bar: { baz: boolean } } } + var g2 = applySpec({ foo: { bar: { baz: (x: any) => true } } }); + + // Repro from #12633 + + const foo = (object: T, partial: Partial) => object; + let o = {a: 5, b: 7}; + foo(o, {b: 9}); + o = foo(o, {b: 9}); + + // Inferring to { [P in K]: X }, where K extends keyof T, produces same inferences as + // inferring to { [P in keyof T]: X }. + + declare function f20(obj: Pick): T; + declare function f21(obj: Pick): K; + declare function f22(obj: Boxified>): T; + declare function f23(obj: Pick): T; + declare function f24(obj: Pick): T & U; + + let x0 = f20({ foo: 42, bar: "hello" }); + let x1 = f21({ foo: 42, bar: "hello" }); + let x2 = f22({ foo: { value: 42} , bar: { value: "hello" } }); + let x3 = f23({ foo: 42, bar: "hello" }); + let x4 = f24({ foo: 42, bar: "hello" }); + + // Repro from #29765 + + function getProps(obj: T, list: K[]): Pick { + return {} as any; + } + + const myAny: any = {}; + + const o1 = getProps(myAny, ['foo', 'bar']); + + const o2: { foo: any; bar: any } = getProps(myAny, ['foo', 'bar']); + \ No newline at end of file diff --git a/tests/baselines/reference/isomorphicMappedTypeInference.symbols b/tests/baselines/reference/isomorphicMappedTypeInference.symbols index f48c4517b700d..fbfeb5b3bd59f 100644 --- a/tests/baselines/reference/isomorphicMappedTypeInference.symbols +++ b/tests/baselines/reference/isomorphicMappedTypeInference.symbols @@ -118,10 +118,8 @@ function assignBoxified(obj: Boxified, values: T) { >values : Symbol(values, Decl(isomorphicMappedTypeInference.ts, 32, 44)) obj[k].value = values[k]; ->obj[k].value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 0, 15)) >obj : Symbol(obj, Decl(isomorphicMappedTypeInference.ts, 32, 27)) >k : Symbol(k, Decl(isomorphicMappedTypeInference.ts, 33, 12)) ->value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 0, 15)) >values : Symbol(values, Decl(isomorphicMappedTypeInference.ts, 32, 44)) >k : Symbol(k, Decl(isomorphicMappedTypeInference.ts, 33, 12)) } diff --git a/tests/baselines/reference/isomorphicMappedTypeInference.types b/tests/baselines/reference/isomorphicMappedTypeInference.types index 964f662342216..92dfec41cb6cb 100644 --- a/tests/baselines/reference/isomorphicMappedTypeInference.types +++ b/tests/baselines/reference/isomorphicMappedTypeInference.types @@ -65,30 +65,30 @@ function boxify(obj: T): Boxified { > : ^^ for (let k in obj) { ->k : Extract -> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>k : Extract, string> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >obj : T > : ^ result[k] = box(obj[k]); ->result[k] = box(obj[k]) : Box]> -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->result[k] : Boxified[Extract] -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>result[k] = box(obj[k]) : Box[Extract, string>]> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>result[k] : any +> : ^^^ >result : Boxified > : ^^^^^^^^^^^ ->k : Extract -> : ^^^^^^^^^^^^^^^^^^^^^^^^ ->box(obj[k]) : Box]> -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>k : Extract, string> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>box(obj[k]) : Box[Extract, string>]> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >box : (x: T_1) => Box > : ^^^^^^ ^^ ^^^^^ ->obj[k] : T[Extract] -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->obj : T -> : ^ ->k : Extract -> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>obj[k] : NonNullable[Extract, string>] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : NonNullable +> : ^^^^^^^^^^^^^^ +>k : Extract, string> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ } return result; >result : Boxified @@ -149,30 +149,30 @@ function assignBoxified(obj: Boxified, values: T) { > : ^ for (let k in values) { ->k : Extract -> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>k : Extract, string> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >values : T > : ^ obj[k].value = values[k]; ->obj[k].value = values[k] : T[Extract] -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->obj[k].value : T[Extract] -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->obj[k] : Boxified[Extract] -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj[k].value = values[k] : NonNullable[Extract, string>] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj[k].value : any +> : ^^^ +>obj[k] : any +> : ^^^ >obj : Boxified > : ^^^^^^^^^^^ ->k : Extract -> : ^^^^^^^^^^^^^^^^^^^^^^^^ ->value : T[Extract] -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->values[k] : T[Extract] -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->values : T -> : ^ ->k : Extract -> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>k : Extract, string> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>value : any +> : ^^^ +>values[k] : NonNullable[Extract, string>] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>values : NonNullable +> : ^^^^^^^^^^^^^^ +>k : Extract, string> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ } } @@ -695,6 +695,7 @@ var g1 = applySpec({ >(a: any) => 3 : (a: any) => number > : ^ ^^ ^^^^^^^^^^^ >a : any +> : ^^^ >3 : 3 > : ^ @@ -710,6 +711,7 @@ var g1 = applySpec({ >(b: any) => "n" : (b: any) => string > : ^ ^^ ^^^^^^^^^^^ >b : any +> : ^^^ >"n" : "n" > : ^^^ } @@ -738,6 +740,7 @@ var g2 = applySpec({ foo: { bar: { baz: (x: any) => true } } }); >(x: any) => true : (x: any) => boolean > : ^ ^^ ^^^^^^^^^^^^ >x : any +> : ^^^ >true : true > : ^^^^ @@ -944,12 +947,14 @@ function getProps(obj: T, list: K[]): Pick { return {} as any; >{} as any : any +> : ^^^ >{} : {} > : ^^ } const myAny: any = {}; >myAny : any +> : ^^^ >{} : {} > : ^^ @@ -961,6 +966,7 @@ const o1 = getProps(myAny, ['foo', 'bar']); >getProps : (obj: T, list: K[]) => Pick > : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^ >myAny : any +> : ^^^ >['foo', 'bar'] : ("foo" | "bar")[] > : ^^^^^^^^^^^^^^^^^ >'foo' : "foo" @@ -972,12 +978,15 @@ const o2: { foo: any; bar: any } = getProps(myAny, ['foo', 'bar']); >o2 : { foo: any; bar: any; } > : ^^^^^^^ ^^^^^^^ ^^^ >foo : any +> : ^^^ >bar : any +> : ^^^ >getProps(myAny, ['foo', 'bar']) : Pick > : ^^^^^^^^^^^^^^^^^^^^^^^^ >getProps : (obj: T, list: K[]) => Pick > : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^ >myAny : any +> : ^^^ >['foo', 'bar'] : ("foo" | "bar")[] > : ^^^^^^^^^^^^^^^^^ >'foo' : "foo" diff --git a/tests/baselines/reference/keyofAndIndexedAccess.errors.txt b/tests/baselines/reference/keyofAndIndexedAccess.errors.txt index b9df4e468911a..23bf5089cc4d1 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccess.errors.txt @@ -1,19 +1,19 @@ -keyofAndIndexedAccess.ts(205,24): error TS2322: Type 'T[keyof T]' is not assignable to type 'object'. - Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'object'. - Type 'T[string]' is not assignable to type 'object'. -keyofAndIndexedAccess.ts(211,24): error TS2322: Type 'T[K]' is not assignable to type 'object'. - Type 'T[keyof T]' is not assignable to type 'object'. - Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'object'. - Type 'T[string]' is not assignable to type 'object'. +keyofAndIndexedAccess.ts(205,24): error TS2533: Object is possibly 'null' or 'undefined'. +keyofAndIndexedAccess.ts(211,24): error TS2533: Object is possibly 'null' or 'undefined'. +keyofAndIndexedAccess.ts(216,9): error TS18049: 'target' is possibly 'null' or 'undefined'. +keyofAndIndexedAccess.ts(216,9): error TS2536: Type 'Extract, string>' cannot be used to index type 'T'. keyofAndIndexedAccess.ts(316,5): error TS2322: Type 'T' is not assignable to type '{}'. keyofAndIndexedAccess.ts(317,5): error TS2322: Type 'T[keyof T]' is not assignable to type '{}'. Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'. Type 'T[string]' is not assignable to type '{}'. keyofAndIndexedAccess.ts(318,5): error TS2322: Type 'T[K]' is not assignable to type '{}'. Type 'T[keyof T]' is not assignable to type '{}'. +keyofAndIndexedAccess.ts(566,9): error TS2322: Type 'T[K]' is not assignable to type 'NonNullable[Extract, string>]'. + Type 'T' is not assignable to type 'NonNullable'. + Type 'T' is not assignable to type '{}'. -==== keyofAndIndexedAccess.ts (5 errors) ==== +==== keyofAndIndexedAccess.ts (8 errors) ==== class Shape { name: string; width: number; @@ -220,9 +220,7 @@ keyofAndIndexedAccess.ts(318,5): error TS2322: Type 'T[K]' is not assignable to } const b = "foo" in obj[key]; ~~~~~~~~ -!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'object'. -!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'object'. -!!! error TS2322: Type 'T[string]' is not assignable to type 'object'. +!!! error TS2533: Object is possibly 'null' or 'undefined'. } function f55(obj: T, key: K) { @@ -230,15 +228,16 @@ keyofAndIndexedAccess.ts(318,5): error TS2322: Type 'T[K]' is not assignable to } const b = "foo" in obj[key]; ~~~~~~~~ -!!! error TS2322: Type 'T[K]' is not assignable to type 'object'. -!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'object'. -!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'object'. -!!! error TS2322: Type 'T[string]' is not assignable to type 'object'. +!!! error TS2533: Object is possibly 'null' or 'undefined'. } function f60(source: T, target: T) { for (let k in source) { target[k] = source[k]; + ~~~~~~ +!!! error TS18049: 'target' is possibly 'null' or 'undefined'. + ~~~~~~~~~ +!!! error TS2536: Type 'Extract, string>' cannot be used to index type 'T'. } } @@ -599,6 +598,12 @@ keyofAndIndexedAccess.ts(318,5): error TS2322: Type 'T[K]' is not assignable to for (let key in t) { key = k // ok, K ==> keyof T t[key] = tk; // ok, T[K] ==> T[keyof T] + ~~~~~~ +!!! error TS2322: Type 'T[K]' is not assignable to type 'NonNullable[Extract, string>]'. +!!! error TS2322: Type 'T' is not assignable to type 'NonNullable'. +!!! error TS2322: Type 'T' is not assignable to type '{}'. +!!! related TS2208 keyofAndIndexedAccess.ts:563:13: This type parameter might need an `extends {}` constraint. +!!! related TS2208 keyofAndIndexedAccess.ts:563:13: This type parameter might need an `extends NonNullable` constraint. } } diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types index bd6545897debe..5089bc8ce06b6 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.types +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -1120,8 +1120,8 @@ function f54(obj: T, key: keyof T) { > : ^^^^^^^ for (let s in obj[key]) { ->s : Extract -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>s : Extract, string> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >obj[key] : T[keyof T] > : ^^^^^^^^^^ >obj : T @@ -1153,8 +1153,8 @@ function f55(obj: T, key: K) { > : ^ for (let s in obj[key]) { ->s : Extract -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>s : Extract, string> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >obj[key] : T[K] > : ^^^^ >obj : T @@ -1186,26 +1186,26 @@ function f60(source: T, target: T) { > : ^ for (let k in source) { ->k : Extract -> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>k : Extract, string> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >source : T > : ^ target[k] = source[k]; ->target[k] = source[k] : T[Extract] -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->target[k] : T[Extract] -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>target[k] = source[k] : NonNullable[Extract, string>] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>target[k] : any +> : ^^^ >target : T > : ^ ->k : Extract -> : ^^^^^^^^^^^^^^^^^^^^^^^^ ->source[k] : T[Extract] -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->source : T -> : ^ ->k : Extract -> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>k : Extract, string> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>source[k] : NonNullable[Extract, string>] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>source : NonNullable +> : ^^^^^^^^^^^^^^ +>k : Extract, string> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ } } @@ -3082,28 +3082,28 @@ function f3>(t: T, k: K, tk: T[K]): void { > : ^^^^ for (let key in t) { ->key : Extract -> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>key : Extract, string> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >t : T > : ^ key = k // ok, K ==> keyof T >key = k : K > : ^ ->key : Extract -> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>key : Extract, string> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >k : K > : ^ t[key] = tk; // ok, T[K] ==> T[keyof T] >t[key] = tk : T[K] > : ^^^^ ->t[key] : T[Extract] -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->t : T -> : ^ ->key : Extract -> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>t[key] : NonNullable[Extract, string>] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>t : NonNullable +> : ^^^^^^^^^^^^^^ +>key : Extract, string> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >tk : T[K] > : ^^^^ } diff --git a/tests/baselines/reference/mappedTypeRelationships.errors.txt b/tests/baselines/reference/mappedTypeRelationships.errors.txt index 1918a9532f32d..6f5f99ac11886 100644 --- a/tests/baselines/reference/mappedTypeRelationships.errors.txt +++ b/tests/baselines/reference/mappedTypeRelationships.errors.txt @@ -4,9 +4,15 @@ mappedTypeRelationships.ts(11,5): error TS2322: Type 'T[keyof T]' is not assigna mappedTypeRelationships.ts(16,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. Type 'T' is not assignable to type 'U'. 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'. -mappedTypeRelationships.ts(20,5): error TS2536: Type 'keyof U' cannot be used to index type 'T'. -mappedTypeRelationships.ts(21,12): error TS2536: Type 'keyof U' cannot be used to index type 'T'. +mappedTypeRelationships.ts(20,5): error TS18049: 'x' is possibly 'null' or 'undefined'. +mappedTypeRelationships.ts(20,5): error TS2536: Type 'keyof U' cannot be used to index type 'NonNullable'. +mappedTypeRelationships.ts(20,12): error TS18049: 'y' is possibly 'null' or 'undefined'. +mappedTypeRelationships.ts(21,5): error TS18049: 'y' is possibly 'null' or 'undefined'. +mappedTypeRelationships.ts(21,12): error TS18049: 'x' is possibly 'null' or 'undefined'. +mappedTypeRelationships.ts(21,12): error TS2536: Type 'keyof U' cannot be used to index type 'NonNullable'. +mappedTypeRelationships.ts(25,5): error TS18049: 'x' is possibly 'null' or 'undefined'. mappedTypeRelationships.ts(25,5): error TS2536: Type 'K' cannot be used to index type 'T'. +mappedTypeRelationships.ts(26,12): error TS18049: 'x' is possibly 'null' or 'undefined'. mappedTypeRelationships.ts(26,12): error TS2536: Type 'K' cannot be used to index type 'T'. mappedTypeRelationships.ts(30,5): error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'. 'T[keyof T]' could be instantiated with an arbitrary type which could be unrelated to 'T[keyof T] | undefined'. @@ -73,7 +79,7 @@ mappedTypeRelationships.ts(168,5): error TS2322: Type '{ [P in K]: T[P]; }' is n 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'. -==== mappedTypeRelationships.ts (28 errors) ==== +==== mappedTypeRelationships.ts (34 errors) ==== function f1(x: T, k: keyof T) { return x[k]; } @@ -104,18 +110,30 @@ mappedTypeRelationships.ts(168,5): error TS2322: Type '{ [P in K]: T[P]; }' is n function f5(x: T, y: U, k: keyof U) { x[k] = y[k]; // Error + ~ +!!! error TS18049: 'x' is possibly 'null' or 'undefined'. ~~~~ -!!! error TS2536: Type 'keyof U' cannot be used to index type 'T'. +!!! error TS2536: Type 'keyof U' cannot be used to index type 'NonNullable'. + ~ +!!! error TS18049: 'y' is possibly 'null' or 'undefined'. y[k] = x[k]; // Error + ~ +!!! error TS18049: 'y' is possibly 'null' or 'undefined'. + ~ +!!! error TS18049: 'x' is possibly 'null' or 'undefined'. ~~~~ -!!! error TS2536: Type 'keyof U' cannot be used to index type 'T'. +!!! error TS2536: Type 'keyof U' cannot be used to index type 'NonNullable'. } function f6(x: T, y: U, k: K) { x[k] = y[k]; // Error + ~ +!!! error TS18049: 'x' is possibly 'null' or 'undefined'. ~~~~ !!! error TS2536: Type 'K' cannot be used to index type 'T'. y[k] = x[k]; // Error + ~ +!!! error TS18049: 'x' is possibly 'null' or 'undefined'. ~~~~ !!! error TS2536: Type 'K' cannot be used to index type 'T'. } diff --git a/tests/baselines/reference/mappedTypeRelationships.types b/tests/baselines/reference/mappedTypeRelationships.types index ea45a0eb3041c..aa479b92808a5 100644 --- a/tests/baselines/reference/mappedTypeRelationships.types +++ b/tests/baselines/reference/mappedTypeRelationships.types @@ -132,16 +132,16 @@ function f5(x: T, y: U, k: keyof U) { > : ^^^^^^^ x[k] = y[k]; // Error ->x[k] = y[k] : U[keyof U] -> : ^^^^^^^^^^ +>x[k] = y[k] : NonNullable[keyof U] +> : ^^^^^^^^^^^^^^^^^^^^^^^ >x[k] : any > : ^^^ >x : T > : ^ >k : keyof U > : ^^^^^^^ ->y[k] : U[keyof U] -> : ^^^^^^^^^^ +>y[k] : NonNullable[keyof U] +> : ^^^^^^^^^^^^^^^^^^^^^^^ >y : U > : ^ >k : keyof U @@ -150,8 +150,8 @@ function f5(x: T, y: U, k: keyof U) { y[k] = x[k]; // Error >y[k] = x[k] : any > : ^^^ ->y[k] : U[keyof U] -> : ^^^^^^^^^^ +>y[k] : NonNullable[keyof U] +> : ^^^^^^^^^^^^^^^^^^^^^^^ >y : U > : ^ >k : keyof U diff --git a/tests/baselines/reference/testtestunconstrainedType.errors.txt b/tests/baselines/reference/testtestunconstrainedType.errors.txt new file mode 100644 index 0000000000000..5888678a07231 --- /dev/null +++ b/tests/baselines/reference/testtestunconstrainedType.errors.txt @@ -0,0 +1,13 @@ +testtestunconstrainedType.ts(6,5): error TS18049: 't' is possibly 'null' or 'undefined'. + + +==== testtestunconstrainedType.ts (1 errors) ==== + function f(obj: T, key: keyof T) { + return obj[key]; + } + + function ff3(t: T, k: keyof (T & {})) { + t[k]; + ~ +!!! error TS18049: 't' is possibly 'null' or 'undefined'. + } \ No newline at end of file diff --git a/tests/baselines/reference/testtestunconstrainedType.symbols b/tests/baselines/reference/testtestunconstrainedType.symbols new file mode 100644 index 0000000000000..894bdbccb8130 --- /dev/null +++ b/tests/baselines/reference/testtestunconstrainedType.symbols @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/testtestunconstrainedType.ts] //// + +=== testtestunconstrainedType.ts === +function f(obj: T, key: keyof T) { +>f : Symbol(f, Decl(testtestunconstrainedType.ts, 0, 0)) +>T : Symbol(T, Decl(testtestunconstrainedType.ts, 0, 11)) +>obj : Symbol(obj, Decl(testtestunconstrainedType.ts, 0, 14)) +>T : Symbol(T, Decl(testtestunconstrainedType.ts, 0, 11)) +>key : Symbol(key, Decl(testtestunconstrainedType.ts, 0, 21)) +>T : Symbol(T, Decl(testtestunconstrainedType.ts, 0, 11)) + + return obj[key]; +>obj : Symbol(obj, Decl(testtestunconstrainedType.ts, 0, 14)) +>key : Symbol(key, Decl(testtestunconstrainedType.ts, 0, 21)) +} + +function ff3(t: T, k: keyof (T & {})) { +>ff3 : Symbol(ff3, Decl(testtestunconstrainedType.ts, 2, 1)) +>T : Symbol(T, Decl(testtestunconstrainedType.ts, 4, 13)) +>t : Symbol(t, Decl(testtestunconstrainedType.ts, 4, 16)) +>T : Symbol(T, Decl(testtestunconstrainedType.ts, 4, 13)) +>k : Symbol(k, Decl(testtestunconstrainedType.ts, 4, 21)) +>T : Symbol(T, Decl(testtestunconstrainedType.ts, 4, 13)) + + t[k]; +>t : Symbol(t, Decl(testtestunconstrainedType.ts, 4, 16)) +>k : Symbol(k, Decl(testtestunconstrainedType.ts, 4, 21)) +} diff --git a/tests/baselines/reference/testtestunconstrainedType.types b/tests/baselines/reference/testtestunconstrainedType.types new file mode 100644 index 0000000000000..1018f933b5dcd --- /dev/null +++ b/tests/baselines/reference/testtestunconstrainedType.types @@ -0,0 +1,36 @@ +//// [tests/cases/compiler/testtestunconstrainedType.ts] //// + +=== testtestunconstrainedType.ts === +function f(obj: T, key: keyof T) { +>f : (obj: T, key: keyof T) => T[keyof T] +> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^ +>obj : T +> : ^ +>key : keyof T +> : ^^^^^^^ + + return obj[key]; +>obj[key] : T[keyof T] +> : ^^^^^^^^^^ +>obj : T +> : ^ +>key : keyof T +> : ^^^^^^^ +} + +function ff3(t: T, k: keyof (T & {})) { +>ff3 : (t: T, k: keyof (T & {})) => void +> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>t : T +> : ^ +>k : keyof (T & {}) +> : ^^^^^^^^^^^^^^ + + t[k]; +>t[k] : NonNullable[keyof (T & {})] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>t : T +> : ^ +>k : keyof (T & {}) +> : ^^^^^^^^^^^^^^ +} diff --git a/tests/baselines/reference/unconstrainedTypeComparisons.errors.txt b/tests/baselines/reference/unconstrainedTypeComparisons.errors.txt new file mode 100644 index 0000000000000..6f7646b9978fd --- /dev/null +++ b/tests/baselines/reference/unconstrainedTypeComparisons.errors.txt @@ -0,0 +1,46 @@ +unconstrainedTypeComparisons.ts(2,10): error TS18049: 'a' is possibly 'null' or 'undefined'. +unconstrainedTypeComparisons.ts(2,14): error TS18049: 'b' is possibly 'null' or 'undefined'. +unconstrainedTypeComparisons.ts(6,10): error TS18049: 'a' is possibly 'null' or 'undefined'. +unconstrainedTypeComparisons.ts(6,14): error TS18049: 'b' is possibly 'null' or 'undefined'. +unconstrainedTypeComparisons.ts(10,10): error TS18049: 'a' is possibly 'null' or 'undefined'. +unconstrainedTypeComparisons.ts(10,14): error TS18049: 'b' is possibly 'null' or 'undefined'. +unconstrainedTypeComparisons.ts(18,10): error TS18047: 'a' is possibly 'null'. +unconstrainedTypeComparisons.ts(18,14): error TS18049: 'b' is possibly 'null' or 'undefined'. + + +==== unconstrainedTypeComparisons.ts (8 errors) ==== + function f(a: T, b: T): boolean { + return a > b; + ~ +!!! error TS18049: 'a' is possibly 'null' or 'undefined'. + ~ +!!! error TS18049: 'b' is possibly 'null' or 'undefined'. + } + + function g(a: T, b: T): boolean { + return a > b; + ~ +!!! error TS18049: 'a' is possibly 'null' or 'undefined'. + ~ +!!! error TS18049: 'b' is possibly 'null' or 'undefined'. + } + + function h(a: T, b: T): boolean { + return a > b; + ~ +!!! error TS18049: 'a' is possibly 'null' or 'undefined'. + ~ +!!! error TS18049: 'b' is possibly 'null' or 'undefined'. + } + + function i(a: T, b: T): boolean { + if (a === undefined) { + return true; + } + + return a > b; + ~ +!!! error TS18047: 'a' is possibly 'null'. + ~ +!!! error TS18049: 'b' is possibly 'null' or 'undefined'. + } \ No newline at end of file diff --git a/tests/baselines/reference/unconstrainedTypeComparisons.symbols b/tests/baselines/reference/unconstrainedTypeComparisons.symbols new file mode 100644 index 0000000000000..9cf094ffc65b7 --- /dev/null +++ b/tests/baselines/reference/unconstrainedTypeComparisons.symbols @@ -0,0 +1,61 @@ +//// [tests/cases/compiler/unconstrainedTypeComparisons.ts] //// + +=== unconstrainedTypeComparisons.ts === +function f(a: T, b: T): boolean { +>f : Symbol(f, Decl(unconstrainedTypeComparisons.ts, 0, 0)) +>T : Symbol(T, Decl(unconstrainedTypeComparisons.ts, 0, 11)) +>a : Symbol(a, Decl(unconstrainedTypeComparisons.ts, 0, 44)) +>T : Symbol(T, Decl(unconstrainedTypeComparisons.ts, 0, 11)) +>b : Symbol(b, Decl(unconstrainedTypeComparisons.ts, 0, 49)) +>T : Symbol(T, Decl(unconstrainedTypeComparisons.ts, 0, 11)) + + return a > b; +>a : Symbol(a, Decl(unconstrainedTypeComparisons.ts, 0, 44)) +>b : Symbol(b, Decl(unconstrainedTypeComparisons.ts, 0, 49)) +} + +function g(a: T, b: T): boolean { +>g : Symbol(g, Decl(unconstrainedTypeComparisons.ts, 2, 1)) +>T : Symbol(T, Decl(unconstrainedTypeComparisons.ts, 4, 11)) +>a : Symbol(a, Decl(unconstrainedTypeComparisons.ts, 4, 14)) +>T : Symbol(T, Decl(unconstrainedTypeComparisons.ts, 4, 11)) +>b : Symbol(b, Decl(unconstrainedTypeComparisons.ts, 4, 19)) +>T : Symbol(T, Decl(unconstrainedTypeComparisons.ts, 4, 11)) + + return a > b; +>a : Symbol(a, Decl(unconstrainedTypeComparisons.ts, 4, 14)) +>b : Symbol(b, Decl(unconstrainedTypeComparisons.ts, 4, 19)) +} + +function h(a: T, b: T): boolean { +>h : Symbol(h, Decl(unconstrainedTypeComparisons.ts, 6, 1)) +>T : Symbol(T, Decl(unconstrainedTypeComparisons.ts, 8, 11)) +>a : Symbol(a, Decl(unconstrainedTypeComparisons.ts, 8, 30)) +>T : Symbol(T, Decl(unconstrainedTypeComparisons.ts, 8, 11)) +>b : Symbol(b, Decl(unconstrainedTypeComparisons.ts, 8, 35)) +>T : Symbol(T, Decl(unconstrainedTypeComparisons.ts, 8, 11)) + + return a > b; +>a : Symbol(a, Decl(unconstrainedTypeComparisons.ts, 8, 30)) +>b : Symbol(b, Decl(unconstrainedTypeComparisons.ts, 8, 35)) +} + +function i(a: T, b: T): boolean { +>i : Symbol(i, Decl(unconstrainedTypeComparisons.ts, 10, 1)) +>T : Symbol(T, Decl(unconstrainedTypeComparisons.ts, 12, 11)) +>a : Symbol(a, Decl(unconstrainedTypeComparisons.ts, 12, 14)) +>T : Symbol(T, Decl(unconstrainedTypeComparisons.ts, 12, 11)) +>b : Symbol(b, Decl(unconstrainedTypeComparisons.ts, 12, 19)) +>T : Symbol(T, Decl(unconstrainedTypeComparisons.ts, 12, 11)) + + if (a === undefined) { +>a : Symbol(a, Decl(unconstrainedTypeComparisons.ts, 12, 14)) +>undefined : Symbol(undefined) + + return true; + } + + return a > b; +>a : Symbol(a, Decl(unconstrainedTypeComparisons.ts, 12, 14)) +>b : Symbol(b, Decl(unconstrainedTypeComparisons.ts, 12, 19)) +} diff --git a/tests/baselines/reference/unconstrainedTypeComparisons.types b/tests/baselines/reference/unconstrainedTypeComparisons.types new file mode 100644 index 0000000000000..c486c9bb293c4 --- /dev/null +++ b/tests/baselines/reference/unconstrainedTypeComparisons.types @@ -0,0 +1,83 @@ +//// [tests/cases/compiler/unconstrainedTypeComparisons.ts] //// + +=== unconstrainedTypeComparisons.ts === +function f(a: T, b: T): boolean { +>f : (a: T, b: T) => boolean +> : ^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^ +>a : T +> : ^ +>b : T +> : ^ + + return a > b; +>a > b : boolean +> : ^^^^^^^ +>a : T +> : ^ +>b : T +> : ^ +} + +function g(a: T, b: T): boolean { +>g : (a: T, b: T) => boolean +> : ^ ^^ ^^ ^^ ^^ ^^^^^ +>a : T +> : ^ +>b : T +> : ^ + + return a > b; +>a > b : boolean +> : ^^^^^^^ +>a : T +> : ^ +>b : T +> : ^ +} + +function h(a: T, b: T): boolean { +>h : (a: T, b: T) => boolean +> : ^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^ +>a : T +> : ^ +>b : T +> : ^ + + return a > b; +>a > b : boolean +> : ^^^^^^^ +>a : T +> : ^ +>b : T +> : ^ +} + +function i(a: T, b: T): boolean { +>i : (a: T, b: T) => boolean +> : ^ ^^ ^^ ^^ ^^ ^^^^^ +>a : T +> : ^ +>b : T +> : ^ + + if (a === undefined) { +>a === undefined : boolean +> : ^^^^^^^ +>a : T +> : ^ +>undefined : undefined +> : ^^^^^^^^^ + + return true; +>true : true +> : ^^^^ + } + + return a > b; +>a > b : boolean +> : ^^^^^^^ +>a : T & ({} | null) +> : ^^^^^^^^^^^^^^^ +>b : T +> : ^ +} diff --git a/tests/baselines/reference/unconstrainedTypeKeyofParam.errors.txt b/tests/baselines/reference/unconstrainedTypeKeyofParam.errors.txt new file mode 100644 index 0000000000000..4efa0f5f4912b --- /dev/null +++ b/tests/baselines/reference/unconstrainedTypeKeyofParam.errors.txt @@ -0,0 +1,195 @@ +unconstrainedTypeKeyofParam.ts(1,10): error TS2393: Duplicate function implementation. +unconstrainedTypeKeyofParam.ts(3,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. + Type 'T' is not assignable to type 'U'. + 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'. +unconstrainedTypeKeyofParam.ts(14,10): error TS2393: Duplicate function implementation. +unconstrainedTypeKeyofParam.ts(36,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeKeyofParam.ts(36,12): error TS2536: Type 'keyof T' cannot be used to index type '{}'. +unconstrainedTypeKeyofParam.ts(40,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeKeyofParam.ts(44,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeKeyofParam.ts(48,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeKeyofParam.ts(48,12): error TS2536: Type 'keyof U' cannot be used to index type '{}'. +unconstrainedTypeKeyofParam.ts(52,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeKeyofParam.ts(93,10): error TS2393: Duplicate function implementation. +unconstrainedTypeKeyofParam.ts(97,10): error TS2393: Duplicate function implementation. +unconstrainedTypeKeyofParam.ts(98,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeKeyofParam.ts(98,12): error TS2536: Type 'keyof T' cannot be used to index type '{}'. +unconstrainedTypeKeyofParam.ts(101,10): error TS2393: Duplicate function implementation. +unconstrainedTypeKeyofParam.ts(102,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeKeyofParam.ts(107,10): error TS2393: Duplicate function implementation. +unconstrainedTypeKeyofParam.ts(108,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeKeyofParam.ts(111,10): error TS2393: Duplicate function implementation. +unconstrainedTypeKeyofParam.ts(112,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeKeyofParam.ts(112,12): error TS2536: Type 'keyof U' cannot be used to index type '{}'. +unconstrainedTypeKeyofParam.ts(115,10): error TS2393: Duplicate function implementation. +unconstrainedTypeKeyofParam.ts(116,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. + + +==== unconstrainedTypeKeyofParam.ts (23 errors) ==== + function f3(x: T, y: U, k: keyof T) { + ~~ +!!! error TS2393: Duplicate function implementation. + x[k] = y[k]; + y[k] = x[k]; + ~~~~ +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'. +!!! related TS2208 unconstrainedTypeKeyofParam.ts:1:13: This type parameter might need an `extends U` constraint. + } + + function f(obj: T, key: K) { + return obj[key]; + } + + function f2(obj: T, key: K) { + return obj[key]; + } + + function f3(obj: T, key: K) { + ~~ +!!! error TS2393: Duplicate function implementation. + return obj[key]; + } + + function f4(obj: U, key: K) { + return obj[key]; + } + + function f5(obj: U, key: K) { + return obj[key]; + } + + function f6(obj: U, key: K) { + return obj[key]; + } + + // ************ + function g1(obj: T, key: keyof T) { + return obj[key]; + } + + function g2(obj: T, key: keyof T) { + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + ~~~~~~~~ +!!! error TS2536: Type 'keyof T' cannot be used to index type '{}'. + } + + function g3(obj: T, key: keyof T) { + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + } + + function g4(obj: U, key: keyof U) { + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + } + + function g5(obj: U, key: keyof U) { + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + ~~~~~~~~ +!!! error TS2536: Type 'keyof U' cannot be used to index type '{}'. + } + + function g6(obj: U, key: keyof U) { + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + } + + // ************** + function h1(obj: T, other: T, key: K) { + obj[key]; + other[key]; + return; + } + + function h2(obj: T, other: T, key: K) { + obj[key]; + other[key]; + return;} + + function h3(obj: T, other: T, key: K) { + obj[key]; + other[key]; + return; + } + + // ************** + function i1(obj: T, other: U, key: K) { + obj[key]; + other[key]; + return; + } + + function i2(obj: T, other: U, key: K) { + obj[key]; + other[key]; + return;} + + function i3(obj: T, other: U, key: K) { + obj[key]; + other[key]; + return; + } + + + // ************ + function j1(obj: U, key: keyof T) { + ~~ +!!! error TS2393: Duplicate function implementation. + return obj[key]; + } + + function j2(obj: U, key: keyof T) { + ~~ +!!! error TS2393: Duplicate function implementation. + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + ~~~~~~~~ +!!! error TS2536: Type 'keyof T' cannot be used to index type '{}'. + } + + function j3(obj: U, key: keyof T) { + ~~ +!!! error TS2393: Duplicate function implementation. + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + } + + + // ************ + function j1(obj: U, key: keyof U) { + ~~ +!!! error TS2393: Duplicate function implementation. + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + } + + function j2(obj: U, key: keyof U) { + ~~ +!!! error TS2393: Duplicate function implementation. + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + ~~~~~~~~ +!!! error TS2536: Type 'keyof U' cannot be used to index type '{}'. + } + + function j3(obj: U, key: keyof U) { + ~~ +!!! error TS2393: Duplicate function implementation. + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/unconstrainedTypeKeyofParam.symbols b/tests/baselines/reference/unconstrainedTypeKeyofParam.symbols new file mode 100644 index 0000000000000..3ab20d2ddaded --- /dev/null +++ b/tests/baselines/reference/unconstrainedTypeKeyofParam.symbols @@ -0,0 +1,447 @@ +//// [tests/cases/compiler/unconstrainedTypeKeyofParam.ts] //// + +=== unconstrainedTypeKeyofParam.ts === +function f3(x: T, y: U, k: keyof T) { +>f3 : Symbol(f3, Decl(unconstrainedTypeKeyofParam.ts, 0, 0), Decl(unconstrainedTypeKeyofParam.ts, 11, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 0, 12)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 0, 14)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 0, 12)) +>x : Symbol(x, Decl(unconstrainedTypeKeyofParam.ts, 0, 28)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 0, 12)) +>y : Symbol(y, Decl(unconstrainedTypeKeyofParam.ts, 0, 33)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 0, 14)) +>k : Symbol(k, Decl(unconstrainedTypeKeyofParam.ts, 0, 39)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 0, 12)) + + x[k] = y[k]; +>x : Symbol(x, Decl(unconstrainedTypeKeyofParam.ts, 0, 28)) +>k : Symbol(k, Decl(unconstrainedTypeKeyofParam.ts, 0, 39)) +>y : Symbol(y, Decl(unconstrainedTypeKeyofParam.ts, 0, 33)) +>k : Symbol(k, Decl(unconstrainedTypeKeyofParam.ts, 0, 39)) + + y[k] = x[k]; +>y : Symbol(y, Decl(unconstrainedTypeKeyofParam.ts, 0, 33)) +>k : Symbol(k, Decl(unconstrainedTypeKeyofParam.ts, 0, 39)) +>x : Symbol(x, Decl(unconstrainedTypeKeyofParam.ts, 0, 28)) +>k : Symbol(k, Decl(unconstrainedTypeKeyofParam.ts, 0, 39)) +} + +function f(obj: T, key: K) { +>f : Symbol(f, Decl(unconstrainedTypeKeyofParam.ts, 3, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 5, 11)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 5, 13)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 5, 11)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 5, 33)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 5, 11)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 5, 40)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 5, 13)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 5, 33)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 5, 40)) +} + +function f2(obj: T, key: K) { +>f2 : Symbol(f2, Decl(unconstrainedTypeKeyofParam.ts, 7, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 9, 12)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 9, 45)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 9, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 9, 65)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 9, 12)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 9, 72)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 9, 45)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 9, 65)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 9, 72)) +} + +function f3(obj: T, key: K) { +>f3 : Symbol(f3, Decl(unconstrainedTypeKeyofParam.ts, 0, 0), Decl(unconstrainedTypeKeyofParam.ts, 11, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 13, 12)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 13, 30)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 13, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 13, 50)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 13, 12)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 13, 57)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 13, 30)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 13, 50)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 13, 57)) +} + +function f4(obj: U, key: K) { +>f4 : Symbol(f4, Decl(unconstrainedTypeKeyofParam.ts, 15, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 17, 12)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 17, 14)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 17, 12)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 17, 27)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 17, 14)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 17, 47)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 17, 14)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 17, 54)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 17, 27)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 17, 47)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 17, 54)) +} + +function f5(obj: U, key: K) { +>f5 : Symbol(f5, Decl(unconstrainedTypeKeyofParam.ts, 19, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 21, 12)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 21, 44)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 21, 12)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 21, 57)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 21, 44)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 21, 77)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 21, 44)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 21, 84)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 21, 57)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 21, 77)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 21, 84)) +} + +function f6(obj: U, key: K) { +>f6 : Symbol(f6, Decl(unconstrainedTypeKeyofParam.ts, 23, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 25, 12)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 25, 30)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 25, 12)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 25, 43)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 25, 30)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 25, 63)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 25, 30)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 25, 70)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 25, 43)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 25, 63)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 25, 70)) +} + +// ************ +function g1(obj: T, key: keyof T) { +>g1 : Symbol(g1, Decl(unconstrainedTypeKeyofParam.ts, 27, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 30, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 30, 15)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 30, 12)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 30, 22)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 30, 12)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 30, 15)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 30, 22)) +} + +function g2(obj: T, key: keyof T) { +>g2 : Symbol(g2, Decl(unconstrainedTypeKeyofParam.ts, 32, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 34, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 34, 45)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 34, 12)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 34, 52)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 34, 12)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 34, 45)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 34, 52)) +} + +function g3(obj: T, key: keyof T) { +>g3 : Symbol(g3, Decl(unconstrainedTypeKeyofParam.ts, 36, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 38, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 38, 31)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 38, 12)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 38, 38)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 38, 12)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 38, 31)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 38, 38)) +} + +function g4(obj: U, key: keyof U) { +>g4 : Symbol(g4, Decl(unconstrainedTypeKeyofParam.ts, 40, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 42, 12)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 42, 14)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 42, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 42, 28)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 42, 14)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 42, 35)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 42, 14)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 42, 28)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 42, 35)) +} + +function g5(obj: U, key: keyof U) { +>g5 : Symbol(g5, Decl(unconstrainedTypeKeyofParam.ts, 44, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 46, 12)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 46, 44)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 46, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 46, 58)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 46, 44)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 46, 65)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 46, 44)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 46, 58)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 46, 65)) +} + +function g6(obj: U, key: keyof U) { +>g6 : Symbol(g6, Decl(unconstrainedTypeKeyofParam.ts, 48, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 50, 12)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 50, 30)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 50, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 50, 44)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 50, 30)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 50, 51)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 50, 30)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 50, 44)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 50, 51)) +} + +// ************** +function h1(obj: T, other: T, key: K) { +>h1 : Symbol(h1, Decl(unconstrainedTypeKeyofParam.ts, 52, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 55, 12)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 55, 14)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 55, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 55, 34)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 55, 12)) +>other : Symbol(other, Decl(unconstrainedTypeKeyofParam.ts, 55, 41)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 55, 12)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 55, 51)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 55, 14)) + + obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 55, 34)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 55, 51)) + + other[key]; +>other : Symbol(other, Decl(unconstrainedTypeKeyofParam.ts, 55, 41)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 55, 51)) + + return; +} + +function h2(obj: T, other: T, key: K) { +>h2 : Symbol(h2, Decl(unconstrainedTypeKeyofParam.ts, 59, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 61, 12)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 61, 45)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 61, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 61, 65)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 61, 12)) +>other : Symbol(other, Decl(unconstrainedTypeKeyofParam.ts, 61, 72)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 61, 12)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 61, 82)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 61, 45)) + + obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 61, 65)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 61, 82)) + + other[key]; +>other : Symbol(other, Decl(unconstrainedTypeKeyofParam.ts, 61, 72)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 61, 82)) + + return;} + +function h3(obj: T, other: T, key: K) { +>h3 : Symbol(h3, Decl(unconstrainedTypeKeyofParam.ts, 64, 12)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 66, 12)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 66, 30)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 66, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 66, 50)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 66, 12)) +>other : Symbol(other, Decl(unconstrainedTypeKeyofParam.ts, 66, 57)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 66, 12)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 66, 67)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 66, 30)) + + obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 66, 50)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 66, 67)) + + other[key]; +>other : Symbol(other, Decl(unconstrainedTypeKeyofParam.ts, 66, 57)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 66, 67)) + + return; +} + +// ************** +function i1(obj: T, other: U, key: K) { +>i1 : Symbol(i1, Decl(unconstrainedTypeKeyofParam.ts, 70, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 73, 12)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 73, 14)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 73, 12)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 73, 27)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 73, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 73, 47)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 73, 12)) +>other : Symbol(other, Decl(unconstrainedTypeKeyofParam.ts, 73, 54)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 73, 14)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 73, 64)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 73, 27)) + + obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 73, 47)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 73, 64)) + + other[key]; +>other : Symbol(other, Decl(unconstrainedTypeKeyofParam.ts, 73, 54)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 73, 64)) + + return; +} + +function i2(obj: T, other: U, key: K) { +>i2 : Symbol(i2, Decl(unconstrainedTypeKeyofParam.ts, 77, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 79, 12)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 79, 45)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 79, 12)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 79, 58)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 79, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 79, 78)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 79, 12)) +>other : Symbol(other, Decl(unconstrainedTypeKeyofParam.ts, 79, 85)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 79, 45)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 79, 95)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 79, 58)) + + obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 79, 78)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 79, 95)) + + other[key]; +>other : Symbol(other, Decl(unconstrainedTypeKeyofParam.ts, 79, 85)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 79, 95)) + + return;} + +function i3(obj: T, other: U, key: K) { +>i3 : Symbol(i3, Decl(unconstrainedTypeKeyofParam.ts, 82, 12)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 84, 12)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 84, 30)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 84, 12)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 84, 43)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 84, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 84, 63)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 84, 12)) +>other : Symbol(other, Decl(unconstrainedTypeKeyofParam.ts, 84, 70)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 84, 30)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 84, 80)) +>K : Symbol(K, Decl(unconstrainedTypeKeyofParam.ts, 84, 43)) + + obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 84, 63)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 84, 80)) + + other[key]; +>other : Symbol(other, Decl(unconstrainedTypeKeyofParam.ts, 84, 70)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 84, 80)) + + return; +} + + +// ************ +function j1(obj: U, key: keyof T) { +>j1 : Symbol(j1, Decl(unconstrainedTypeKeyofParam.ts, 88, 1), Decl(unconstrainedTypeKeyofParam.ts, 102, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 92, 12)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 92, 14)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 92, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 92, 28)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 92, 14)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 92, 35)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 92, 12)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 92, 28)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 92, 35)) +} + +function j2(obj: U, key: keyof T) { +>j2 : Symbol(j2, Decl(unconstrainedTypeKeyofParam.ts, 94, 1), Decl(unconstrainedTypeKeyofParam.ts, 108, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 96, 12)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 96, 44)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 96, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 96, 58)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 96, 44)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 96, 65)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 96, 12)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 96, 58)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 96, 65)) +} + +function j3(obj: U, key: keyof T) { +>j3 : Symbol(j3, Decl(unconstrainedTypeKeyofParam.ts, 98, 1), Decl(unconstrainedTypeKeyofParam.ts, 112, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 100, 12)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 100, 30)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 100, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 100, 44)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 100, 30)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 100, 51)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 100, 12)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 100, 44)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 100, 51)) +} + + +// ************ +function j1(obj: U, key: keyof U) { +>j1 : Symbol(j1, Decl(unconstrainedTypeKeyofParam.ts, 88, 1), Decl(unconstrainedTypeKeyofParam.ts, 102, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 106, 12)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 106, 14)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 106, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 106, 28)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 106, 14)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 106, 35)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 106, 14)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 106, 28)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 106, 35)) +} + +function j2(obj: U, key: keyof U) { +>j2 : Symbol(j2, Decl(unconstrainedTypeKeyofParam.ts, 94, 1), Decl(unconstrainedTypeKeyofParam.ts, 108, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 110, 12)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 110, 44)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 110, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 110, 58)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 110, 44)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 110, 65)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 110, 44)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 110, 58)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 110, 65)) +} + +function j3(obj: U, key: keyof U) { +>j3 : Symbol(j3, Decl(unconstrainedTypeKeyofParam.ts, 98, 1), Decl(unconstrainedTypeKeyofParam.ts, 112, 1)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 114, 12)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 114, 30)) +>T : Symbol(T, Decl(unconstrainedTypeKeyofParam.ts, 114, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 114, 44)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 114, 30)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 114, 51)) +>U : Symbol(U, Decl(unconstrainedTypeKeyofParam.ts, 114, 30)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeKeyofParam.ts, 114, 44)) +>key : Symbol(key, Decl(unconstrainedTypeKeyofParam.ts, 114, 51)) +} + diff --git a/tests/baselines/reference/unconstrainedTypeKeyofParam.types b/tests/baselines/reference/unconstrainedTypeKeyofParam.types new file mode 100644 index 0000000000000..a8d539d23e086 --- /dev/null +++ b/tests/baselines/reference/unconstrainedTypeKeyofParam.types @@ -0,0 +1,531 @@ +//// [tests/cases/compiler/unconstrainedTypeKeyofParam.ts] //// + +=== unconstrainedTypeKeyofParam.ts === +function f3(x: T, y: U, k: keyof T) { +>f3 : { (x: T, y: U, k: keyof T): void; (obj: T_1, key: K): T_1[K]; } +> : ^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^ +>x : T +> : ^ +>y : U +> : ^ +>k : keyof T +> : ^^^^^^^ + + x[k] = y[k]; +>x[k] = y[k] : U[keyof T] +> : ^^^^^^^^^^ +>x[k] : T[keyof T] +> : ^^^^^^^^^^ +>x : T +> : ^ +>k : keyof T +> : ^^^^^^^ +>y[k] : U[keyof T] +> : ^^^^^^^^^^ +>y : U +> : ^ +>k : keyof T +> : ^^^^^^^ + + y[k] = x[k]; +>y[k] = x[k] : T[keyof T] +> : ^^^^^^^^^^ +>y[k] : U[keyof T] +> : ^^^^^^^^^^ +>y : U +> : ^ +>k : keyof T +> : ^^^^^^^ +>x[k] : T[keyof T] +> : ^^^^^^^^^^ +>x : T +> : ^ +>k : keyof T +> : ^^^^^^^ +} + +function f(obj: T, key: K) { +>f : (obj: T, key: K) => T[K] +> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : T +> : ^ +>key : K +> : ^ + + return obj[key]; +>obj[key] : T[K] +> : ^^^^ +>obj : T +> : ^ +>key : K +> : ^ +} + +function f2(obj: T, key: K) { +>f2 : (obj: T, key: K) => {} | null | undefined +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : T +> : ^ +>key : K +> : ^ + + return obj[key]; +>obj[key] : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>obj : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : K +> : ^ +} + +function f3(obj: T, key: K) { +>f3 : { (x: T_1, y: U, k: keyof T_1): void; (obj: T, key: K): T[K]; } +> : ^^^^^^^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^ +>obj : T +> : ^ +>key : K +> : ^ + + return obj[key]; +>obj[key] : T[K] +> : ^^^^ +>obj : T +> : ^ +>key : K +> : ^ +} + +function f4(obj: U, key: K) { +>f4 : (obj: U, key: K) => U[K] +> : ^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : U +> : ^ +>key : K +> : ^ + + return obj[key]; +>obj[key] : U[K] +> : ^^^^ +>obj : U +> : ^ +>key : K +> : ^ +} + +function f5(obj: U, key: K) { +>f5 : (obj: U, key: K) => {} | null | undefined +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : K +> : ^ + + return obj[key]; +>obj[key] : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>obj : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : K +> : ^ +} + +function f6(obj: U, key: K) { +>f6 : (obj: U, key: K) => U[K] +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : U +> : ^ +>key : K +> : ^ + + return obj[key]; +>obj[key] : U[K] +> : ^^^^ +>obj : U +> : ^ +>key : K +> : ^ +} + +// ************ +function g1(obj: T, key: keyof T) { +>g1 : (obj: T, key: keyof T) => T[keyof T] +> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^ +>obj : T +> : ^ +>key : keyof T +> : ^^^^^^^ + + return obj[key]; +>obj[key] : T[keyof T] +> : ^^^^^^^^^^ +>obj : T +> : ^ +>key : keyof T +> : ^^^^^^^ +} + +function g2(obj: T, key: keyof T) { +>g2 : (obj: T, key: keyof T) => any +> : ^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^ +>obj : T +> : ^ +>key : keyof T +> : ^^^^^^^ + + return obj[key]; +>obj[key] : any +> : ^^^ +>obj : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : keyof T +> : ^^^^^^^ +} + +function g3(obj: T, key: keyof T) { +>g3 : (obj: T, key: keyof T) => NonNullable[keyof T] +> : ^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : T +> : ^ +>key : keyof T +> : ^^^^^^^ + + return obj[key]; +>obj[key] : NonNullable[keyof T] +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>obj : T +> : ^ +>key : keyof T +> : ^^^^^^^ +} + +function g4(obj: U, key: keyof U) { +>g4 : (obj: U, key: keyof U) => NonNullable[keyof U] +> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ + + return obj[key]; +>obj[key] : NonNullable[keyof U] +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ +} + +function g5(obj: U, key: keyof U) { +>g5 : (obj: U, key: keyof U) => any +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ + + return obj[key]; +>obj[key] : any +> : ^^^ +>obj : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : keyof U +> : ^^^^^^^ +} + +function g6(obj: U, key: keyof U) { +>g6 : (obj: U, key: keyof U) => NonNullable[keyof U] +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ + + return obj[key]; +>obj[key] : NonNullable[keyof U] +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ +} + +// ************** +function h1(obj: T, other: T, key: K) { +>h1 : (obj: T, other: T, key: K) => void +> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : T +> : ^ +>other : T +> : ^ +>key : K +> : ^ + + obj[key]; +>obj[key] : T[K] +> : ^^^^ +>obj : T +> : ^ +>key : K +> : ^ + + other[key]; +>other[key] : T[K] +> : ^^^^ +>other : T +> : ^ +>key : K +> : ^ + + return; +} + +function h2(obj: T, other: T, key: K) { +>h2 : (obj: T, other: T, key: K) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : T +> : ^ +>other : T +> : ^ +>key : K +> : ^ + + obj[key]; +>obj[key] : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>obj : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : K +> : ^ + + other[key]; +>other[key] : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>other : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : K +> : ^ + + return;} + +function h3(obj: T, other: T, key: K) { +>h3 : (obj: T, other: T, key: K) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : T +> : ^ +>other : T +> : ^ +>key : K +> : ^ + + obj[key]; +>obj[key] : T[K] +> : ^^^^ +>obj : T +> : ^ +>key : K +> : ^ + + other[key]; +>other[key] : T[K] +> : ^^^^ +>other : T +> : ^ +>key : K +> : ^ + + return; +} + +// ************** +function i1(obj: T, other: U, key: K) { +>i1 : (obj: T, other: U, key: K) => void +> : ^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : T +> : ^ +>other : U +> : ^ +>key : K +> : ^ + + obj[key]; +>obj[key] : T[K] +> : ^^^^ +>obj : T +> : ^ +>key : K +> : ^ + + other[key]; +>other[key] : U[K] +> : ^^^^ +>other : U +> : ^ +>key : K +> : ^ + + return; +} + +function i2(obj: T, other: U, key: K) { +>i2 : (obj: T, other: U, key: K) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : T +> : ^ +>other : U +> : ^ +>key : K +> : ^ + + obj[key]; +>obj[key] : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>obj : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : K +> : ^ + + other[key]; +>other[key] : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>other : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : K +> : ^ + + return;} + +function i3(obj: T, other: U, key: K) { +>i3 : (obj: T, other: U, key: K) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : T +> : ^ +>other : U +> : ^ +>key : K +> : ^ + + obj[key]; +>obj[key] : T[K] +> : ^^^^ +>obj : T +> : ^ +>key : K +> : ^ + + other[key]; +>other[key] : U[K] +> : ^^^^ +>other : U +> : ^ +>key : K +> : ^ + + return; +} + + +// ************ +function j1(obj: U, key: keyof T) { +>j1 : { (obj: U, key: keyof T): U[keyof T]; (obj: U_1, key: keyof U_1): NonNullable[keyof U_1]; } +> : ^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof T +> : ^^^^^^^ + + return obj[key]; +>obj[key] : U[keyof T] +> : ^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof T +> : ^^^^^^^ +} + +function j2(obj: U, key: keyof T) { +>j2 : { (obj: U, key: keyof T): any; (obj: U_1, key: keyof U_1): any; } +> : ^^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : U +> : ^ +>key : keyof T +> : ^^^^^^^ + + return obj[key]; +>obj[key] : any +> : ^^^ +>obj : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : keyof T +> : ^^^^^^^ +} + +function j3(obj: U, key: keyof T) { +>j3 : { (obj: U, key: keyof T): NonNullable[keyof T]; (obj: U_1, key: keyof U_1): NonNullable[keyof U_1]; } +> : ^^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof T +> : ^^^^^^^ + + return obj[key]; +>obj[key] : NonNullable[keyof T] +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof T +> : ^^^^^^^ +} + + +// ************ +function j1(obj: U, key: keyof U) { +>j1 : { (obj: U_1, key: keyof T_1): U_1[keyof T_1]; (obj: U, key: keyof U): NonNullable[keyof U]; } +> : ^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ + + return obj[key]; +>obj[key] : NonNullable[keyof U] +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ +} + +function j2(obj: U, key: keyof U) { +>j2 : { (obj: U_1, key: keyof T_1): any; (obj: U, key: keyof U): any; } +> : ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ + + return obj[key]; +>obj[key] : any +> : ^^^ +>obj : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : keyof U +> : ^^^^^^^ +} + +function j3(obj: U, key: keyof U) { +>j3 : { (obj: U_1, key: keyof T_1): NonNullable[keyof T_1]; (obj: U, key: keyof U): NonNullable[keyof U]; } +> : ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ + + return obj[key]; +>obj[key] : NonNullable[keyof U] +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ +} + diff --git a/tests/baselines/reference/unconstrainedTypeMapped.errors.txt b/tests/baselines/reference/unconstrainedTypeMapped.errors.txt new file mode 100644 index 0000000000000..f73bb81ecd215 --- /dev/null +++ b/tests/baselines/reference/unconstrainedTypeMapped.errors.txt @@ -0,0 +1,195 @@ +unconstrainedTypeMapped.ts(1,10): error TS2393: Duplicate function implementation. +unconstrainedTypeMapped.ts(3,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. + Type 'T' is not assignable to type 'U'. + 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'. +unconstrainedTypeMapped.ts(14,10): error TS2393: Duplicate function implementation. +unconstrainedTypeMapped.ts(36,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeMapped.ts(36,12): error TS2536: Type 'keyof T' cannot be used to index type '{}'. +unconstrainedTypeMapped.ts(40,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeMapped.ts(44,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeMapped.ts(48,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeMapped.ts(48,12): error TS2536: Type 'keyof U' cannot be used to index type '{}'. +unconstrainedTypeMapped.ts(52,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeMapped.ts(93,10): error TS2393: Duplicate function implementation. +unconstrainedTypeMapped.ts(97,10): error TS2393: Duplicate function implementation. +unconstrainedTypeMapped.ts(98,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeMapped.ts(98,12): error TS2536: Type 'keyof T' cannot be used to index type '{}'. +unconstrainedTypeMapped.ts(101,10): error TS2393: Duplicate function implementation. +unconstrainedTypeMapped.ts(102,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeMapped.ts(107,10): error TS2393: Duplicate function implementation. +unconstrainedTypeMapped.ts(108,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeMapped.ts(111,10): error TS2393: Duplicate function implementation. +unconstrainedTypeMapped.ts(112,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. +unconstrainedTypeMapped.ts(112,12): error TS2536: Type 'keyof U' cannot be used to index type '{}'. +unconstrainedTypeMapped.ts(115,10): error TS2393: Duplicate function implementation. +unconstrainedTypeMapped.ts(116,12): error TS18049: 'obj' is possibly 'null' or 'undefined'. + + +==== unconstrainedTypeMapped.ts (23 errors) ==== + function f3(x: T, y: U, k: keyof T) { + ~~ +!!! error TS2393: Duplicate function implementation. + x[k] = y[k]; + y[k] = x[k]; + ~~~~ +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'. +!!! related TS2208 unconstrainedTypeMapped.ts:1:13: This type parameter might need an `extends U` constraint. + } + + function f(obj: T, key: K) { + return obj[key]; + } + + function f2(obj: T, key: K) { + return obj[key]; + } + + function f3(obj: T, key: K) { + ~~ +!!! error TS2393: Duplicate function implementation. + return obj[key]; + } + + function f4(obj: U, key: K) { + return obj[key]; + } + + function f5(obj: U, key: K) { + return obj[key]; + } + + function f6(obj: U, key: K) { + return obj[key]; + } + + // ************ + function g1(obj: T, key: keyof T) { + return obj[key]; + } + + function g2(obj: T, key: keyof T) { + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + ~~~~~~~~ +!!! error TS2536: Type 'keyof T' cannot be used to index type '{}'. + } + + function g3(obj: T, key: keyof T) { + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + } + + function g4(obj: U, key: keyof U) { + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + } + + function g5(obj: U, key: keyof U) { + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + ~~~~~~~~ +!!! error TS2536: Type 'keyof U' cannot be used to index type '{}'. + } + + function g6(obj: U, key: keyof U) { + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + } + + // ************** + function h1(obj: T, other: T, key: K) { + obj[key]; + other[key]; + return; + } + + function h2(obj: T, other: T, key: K) { + obj[key]; + other[key]; + return;} + + function h3(obj: T, other: T, key: K) { + obj[key]; + other[key]; + return; + } + + // ************** + function i1(obj: T, other: U, key: K) { + obj[key]; + other[key]; + return; + } + + function i2(obj: T, other: U, key: K) { + obj[key]; + other[key]; + return;} + + function i3(obj: T, other: U, key: K) { + obj[key]; + other[key]; + return; + } + + + // ************ + function j1(obj: U, key: keyof T) { + ~~ +!!! error TS2393: Duplicate function implementation. + return obj[key]; + } + + function j2(obj: U, key: keyof T) { + ~~ +!!! error TS2393: Duplicate function implementation. + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + ~~~~~~~~ +!!! error TS2536: Type 'keyof T' cannot be used to index type '{}'. + } + + function j3(obj: U, key: keyof T) { + ~~ +!!! error TS2393: Duplicate function implementation. + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + } + + + // ************ + function j1(obj: U, key: keyof U) { + ~~ +!!! error TS2393: Duplicate function implementation. + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + } + + function j2(obj: U, key: keyof U) { + ~~ +!!! error TS2393: Duplicate function implementation. + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + ~~~~~~~~ +!!! error TS2536: Type 'keyof U' cannot be used to index type '{}'. + } + + function j3(obj: U, key: keyof U) { + ~~ +!!! error TS2393: Duplicate function implementation. + return obj[key]; + ~~~ +!!! error TS18049: 'obj' is possibly 'null' or 'undefined'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/unconstrainedTypeMapped.symbols b/tests/baselines/reference/unconstrainedTypeMapped.symbols new file mode 100644 index 0000000000000..6bde77a1ca609 --- /dev/null +++ b/tests/baselines/reference/unconstrainedTypeMapped.symbols @@ -0,0 +1,447 @@ +//// [tests/cases/compiler/unconstrainedTypeMapped.ts] //// + +=== unconstrainedTypeMapped.ts === +function f3(x: T, y: U, k: keyof T) { +>f3 : Symbol(f3, Decl(unconstrainedTypeMapped.ts, 0, 0), Decl(unconstrainedTypeMapped.ts, 11, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 0, 12)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 0, 14)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 0, 12)) +>x : Symbol(x, Decl(unconstrainedTypeMapped.ts, 0, 28)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 0, 12)) +>y : Symbol(y, Decl(unconstrainedTypeMapped.ts, 0, 33)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 0, 14)) +>k : Symbol(k, Decl(unconstrainedTypeMapped.ts, 0, 39)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 0, 12)) + + x[k] = y[k]; +>x : Symbol(x, Decl(unconstrainedTypeMapped.ts, 0, 28)) +>k : Symbol(k, Decl(unconstrainedTypeMapped.ts, 0, 39)) +>y : Symbol(y, Decl(unconstrainedTypeMapped.ts, 0, 33)) +>k : Symbol(k, Decl(unconstrainedTypeMapped.ts, 0, 39)) + + y[k] = x[k]; +>y : Symbol(y, Decl(unconstrainedTypeMapped.ts, 0, 33)) +>k : Symbol(k, Decl(unconstrainedTypeMapped.ts, 0, 39)) +>x : Symbol(x, Decl(unconstrainedTypeMapped.ts, 0, 28)) +>k : Symbol(k, Decl(unconstrainedTypeMapped.ts, 0, 39)) +} + +function f(obj: T, key: K) { +>f : Symbol(f, Decl(unconstrainedTypeMapped.ts, 3, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 5, 11)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 5, 13)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 5, 11)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 5, 33)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 5, 11)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 5, 40)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 5, 13)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 5, 33)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 5, 40)) +} + +function f2(obj: T, key: K) { +>f2 : Symbol(f2, Decl(unconstrainedTypeMapped.ts, 7, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 9, 12)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 9, 45)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 9, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 9, 65)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 9, 12)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 9, 72)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 9, 45)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 9, 65)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 9, 72)) +} + +function f3(obj: T, key: K) { +>f3 : Symbol(f3, Decl(unconstrainedTypeMapped.ts, 0, 0), Decl(unconstrainedTypeMapped.ts, 11, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 13, 12)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 13, 30)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 13, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 13, 50)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 13, 12)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 13, 57)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 13, 30)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 13, 50)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 13, 57)) +} + +function f4(obj: U, key: K) { +>f4 : Symbol(f4, Decl(unconstrainedTypeMapped.ts, 15, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 17, 12)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 17, 14)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 17, 12)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 17, 27)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 17, 14)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 17, 47)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 17, 14)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 17, 54)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 17, 27)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 17, 47)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 17, 54)) +} + +function f5(obj: U, key: K) { +>f5 : Symbol(f5, Decl(unconstrainedTypeMapped.ts, 19, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 21, 12)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 21, 44)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 21, 12)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 21, 57)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 21, 44)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 21, 77)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 21, 44)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 21, 84)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 21, 57)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 21, 77)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 21, 84)) +} + +function f6(obj: U, key: K) { +>f6 : Symbol(f6, Decl(unconstrainedTypeMapped.ts, 23, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 25, 12)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 25, 30)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 25, 12)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 25, 43)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 25, 30)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 25, 63)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 25, 30)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 25, 70)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 25, 43)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 25, 63)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 25, 70)) +} + +// ************ +function g1(obj: T, key: keyof T) { +>g1 : Symbol(g1, Decl(unconstrainedTypeMapped.ts, 27, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 30, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 30, 15)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 30, 12)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 30, 22)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 30, 12)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 30, 15)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 30, 22)) +} + +function g2(obj: T, key: keyof T) { +>g2 : Symbol(g2, Decl(unconstrainedTypeMapped.ts, 32, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 34, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 34, 45)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 34, 12)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 34, 52)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 34, 12)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 34, 45)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 34, 52)) +} + +function g3(obj: T, key: keyof T) { +>g3 : Symbol(g3, Decl(unconstrainedTypeMapped.ts, 36, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 38, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 38, 31)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 38, 12)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 38, 38)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 38, 12)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 38, 31)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 38, 38)) +} + +function g4(obj: U, key: keyof U) { +>g4 : Symbol(g4, Decl(unconstrainedTypeMapped.ts, 40, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 42, 12)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 42, 14)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 42, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 42, 28)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 42, 14)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 42, 35)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 42, 14)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 42, 28)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 42, 35)) +} + +function g5(obj: U, key: keyof U) { +>g5 : Symbol(g5, Decl(unconstrainedTypeMapped.ts, 44, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 46, 12)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 46, 44)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 46, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 46, 58)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 46, 44)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 46, 65)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 46, 44)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 46, 58)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 46, 65)) +} + +function g6(obj: U, key: keyof U) { +>g6 : Symbol(g6, Decl(unconstrainedTypeMapped.ts, 48, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 50, 12)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 50, 30)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 50, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 50, 44)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 50, 30)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 50, 51)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 50, 30)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 50, 44)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 50, 51)) +} + +// ************** +function h1(obj: T, other: T, key: K) { +>h1 : Symbol(h1, Decl(unconstrainedTypeMapped.ts, 52, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 55, 12)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 55, 14)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 55, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 55, 34)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 55, 12)) +>other : Symbol(other, Decl(unconstrainedTypeMapped.ts, 55, 41)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 55, 12)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 55, 51)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 55, 14)) + + obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 55, 34)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 55, 51)) + + other[key]; +>other : Symbol(other, Decl(unconstrainedTypeMapped.ts, 55, 41)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 55, 51)) + + return; +} + +function h2(obj: T, other: T, key: K) { +>h2 : Symbol(h2, Decl(unconstrainedTypeMapped.ts, 59, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 61, 12)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 61, 45)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 61, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 61, 65)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 61, 12)) +>other : Symbol(other, Decl(unconstrainedTypeMapped.ts, 61, 72)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 61, 12)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 61, 82)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 61, 45)) + + obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 61, 65)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 61, 82)) + + other[key]; +>other : Symbol(other, Decl(unconstrainedTypeMapped.ts, 61, 72)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 61, 82)) + + return;} + +function h3(obj: T, other: T, key: K) { +>h3 : Symbol(h3, Decl(unconstrainedTypeMapped.ts, 64, 12)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 66, 12)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 66, 30)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 66, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 66, 50)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 66, 12)) +>other : Symbol(other, Decl(unconstrainedTypeMapped.ts, 66, 57)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 66, 12)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 66, 67)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 66, 30)) + + obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 66, 50)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 66, 67)) + + other[key]; +>other : Symbol(other, Decl(unconstrainedTypeMapped.ts, 66, 57)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 66, 67)) + + return; +} + +// ************** +function i1(obj: T, other: U, key: K) { +>i1 : Symbol(i1, Decl(unconstrainedTypeMapped.ts, 70, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 73, 12)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 73, 14)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 73, 12)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 73, 27)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 73, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 73, 47)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 73, 12)) +>other : Symbol(other, Decl(unconstrainedTypeMapped.ts, 73, 54)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 73, 14)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 73, 64)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 73, 27)) + + obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 73, 47)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 73, 64)) + + other[key]; +>other : Symbol(other, Decl(unconstrainedTypeMapped.ts, 73, 54)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 73, 64)) + + return; +} + +function i2(obj: T, other: U, key: K) { +>i2 : Symbol(i2, Decl(unconstrainedTypeMapped.ts, 77, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 79, 12)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 79, 45)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 79, 12)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 79, 58)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 79, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 79, 78)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 79, 12)) +>other : Symbol(other, Decl(unconstrainedTypeMapped.ts, 79, 85)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 79, 45)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 79, 95)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 79, 58)) + + obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 79, 78)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 79, 95)) + + other[key]; +>other : Symbol(other, Decl(unconstrainedTypeMapped.ts, 79, 85)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 79, 95)) + + return;} + +function i3(obj: T, other: U, key: K) { +>i3 : Symbol(i3, Decl(unconstrainedTypeMapped.ts, 82, 12)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 84, 12)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 84, 30)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 84, 12)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 84, 43)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 84, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 84, 63)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 84, 12)) +>other : Symbol(other, Decl(unconstrainedTypeMapped.ts, 84, 70)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 84, 30)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 84, 80)) +>K : Symbol(K, Decl(unconstrainedTypeMapped.ts, 84, 43)) + + obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 84, 63)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 84, 80)) + + other[key]; +>other : Symbol(other, Decl(unconstrainedTypeMapped.ts, 84, 70)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 84, 80)) + + return; +} + + +// ************ +function j1(obj: U, key: keyof T) { +>j1 : Symbol(j1, Decl(unconstrainedTypeMapped.ts, 88, 1), Decl(unconstrainedTypeMapped.ts, 102, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 92, 12)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 92, 14)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 92, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 92, 28)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 92, 14)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 92, 35)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 92, 12)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 92, 28)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 92, 35)) +} + +function j2(obj: U, key: keyof T) { +>j2 : Symbol(j2, Decl(unconstrainedTypeMapped.ts, 94, 1), Decl(unconstrainedTypeMapped.ts, 108, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 96, 12)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 96, 44)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 96, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 96, 58)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 96, 44)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 96, 65)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 96, 12)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 96, 58)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 96, 65)) +} + +function j3(obj: U, key: keyof T) { +>j3 : Symbol(j3, Decl(unconstrainedTypeMapped.ts, 98, 1), Decl(unconstrainedTypeMapped.ts, 112, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 100, 12)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 100, 30)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 100, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 100, 44)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 100, 30)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 100, 51)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 100, 12)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 100, 44)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 100, 51)) +} + + +// ************ +function j1(obj: U, key: keyof U) { +>j1 : Symbol(j1, Decl(unconstrainedTypeMapped.ts, 88, 1), Decl(unconstrainedTypeMapped.ts, 102, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 106, 12)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 106, 14)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 106, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 106, 28)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 106, 14)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 106, 35)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 106, 14)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 106, 28)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 106, 35)) +} + +function j2(obj: U, key: keyof U) { +>j2 : Symbol(j2, Decl(unconstrainedTypeMapped.ts, 94, 1), Decl(unconstrainedTypeMapped.ts, 108, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 110, 12)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 110, 44)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 110, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 110, 58)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 110, 44)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 110, 65)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 110, 44)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 110, 58)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 110, 65)) +} + +function j3(obj: U, key: keyof U) { +>j3 : Symbol(j3, Decl(unconstrainedTypeMapped.ts, 98, 1), Decl(unconstrainedTypeMapped.ts, 112, 1)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 114, 12)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 114, 30)) +>T : Symbol(T, Decl(unconstrainedTypeMapped.ts, 114, 12)) +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 114, 44)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 114, 30)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 114, 51)) +>U : Symbol(U, Decl(unconstrainedTypeMapped.ts, 114, 30)) + + return obj[key]; +>obj : Symbol(obj, Decl(unconstrainedTypeMapped.ts, 114, 44)) +>key : Symbol(key, Decl(unconstrainedTypeMapped.ts, 114, 51)) +} + diff --git a/tests/baselines/reference/unconstrainedTypeMapped.types b/tests/baselines/reference/unconstrainedTypeMapped.types new file mode 100644 index 0000000000000..d3e3ddac4409c --- /dev/null +++ b/tests/baselines/reference/unconstrainedTypeMapped.types @@ -0,0 +1,531 @@ +//// [tests/cases/compiler/unconstrainedTypeMapped.ts] //// + +=== unconstrainedTypeMapped.ts === +function f3(x: T, y: U, k: keyof T) { +>f3 : { (x: T, y: U, k: keyof T): void; (obj: T_1, key: K): T_1[K]; } +> : ^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^ +>x : T +> : ^ +>y : U +> : ^ +>k : keyof T +> : ^^^^^^^ + + x[k] = y[k]; +>x[k] = y[k] : U[keyof T] +> : ^^^^^^^^^^ +>x[k] : T[keyof T] +> : ^^^^^^^^^^ +>x : T +> : ^ +>k : keyof T +> : ^^^^^^^ +>y[k] : U[keyof T] +> : ^^^^^^^^^^ +>y : U +> : ^ +>k : keyof T +> : ^^^^^^^ + + y[k] = x[k]; +>y[k] = x[k] : T[keyof T] +> : ^^^^^^^^^^ +>y[k] : U[keyof T] +> : ^^^^^^^^^^ +>y : U +> : ^ +>k : keyof T +> : ^^^^^^^ +>x[k] : T[keyof T] +> : ^^^^^^^^^^ +>x : T +> : ^ +>k : keyof T +> : ^^^^^^^ +} + +function f(obj: T, key: K) { +>f : (obj: T, key: K) => T[K] +> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : T +> : ^ +>key : K +> : ^ + + return obj[key]; +>obj[key] : T[K] +> : ^^^^ +>obj : T +> : ^ +>key : K +> : ^ +} + +function f2(obj: T, key: K) { +>f2 : (obj: T, key: K) => {} | null | undefined +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : T +> : ^ +>key : K +> : ^ + + return obj[key]; +>obj[key] : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>obj : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : K +> : ^ +} + +function f3(obj: T, key: K) { +>f3 : { (x: T_1, y: U, k: keyof T_1): void; (obj: T, key: K): T[K]; } +> : ^^^^^^^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^ +>obj : T +> : ^ +>key : K +> : ^ + + return obj[key]; +>obj[key] : T[K] +> : ^^^^ +>obj : T +> : ^ +>key : K +> : ^ +} + +function f4(obj: U, key: K) { +>f4 : (obj: U, key: K) => U[K] +> : ^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : U +> : ^ +>key : K +> : ^ + + return obj[key]; +>obj[key] : U[K] +> : ^^^^ +>obj : U +> : ^ +>key : K +> : ^ +} + +function f5(obj: U, key: K) { +>f5 : (obj: U, key: K) => {} | null | undefined +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : K +> : ^ + + return obj[key]; +>obj[key] : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>obj : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : K +> : ^ +} + +function f6(obj: U, key: K) { +>f6 : (obj: U, key: K) => U[K] +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : U +> : ^ +>key : K +> : ^ + + return obj[key]; +>obj[key] : U[K] +> : ^^^^ +>obj : U +> : ^ +>key : K +> : ^ +} + +// ************ +function g1(obj: T, key: keyof T) { +>g1 : (obj: T, key: keyof T) => T[keyof T] +> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^ +>obj : T +> : ^ +>key : keyof T +> : ^^^^^^^ + + return obj[key]; +>obj[key] : T[keyof T] +> : ^^^^^^^^^^ +>obj : T +> : ^ +>key : keyof T +> : ^^^^^^^ +} + +function g2(obj: T, key: keyof T) { +>g2 : (obj: T, key: keyof T) => any +> : ^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^ +>obj : T +> : ^ +>key : keyof T +> : ^^^^^^^ + + return obj[key]; +>obj[key] : any +> : ^^^ +>obj : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : keyof T +> : ^^^^^^^ +} + +function g3(obj: T, key: keyof T) { +>g3 : (obj: T, key: keyof T) => NonNullable[keyof T] +> : ^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : T +> : ^ +>key : keyof T +> : ^^^^^^^ + + return obj[key]; +>obj[key] : NonNullable[keyof T] +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>obj : T +> : ^ +>key : keyof T +> : ^^^^^^^ +} + +function g4(obj: U, key: keyof U) { +>g4 : (obj: U, key: keyof U) => NonNullable[keyof U] +> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ + + return obj[key]; +>obj[key] : NonNullable[keyof U] +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ +} + +function g5(obj: U, key: keyof U) { +>g5 : (obj: U, key: keyof U) => any +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ + + return obj[key]; +>obj[key] : any +> : ^^^ +>obj : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : keyof U +> : ^^^^^^^ +} + +function g6(obj: U, key: keyof U) { +>g6 : (obj: U, key: keyof U) => NonNullable[keyof U] +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ + + return obj[key]; +>obj[key] : NonNullable[keyof U] +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ +} + +// ************** +function h1(obj: T, other: T, key: K) { +>h1 : (obj: T, other: T, key: K) => void +> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : T +> : ^ +>other : T +> : ^ +>key : K +> : ^ + + obj[key]; +>obj[key] : T[K] +> : ^^^^ +>obj : T +> : ^ +>key : K +> : ^ + + other[key]; +>other[key] : T[K] +> : ^^^^ +>other : T +> : ^ +>key : K +> : ^ + + return; +} + +function h2(obj: T, other: T, key: K) { +>h2 : (obj: T, other: T, key: K) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : T +> : ^ +>other : T +> : ^ +>key : K +> : ^ + + obj[key]; +>obj[key] : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>obj : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : K +> : ^ + + other[key]; +>other[key] : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>other : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : K +> : ^ + + return;} + +function h3(obj: T, other: T, key: K) { +>h3 : (obj: T, other: T, key: K) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : T +> : ^ +>other : T +> : ^ +>key : K +> : ^ + + obj[key]; +>obj[key] : T[K] +> : ^^^^ +>obj : T +> : ^ +>key : K +> : ^ + + other[key]; +>other[key] : T[K] +> : ^^^^ +>other : T +> : ^ +>key : K +> : ^ + + return; +} + +// ************** +function i1(obj: T, other: U, key: K) { +>i1 : (obj: T, other: U, key: K) => void +> : ^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : T +> : ^ +>other : U +> : ^ +>key : K +> : ^ + + obj[key]; +>obj[key] : T[K] +> : ^^^^ +>obj : T +> : ^ +>key : K +> : ^ + + other[key]; +>other[key] : U[K] +> : ^^^^ +>other : U +> : ^ +>key : K +> : ^ + + return; +} + +function i2(obj: T, other: U, key: K) { +>i2 : (obj: T, other: U, key: K) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : T +> : ^ +>other : U +> : ^ +>key : K +> : ^ + + obj[key]; +>obj[key] : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>obj : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : K +> : ^ + + other[key]; +>other[key] : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>other : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : K +> : ^ + + return;} + +function i3(obj: T, other: U, key: K) { +>i3 : (obj: T, other: U, key: K) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : T +> : ^ +>other : U +> : ^ +>key : K +> : ^ + + obj[key]; +>obj[key] : T[K] +> : ^^^^ +>obj : T +> : ^ +>key : K +> : ^ + + other[key]; +>other[key] : U[K] +> : ^^^^ +>other : U +> : ^ +>key : K +> : ^ + + return; +} + + +// ************ +function j1(obj: U, key: keyof T) { +>j1 : { (obj: U, key: keyof T): U[keyof T]; (obj: U_1, key: keyof U_1): NonNullable[keyof U_1]; } +> : ^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof T +> : ^^^^^^^ + + return obj[key]; +>obj[key] : U[keyof T] +> : ^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof T +> : ^^^^^^^ +} + +function j2(obj: U, key: keyof T) { +>j2 : { (obj: U, key: keyof T): any; (obj: U_1, key: keyof U_1): any; } +> : ^^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : U +> : ^ +>key : keyof T +> : ^^^^^^^ + + return obj[key]; +>obj[key] : any +> : ^^^ +>obj : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : keyof T +> : ^^^^^^^ +} + +function j3(obj: U, key: keyof T) { +>j3 : { (obj: U, key: keyof T): NonNullable[keyof T]; (obj: U_1, key: keyof U_1): NonNullable[keyof U_1]; } +> : ^^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof T +> : ^^^^^^^ + + return obj[key]; +>obj[key] : NonNullable[keyof T] +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof T +> : ^^^^^^^ +} + + +// ************ +function j1(obj: U, key: keyof U) { +>j1 : { (obj: U_1, key: keyof T_1): U_1[keyof T_1]; (obj: U, key: keyof U): NonNullable[keyof U]; } +> : ^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ + + return obj[key]; +>obj[key] : NonNullable[keyof U] +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ +} + +function j2(obj: U, key: keyof U) { +>j2 : { (obj: U_1, key: keyof T_1): any; (obj: U, key: keyof U): any; } +> : ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ + + return obj[key]; +>obj[key] : any +> : ^^^ +>obj : {} | null | undefined +> : ^^^^^^^^^^^^^^^^^^^^^ +>key : keyof U +> : ^^^^^^^ +} + +function j3(obj: U, key: keyof U) { +>j3 : { (obj: U_1, key: keyof T_1): NonNullable[keyof T_1]; (obj: U, key: keyof U): NonNullable[keyof U]; } +> : ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ + + return obj[key]; +>obj[key] : NonNullable[keyof U] +> : ^^^^^^^^^^^^^^^^^^^^^^^ +>obj : U +> : ^ +>key : keyof U +> : ^^^^^^^ +} + diff --git a/tests/baselines/reference/unknownControlFlow.errors.txt b/tests/baselines/reference/unknownControlFlow.errors.txt index e8f4f198a505a..019a765817cf8 100644 --- a/tests/baselines/reference/unknownControlFlow.errors.txt +++ b/tests/baselines/reference/unknownControlFlow.errors.txt @@ -1,5 +1,5 @@ unknownControlFlow.ts(18,9): error TS2322: Type 'unknown' is not assignable to type '{}'. -unknownControlFlow.ts(283,5): error TS2536: Type 'keyof (T & {})' cannot be used to index type 'T'. +unknownControlFlow.ts(283,5): error TS18049: 't' is possibly 'null' or 'undefined'. unknownControlFlow.ts(290,11): error TS2345: Argument of type 'string' is not assignable to parameter of type 'never'. unknownControlFlow.ts(291,5): error TS2345: Argument of type 'null' is not assignable to parameter of type 'never'. unknownControlFlow.ts(293,5): error TS2345: Argument of type 'null' is not assignable to parameter of type 'never'. @@ -293,8 +293,8 @@ unknownControlFlow.ts(341,9): error TS2367: This comparison appears to be uninte function ff3(t: T, k: keyof (T & {})) { t[k]; // Error - ~~~~ -!!! error TS2536: Type 'keyof (T & {})' cannot be used to index type 'T'. + ~ +!!! error TS18049: 't' is possibly 'null' or 'undefined'. } function ff4(t: T & {}, k: keyof (T & {})) { diff --git a/tests/baselines/reference/unknownControlFlow.types b/tests/baselines/reference/unknownControlFlow.types index 2c84aa0d19d3e..6b9c80c7077a5 100644 --- a/tests/baselines/reference/unknownControlFlow.types +++ b/tests/baselines/reference/unknownControlFlow.types @@ -481,8 +481,8 @@ function f23(x: T | undefined | null) { > : ^^^^^^^^^ x; // T & {} | null ->x : (T & {}) | null -> : ^^^^^^^^^^^^^^^ +>x : (T & ({} | null)) | null +> : ^^^^^^^^^^^^^^^^^^^^^^^^ } if (x !== null) { >x !== null : boolean @@ -491,8 +491,8 @@ function f23(x: T | undefined | null) { > : ^^^^^^^^^^^^^^^^^^^^ x; // T & {} | undefined ->x : (T & {}) | undefined -> : ^^^^^^^^^^^^^^^^^^^^ +>x : (T & ({} | undefined)) | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ } if (x != undefined) { >x != undefined : boolean @@ -1096,8 +1096,8 @@ function ff3(t: T, k: keyof (T & {})) { > : ^^^^^^^^^^^^^^ t[k]; // Error ->t[k] : any -> : ^^^ +>t[k] : NonNullable[keyof (T & {})] +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >t : T > : ^ >k : keyof (T & {}) diff --git a/tests/baselines/reference/voidUndefinedReduction.types b/tests/baselines/reference/voidUndefinedReduction.types index b1f9ed6009be1..44f2e251a3987 100644 --- a/tests/baselines/reference/voidUndefinedReduction.types +++ b/tests/baselines/reference/voidUndefinedReduction.types @@ -20,8 +20,8 @@ function isDefined(value: T | undefined | null | void): value is T { > : ^^^^^^^^^ >value !== null : boolean > : ^^^^^^^ ->value : (T & {}) | null -> : ^^^^^^^^^^^^^^^ +>value : (T & ({} | null)) | null +> : ^^^^^^^^^^^^^^^^^^^^^^^^ } declare const foo: string | undefined; diff --git a/tests/cases/compiler/unconstrainedTypeComparisons.ts b/tests/cases/compiler/unconstrainedTypeComparisons.ts new file mode 100644 index 0000000000000..1b68085f3255d --- /dev/null +++ b/tests/cases/compiler/unconstrainedTypeComparisons.ts @@ -0,0 +1,24 @@ +// @lib: es2015 +// @target: es2015 +// @strict: true +// @noemit: true + +function f(a: T, b: T): boolean { + return a > b; +} + +function g(a: T, b: T): boolean { + return a > b; +} + +function h(a: T, b: T): boolean { + return a > b; +} + +function i(a: T, b: T): boolean { + if (a === undefined) { + return true; + } + + return a > b; +} \ No newline at end of file diff --git a/tests/cases/compiler/unconstrainedTypeKeyofParam.ts b/tests/cases/compiler/unconstrainedTypeKeyofParam.ts new file mode 100644 index 0000000000000..a9cc167623ae8 --- /dev/null +++ b/tests/cases/compiler/unconstrainedTypeKeyofParam.ts @@ -0,0 +1,120 @@ +// @strict: true +// @noemit: true + +function f3(x: T, y: U, k: keyof T) { + x[k] = y[k]; + y[k] = x[k]; +} + +function f(obj: T, key: K) { + return obj[key]; +} + +function f2(obj: T, key: K) { + return obj[key]; +} + +function f3(obj: T, key: K) { + return obj[key]; +} + +function f4(obj: U, key: K) { + return obj[key]; +} + +function f5(obj: U, key: K) { + return obj[key]; +} + +function f6(obj: U, key: K) { + return obj[key]; +} + +// ************ +function g1(obj: T, key: keyof T) { + return obj[key]; +} + +function g2(obj: T, key: keyof T) { + return obj[key]; +} + +function g3(obj: T, key: keyof T) { + return obj[key]; +} + +function g4(obj: U, key: keyof U) { + return obj[key]; +} + +function g5(obj: U, key: keyof U) { + return obj[key]; +} + +function g6(obj: U, key: keyof U) { + return obj[key]; +} + +// ************** +function h1(obj: T, other: T, key: K) { + obj[key]; + other[key]; + return; +} + +function h2(obj: T, other: T, key: K) { + obj[key]; + other[key]; + return;} + +function h3(obj: T, other: T, key: K) { + obj[key]; + other[key]; + return; +} + +// ************** +function i1(obj: T, other: U, key: K) { + obj[key]; + other[key]; + return; +} + +function i2(obj: T, other: U, key: K) { + obj[key]; + other[key]; + return;} + +function i3(obj: T, other: U, key: K) { + obj[key]; + other[key]; + return; +} + + +// ************ +function j1(obj: U, key: keyof T) { + return obj[key]; +} + +function j2(obj: U, key: keyof T) { + return obj[key]; +} + +function j3(obj: U, key: keyof T) { + return obj[key]; +} + + +// ************ +function j1(obj: U, key: keyof U) { + return obj[key]; +} + +function j2(obj: U, key: keyof U) { + return obj[key]; +} + +function j3(obj: U, key: keyof U) { + return obj[key]; +}