diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9ee8fe6572848..bd2d5f99899bc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -36221,9 +36221,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const len = signature.parameters.length - (signatureHasRestParameter(signature) ? 1 : 0); for (let i = 0; i < len; i++) { const parameter = signature.parameters[i]; - if (!getEffectiveTypeAnnotationNode(parameter.valueDeclaration as ParameterDeclaration)) { - const contextualParameterType = tryGetTypeAtPosition(context, i); - assignParameterType(parameter, contextualParameterType); + const declaration = parameter.valueDeclaration as ParameterDeclaration; + if (!getEffectiveTypeAnnotationNode(declaration)) { + let type = tryGetTypeAtPosition(context, i); + if (type && declaration.initializer) { + let initializerType = checkDeclarationInitializer(declaration, CheckMode.Normal); + if (!isTypeAssignableTo(initializerType, type) && isTypeAssignableTo(type, initializerType = widenTypeInferredFromInitializer(declaration, initializerType))) { + type = initializerType; + } + } + assignParameterType(parameter, type); } } if (signatureHasRestParameter(signature)) { diff --git a/tests/baselines/reference/contextuallyTypedParametersWithInitializers.errors.txt b/tests/baselines/reference/contextuallyTypedParametersWithInitializers1.errors.txt similarity index 90% rename from tests/baselines/reference/contextuallyTypedParametersWithInitializers.errors.txt rename to tests/baselines/reference/contextuallyTypedParametersWithInitializers1.errors.txt index ead06513c5270..037a858524c4b 100644 --- a/tests/baselines/reference/contextuallyTypedParametersWithInitializers.errors.txt +++ b/tests/baselines/reference/contextuallyTypedParametersWithInitializers1.errors.txt @@ -1,8 +1,8 @@ -contextuallyTypedParametersWithInitializers.ts(24,24): error TS7006: Parameter 'x' implicitly has an 'any' type. -contextuallyTypedParametersWithInitializers.ts(40,5): error TS7006: Parameter 'x' implicitly has an 'any' type. +contextuallyTypedParametersWithInitializers1.ts(24,24): error TS7006: Parameter 'x' implicitly has an 'any' type. +contextuallyTypedParametersWithInitializers1.ts(40,5): error TS7006: Parameter 'x' implicitly has an 'any' type. -==== contextuallyTypedParametersWithInitializers.ts (2 errors) ==== +==== contextuallyTypedParametersWithInitializers1.ts (2 errors) ==== declare function id1(input: T): T; declare function id2 any>(input: T): T; declare function id3 any>(input: T): T; diff --git a/tests/baselines/reference/contextuallyTypedParametersWithInitializers.js b/tests/baselines/reference/contextuallyTypedParametersWithInitializers1.js similarity index 94% rename from tests/baselines/reference/contextuallyTypedParametersWithInitializers.js rename to tests/baselines/reference/contextuallyTypedParametersWithInitializers1.js index 088fb6235d512..975f8af6aba26 100644 --- a/tests/baselines/reference/contextuallyTypedParametersWithInitializers.js +++ b/tests/baselines/reference/contextuallyTypedParametersWithInitializers1.js @@ -1,6 +1,6 @@ -//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts] //// +//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers1.ts] //// -//// [contextuallyTypedParametersWithInitializers.ts] +//// [contextuallyTypedParametersWithInitializers1.ts] declare function id1(input: T): T; declare function id2 any>(input: T): T; declare function id3 any>(input: T): T; @@ -86,7 +86,7 @@ const fz1 = (debug = true) => false; const fz2: Function = (debug = true) => false; -//// [contextuallyTypedParametersWithInitializers.js] +//// [contextuallyTypedParametersWithInitializers1.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeSomething = void 0; @@ -234,5 +234,5 @@ var fz2 = function (debug) { }; -//// [contextuallyTypedParametersWithInitializers.d.ts] +//// [contextuallyTypedParametersWithInitializers1.d.ts] export declare function executeSomething(): Promise; diff --git a/tests/baselines/reference/contextuallyTypedParametersWithInitializers.symbols b/tests/baselines/reference/contextuallyTypedParametersWithInitializers1.symbols similarity index 55% rename from tests/baselines/reference/contextuallyTypedParametersWithInitializers.symbols rename to tests/baselines/reference/contextuallyTypedParametersWithInitializers1.symbols index 24e5287c0282a..b02818faea9c4 100644 --- a/tests/baselines/reference/contextuallyTypedParametersWithInitializers.symbols +++ b/tests/baselines/reference/contextuallyTypedParametersWithInitializers1.symbols @@ -1,321 +1,321 @@ -//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts] //// +//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers1.ts] //// -=== contextuallyTypedParametersWithInitializers.ts === +=== contextuallyTypedParametersWithInitializers1.ts === declare function id1(input: T): T; ->id1 : Symbol(id1, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 0)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 21)) ->input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 24)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 21)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 21)) +>id1 : Symbol(id1, Decl(contextuallyTypedParametersWithInitializers1.ts, 0, 0)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 0, 21)) +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers1.ts, 0, 24)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 0, 21)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 0, 21)) declare function id2 any>(input: T): T; ->id2 : Symbol(id2, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 37)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 21)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 32)) ->input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 48)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 21)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 21)) +>id2 : Symbol(id2, Decl(contextuallyTypedParametersWithInitializers1.ts, 0, 37)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 1, 21)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 1, 32)) +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers1.ts, 1, 48)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 1, 21)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 1, 21)) declare function id3 any>(input: T): T; ->id3 : Symbol(id3, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 61)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 21)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 32)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 36)) ->input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 57)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 21)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 21)) +>id3 : Symbol(id3, Decl(contextuallyTypedParametersWithInitializers1.ts, 1, 61)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 2, 21)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 2, 32)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 2, 36)) +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers1.ts, 2, 57)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 2, 21)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 2, 21)) declare function id4 any>(input: T): T; ->id4 : Symbol(id4, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 70)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 21)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 32)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 36)) ->input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 61)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 21)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 21)) +>id4 : Symbol(id4, Decl(contextuallyTypedParametersWithInitializers1.ts, 2, 70)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 3, 21)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 3, 32)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 3, 36)) +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers1.ts, 3, 61)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 3, 21)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 3, 21)) declare function id5 any>(input: T): T; ->id5 : Symbol(id5, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 74)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 4, 21)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 4, 32)) ->input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 4, 52)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 4, 21)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 4, 21)) +>id5 : Symbol(id5, Decl(contextuallyTypedParametersWithInitializers1.ts, 3, 74)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 4, 21)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 4, 32)) +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers1.ts, 4, 52)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 4, 21)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 4, 21)) const f10 = function ({ foo = 42 }) { return foo }; ->f10 : Symbol(f10, Decl(contextuallyTypedParametersWithInitializers.ts, 6, 5)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 6, 23)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 6, 23)) +>f10 : Symbol(f10, Decl(contextuallyTypedParametersWithInitializers1.ts, 6, 5)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 6, 23)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 6, 23)) const f11 = id1(function ({ foo = 42 }) { return foo }); ->f11 : Symbol(f11, Decl(contextuallyTypedParametersWithInitializers.ts, 7, 5)) ->id1 : Symbol(id1, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 0)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 7, 27)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 7, 27)) +>f11 : Symbol(f11, Decl(contextuallyTypedParametersWithInitializers1.ts, 7, 5)) +>id1 : Symbol(id1, Decl(contextuallyTypedParametersWithInitializers1.ts, 0, 0)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 7, 27)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 7, 27)) const f12 = id2(function ({ foo = 42 }) { return foo }); ->f12 : Symbol(f12, Decl(contextuallyTypedParametersWithInitializers.ts, 8, 5)) ->id2 : Symbol(id2, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 37)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 8, 27)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 8, 27)) +>f12 : Symbol(f12, Decl(contextuallyTypedParametersWithInitializers1.ts, 8, 5)) +>id2 : Symbol(id2, Decl(contextuallyTypedParametersWithInitializers1.ts, 0, 37)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 8, 27)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 8, 27)) const f13 = id3(function ({ foo = 42 }) { return foo }); ->f13 : Symbol(f13, Decl(contextuallyTypedParametersWithInitializers.ts, 9, 5)) ->id3 : Symbol(id3, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 61)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 9, 27)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 9, 27)) +>f13 : Symbol(f13, Decl(contextuallyTypedParametersWithInitializers1.ts, 9, 5)) +>id3 : Symbol(id3, Decl(contextuallyTypedParametersWithInitializers1.ts, 1, 61)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 9, 27)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 9, 27)) const f14 = id4(function ({ foo = 42 }) { return foo }); ->f14 : Symbol(f14, Decl(contextuallyTypedParametersWithInitializers.ts, 10, 5)) ->id4 : Symbol(id4, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 70)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 10, 27)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 10, 27)) +>f14 : Symbol(f14, Decl(contextuallyTypedParametersWithInitializers1.ts, 10, 5)) +>id4 : Symbol(id4, Decl(contextuallyTypedParametersWithInitializers1.ts, 2, 70)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 10, 27)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 10, 27)) const f20 = function (foo = 42) { return foo }; ->f20 : Symbol(f20, Decl(contextuallyTypedParametersWithInitializers.ts, 12, 5)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 12, 22)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 12, 22)) +>f20 : Symbol(f20, Decl(contextuallyTypedParametersWithInitializers1.ts, 12, 5)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 12, 22)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 12, 22)) const f21 = id1(function (foo = 42) { return foo }); ->f21 : Symbol(f21, Decl(contextuallyTypedParametersWithInitializers.ts, 13, 5)) ->id1 : Symbol(id1, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 0)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 13, 26)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 13, 26)) +>f21 : Symbol(f21, Decl(contextuallyTypedParametersWithInitializers1.ts, 13, 5)) +>id1 : Symbol(id1, Decl(contextuallyTypedParametersWithInitializers1.ts, 0, 0)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 13, 26)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 13, 26)) const f22 = id2(function (foo = 42) { return foo }); ->f22 : Symbol(f22, Decl(contextuallyTypedParametersWithInitializers.ts, 14, 5)) ->id2 : Symbol(id2, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 37)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 14, 26)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 14, 26)) +>f22 : Symbol(f22, Decl(contextuallyTypedParametersWithInitializers1.ts, 14, 5)) +>id2 : Symbol(id2, Decl(contextuallyTypedParametersWithInitializers1.ts, 0, 37)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 14, 26)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 14, 26)) const f25 = id5(function (foo = 42) { return foo }); ->f25 : Symbol(f25, Decl(contextuallyTypedParametersWithInitializers.ts, 15, 5)) ->id5 : Symbol(id5, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 74)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 15, 26)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 15, 26)) +>f25 : Symbol(f25, Decl(contextuallyTypedParametersWithInitializers1.ts, 15, 5)) +>id5 : Symbol(id5, Decl(contextuallyTypedParametersWithInitializers1.ts, 3, 74)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 15, 26)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 15, 26)) const f1 = (x = 1) => 0; // number ->f1 : Symbol(f1, Decl(contextuallyTypedParametersWithInitializers.ts, 17, 5)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 17, 12)) +>f1 : Symbol(f1, Decl(contextuallyTypedParametersWithInitializers1.ts, 17, 5)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 17, 12)) const f2: any = (x = 1) => 0; // number ->f2 : Symbol(f2, Decl(contextuallyTypedParametersWithInitializers.ts, 18, 5)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 18, 17)) +>f2 : Symbol(f2, Decl(contextuallyTypedParametersWithInitializers1.ts, 18, 5)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 18, 17)) const f3: unknown = (x = 1) => 0; // number ->f3 : Symbol(f3, Decl(contextuallyTypedParametersWithInitializers.ts, 19, 5)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 19, 21)) +>f3 : Symbol(f3, Decl(contextuallyTypedParametersWithInitializers1.ts, 19, 5)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 19, 21)) const f4: Function = (x = 1) => 0; // number ->f4 : Symbol(f4, Decl(contextuallyTypedParametersWithInitializers.ts, 20, 5)) +>f4 : Symbol(f4, Decl(contextuallyTypedParametersWithInitializers1.ts, 20, 5)) >Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 20, 22)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 20, 22)) const f5: (...args: any[]) => any = (x = 1) => 0; // any ->f5 : Symbol(f5, Decl(contextuallyTypedParametersWithInitializers.ts, 21, 5)) ->args : Symbol(args, Decl(contextuallyTypedParametersWithInitializers.ts, 21, 11)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 21, 37)) +>f5 : Symbol(f5, Decl(contextuallyTypedParametersWithInitializers1.ts, 21, 5)) +>args : Symbol(args, Decl(contextuallyTypedParametersWithInitializers1.ts, 21, 11)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 21, 37)) const f6: () => any = (x = 1) => 0; // number ->f6 : Symbol(f6, Decl(contextuallyTypedParametersWithInitializers.ts, 22, 5)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 22, 23)) +>f6 : Symbol(f6, Decl(contextuallyTypedParametersWithInitializers1.ts, 22, 5)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 22, 23)) const f7: () => any = (x?) => 0; // Implicit any error ->f7 : Symbol(f7, Decl(contextuallyTypedParametersWithInitializers.ts, 23, 5)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 23, 23)) +>f7 : Symbol(f7, Decl(contextuallyTypedParametersWithInitializers1.ts, 23, 5)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 23, 23)) const f8: () => any = (...x) => 0; // [] ->f8 : Symbol(f8, Decl(contextuallyTypedParametersWithInitializers.ts, 24, 5)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 24, 23)) +>f8 : Symbol(f8, Decl(contextuallyTypedParametersWithInitializers1.ts, 24, 5)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 24, 23)) declare function g1(x: T): T; ->g1 : Symbol(g1, Decl(contextuallyTypedParametersWithInitializers.ts, 24, 34)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 26, 20)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 26, 23)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 26, 20)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 26, 20)) +>g1 : Symbol(g1, Decl(contextuallyTypedParametersWithInitializers1.ts, 24, 34)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 26, 20)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 26, 23)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 26, 20)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 26, 20)) declare function g2(x: T): T; ->g2 : Symbol(g2, Decl(contextuallyTypedParametersWithInitializers.ts, 26, 32)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 27, 20)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 27, 35)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 27, 20)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 27, 20)) +>g2 : Symbol(g2, Decl(contextuallyTypedParametersWithInitializers1.ts, 26, 32)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 27, 20)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 27, 35)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 27, 20)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 27, 20)) declare function g3(x: T): T; ->g3 : Symbol(g3, Decl(contextuallyTypedParametersWithInitializers.ts, 27, 44)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 28, 20)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 28, 39)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 28, 20)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 28, 20)) +>g3 : Symbol(g3, Decl(contextuallyTypedParametersWithInitializers1.ts, 27, 44)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 28, 20)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 28, 39)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 28, 20)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 28, 20)) declare function g4(x: T): T; ->g4 : Symbol(g4, Decl(contextuallyTypedParametersWithInitializers.ts, 28, 48)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 29, 20)) +>g4 : Symbol(g4, Decl(contextuallyTypedParametersWithInitializers1.ts, 28, 48)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 29, 20)) >Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 29, 40)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 29, 20)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 29, 20)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 29, 40)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 29, 20)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 29, 20)) declare function g5 any>(x: T): T; ->g5 : Symbol(g5, Decl(contextuallyTypedParametersWithInitializers.ts, 29, 49)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 30, 20)) ->args : Symbol(args, Decl(contextuallyTypedParametersWithInitializers.ts, 30, 31)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 30, 55)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 30, 20)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 30, 20)) +>g5 : Symbol(g5, Decl(contextuallyTypedParametersWithInitializers1.ts, 29, 49)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 30, 20)) +>args : Symbol(args, Decl(contextuallyTypedParametersWithInitializers1.ts, 30, 31)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 30, 55)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 30, 20)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 30, 20)) declare function g6 any>(x: T): T; ->g6 : Symbol(g6, Decl(contextuallyTypedParametersWithInitializers.ts, 30, 64)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 31, 20)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 31, 41)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 31, 20)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 31, 20)) +>g6 : Symbol(g6, Decl(contextuallyTypedParametersWithInitializers1.ts, 30, 64)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 31, 20)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 31, 41)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 31, 20)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 31, 20)) g1((x = 1) => 0); // number ->g1 : Symbol(g1, Decl(contextuallyTypedParametersWithInitializers.ts, 24, 34)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 33, 4)) +>g1 : Symbol(g1, Decl(contextuallyTypedParametersWithInitializers1.ts, 24, 34)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 33, 4)) g2((x = 1) => 0); // number ->g2 : Symbol(g2, Decl(contextuallyTypedParametersWithInitializers.ts, 26, 32)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 34, 4)) +>g2 : Symbol(g2, Decl(contextuallyTypedParametersWithInitializers1.ts, 26, 32)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 34, 4)) g3((x = 1) => 0); // number ->g3 : Symbol(g3, Decl(contextuallyTypedParametersWithInitializers.ts, 27, 44)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 35, 4)) +>g3 : Symbol(g3, Decl(contextuallyTypedParametersWithInitializers1.ts, 27, 44)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 35, 4)) g4((x = 1) => 0); // number ->g4 : Symbol(g4, Decl(contextuallyTypedParametersWithInitializers.ts, 28, 48)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 36, 4)) +>g4 : Symbol(g4, Decl(contextuallyTypedParametersWithInitializers1.ts, 28, 48)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 36, 4)) g5((x = 1) => 0); // any ->g5 : Symbol(g5, Decl(contextuallyTypedParametersWithInitializers.ts, 29, 49)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 37, 4)) +>g5 : Symbol(g5, Decl(contextuallyTypedParametersWithInitializers1.ts, 29, 49)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 37, 4)) g6((x = 1) => 0); // number ->g6 : Symbol(g6, Decl(contextuallyTypedParametersWithInitializers.ts, 30, 64)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 38, 4)) +>g6 : Symbol(g6, Decl(contextuallyTypedParametersWithInitializers1.ts, 30, 64)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 38, 4)) g6((x?) => 0); // Implicit any error ->g6 : Symbol(g6, Decl(contextuallyTypedParametersWithInitializers.ts, 30, 64)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 39, 4)) +>g6 : Symbol(g6, Decl(contextuallyTypedParametersWithInitializers1.ts, 30, 64)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 39, 4)) g6((...x) => 0); // [] ->g6 : Symbol(g6, Decl(contextuallyTypedParametersWithInitializers.ts, 30, 64)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 40, 4)) +>g6 : Symbol(g6, Decl(contextuallyTypedParametersWithInitializers1.ts, 30, 64)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 40, 4)) // Repro from #28816 function id(input: T): T { return input } ->id : Symbol(id, Decl(contextuallyTypedParametersWithInitializers.ts, 40, 16)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 44, 12)) ->input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 44, 15)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 44, 12)) ->T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 44, 12)) ->input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 44, 15)) +>id : Symbol(id, Decl(contextuallyTypedParametersWithInitializers1.ts, 40, 16)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 44, 12)) +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers1.ts, 44, 15)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 44, 12)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers1.ts, 44, 12)) +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers1.ts, 44, 15)) function getFoo ({ foo = 42 }) { ->getFoo : Symbol(getFoo, Decl(contextuallyTypedParametersWithInitializers.ts, 44, 44)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 46, 18)) +>getFoo : Symbol(getFoo, Decl(contextuallyTypedParametersWithInitializers1.ts, 44, 44)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 46, 18)) return foo; ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 46, 18)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 46, 18)) } const newGetFoo = id(getFoo); ->newGetFoo : Symbol(newGetFoo, Decl(contextuallyTypedParametersWithInitializers.ts, 50, 5)) ->id : Symbol(id, Decl(contextuallyTypedParametersWithInitializers.ts, 40, 16)) ->getFoo : Symbol(getFoo, Decl(contextuallyTypedParametersWithInitializers.ts, 44, 44)) +>newGetFoo : Symbol(newGetFoo, Decl(contextuallyTypedParametersWithInitializers1.ts, 50, 5)) +>id : Symbol(id, Decl(contextuallyTypedParametersWithInitializers1.ts, 40, 16)) +>getFoo : Symbol(getFoo, Decl(contextuallyTypedParametersWithInitializers1.ts, 44, 44)) const newGetFoo2 = id(function getFoo ({ foo = 42 }) { ->newGetFoo2 : Symbol(newGetFoo2, Decl(contextuallyTypedParametersWithInitializers.ts, 51, 5)) ->id : Symbol(id, Decl(contextuallyTypedParametersWithInitializers.ts, 40, 16)) ->getFoo : Symbol(getFoo, Decl(contextuallyTypedParametersWithInitializers.ts, 51, 22)) ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 51, 40)) +>newGetFoo2 : Symbol(newGetFoo2, Decl(contextuallyTypedParametersWithInitializers1.ts, 51, 5)) +>id : Symbol(id, Decl(contextuallyTypedParametersWithInitializers1.ts, 40, 16)) +>getFoo : Symbol(getFoo, Decl(contextuallyTypedParametersWithInitializers1.ts, 51, 22)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 51, 40)) return foo; ->foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 51, 40)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers1.ts, 51, 40)) }); // Repro from comment in #30840 declare function memoize(func: F): F; ->memoize : Symbol(memoize, Decl(contextuallyTypedParametersWithInitializers.ts, 53, 3)) ->F : Symbol(F, Decl(contextuallyTypedParametersWithInitializers.ts, 57, 25)) +>memoize : Symbol(memoize, Decl(contextuallyTypedParametersWithInitializers1.ts, 53, 3)) +>F : Symbol(F, Decl(contextuallyTypedParametersWithInitializers1.ts, 57, 25)) >Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->func : Symbol(func, Decl(contextuallyTypedParametersWithInitializers.ts, 57, 45)) ->F : Symbol(F, Decl(contextuallyTypedParametersWithInitializers.ts, 57, 25)) ->F : Symbol(F, Decl(contextuallyTypedParametersWithInitializers.ts, 57, 25)) +>func : Symbol(func, Decl(contextuallyTypedParametersWithInitializers1.ts, 57, 45)) +>F : Symbol(F, Decl(contextuallyTypedParametersWithInitializers1.ts, 57, 25)) +>F : Symbol(F, Decl(contextuallyTypedParametersWithInitializers1.ts, 57, 25)) function add(x: number, y = 0): number { ->add : Symbol(add, Decl(contextuallyTypedParametersWithInitializers.ts, 57, 57)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 59, 13)) ->y : Symbol(y, Decl(contextuallyTypedParametersWithInitializers.ts, 59, 23)) +>add : Symbol(add, Decl(contextuallyTypedParametersWithInitializers1.ts, 57, 57)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 59, 13)) +>y : Symbol(y, Decl(contextuallyTypedParametersWithInitializers1.ts, 59, 23)) return x + y; ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 59, 13)) ->y : Symbol(y, Decl(contextuallyTypedParametersWithInitializers.ts, 59, 23)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 59, 13)) +>y : Symbol(y, Decl(contextuallyTypedParametersWithInitializers1.ts, 59, 23)) } const memoizedAdd = memoize(add); ->memoizedAdd : Symbol(memoizedAdd, Decl(contextuallyTypedParametersWithInitializers.ts, 62, 5)) ->memoize : Symbol(memoize, Decl(contextuallyTypedParametersWithInitializers.ts, 53, 3)) ->add : Symbol(add, Decl(contextuallyTypedParametersWithInitializers.ts, 57, 57)) +>memoizedAdd : Symbol(memoizedAdd, Decl(contextuallyTypedParametersWithInitializers1.ts, 62, 5)) +>memoize : Symbol(memoize, Decl(contextuallyTypedParametersWithInitializers1.ts, 53, 3)) +>add : Symbol(add, Decl(contextuallyTypedParametersWithInitializers1.ts, 57, 57)) const add2 = (x: number, y = 0): number => x + y; ->add2 : Symbol(add2, Decl(contextuallyTypedParametersWithInitializers.ts, 64, 5)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 64, 14)) ->y : Symbol(y, Decl(contextuallyTypedParametersWithInitializers.ts, 64, 24)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 64, 14)) ->y : Symbol(y, Decl(contextuallyTypedParametersWithInitializers.ts, 64, 24)) +>add2 : Symbol(add2, Decl(contextuallyTypedParametersWithInitializers1.ts, 64, 5)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 64, 14)) +>y : Symbol(y, Decl(contextuallyTypedParametersWithInitializers1.ts, 64, 24)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 64, 14)) +>y : Symbol(y, Decl(contextuallyTypedParametersWithInitializers1.ts, 64, 24)) const memoizedAdd2 = memoize(add2); ->memoizedAdd2 : Symbol(memoizedAdd2, Decl(contextuallyTypedParametersWithInitializers.ts, 65, 5)) ->memoize : Symbol(memoize, Decl(contextuallyTypedParametersWithInitializers.ts, 53, 3)) ->add2 : Symbol(add2, Decl(contextuallyTypedParametersWithInitializers.ts, 64, 5)) +>memoizedAdd2 : Symbol(memoizedAdd2, Decl(contextuallyTypedParametersWithInitializers1.ts, 65, 5)) +>memoize : Symbol(memoize, Decl(contextuallyTypedParametersWithInitializers1.ts, 53, 3)) +>add2 : Symbol(add2, Decl(contextuallyTypedParametersWithInitializers1.ts, 64, 5)) const memoizedAdd3 = memoize((x: number, y = 0): number => x + y); ->memoizedAdd3 : Symbol(memoizedAdd3, Decl(contextuallyTypedParametersWithInitializers.ts, 67, 5)) ->memoize : Symbol(memoize, Decl(contextuallyTypedParametersWithInitializers.ts, 53, 3)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 67, 30)) ->y : Symbol(y, Decl(contextuallyTypedParametersWithInitializers.ts, 67, 40)) ->x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 67, 30)) ->y : Symbol(y, Decl(contextuallyTypedParametersWithInitializers.ts, 67, 40)) +>memoizedAdd3 : Symbol(memoizedAdd3, Decl(contextuallyTypedParametersWithInitializers1.ts, 67, 5)) +>memoize : Symbol(memoize, Decl(contextuallyTypedParametersWithInitializers1.ts, 53, 3)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 67, 30)) +>y : Symbol(y, Decl(contextuallyTypedParametersWithInitializers1.ts, 67, 40)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers1.ts, 67, 30)) +>y : Symbol(y, Decl(contextuallyTypedParametersWithInitializers1.ts, 67, 40)) // Repro from #36052 declare function execute(script: string | Function): Promise; ->execute : Symbol(execute, Decl(contextuallyTypedParametersWithInitializers.ts, 67, 66)) ->script : Symbol(script, Decl(contextuallyTypedParametersWithInitializers.ts, 71, 25)) +>execute : Symbol(execute, Decl(contextuallyTypedParametersWithInitializers1.ts, 67, 66)) +>script : Symbol(script, Decl(contextuallyTypedParametersWithInitializers1.ts, 71, 25)) >Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --)) export function executeSomething() { ->executeSomething : Symbol(executeSomething, Decl(contextuallyTypedParametersWithInitializers.ts, 71, 69)) +>executeSomething : Symbol(executeSomething, Decl(contextuallyTypedParametersWithInitializers1.ts, 71, 69)) return execute((root: HTMLElement, debug = true) => { ->execute : Symbol(execute, Decl(contextuallyTypedParametersWithInitializers.ts, 67, 66)) ->root : Symbol(root, Decl(contextuallyTypedParametersWithInitializers.ts, 74, 20)) +>execute : Symbol(execute, Decl(contextuallyTypedParametersWithInitializers1.ts, 67, 66)) +>root : Symbol(root, Decl(contextuallyTypedParametersWithInitializers1.ts, 74, 20)) >HTMLElement : Symbol(HTMLElement, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) ->debug : Symbol(debug, Decl(contextuallyTypedParametersWithInitializers.ts, 74, 38)) +>debug : Symbol(debug, Decl(contextuallyTypedParametersWithInitializers1.ts, 74, 38)) if (debug) { ->debug : Symbol(debug, Decl(contextuallyTypedParametersWithInitializers.ts, 74, 38)) +>debug : Symbol(debug, Decl(contextuallyTypedParametersWithInitializers1.ts, 74, 38)) root.innerHTML = ''; >root.innerHTML : Symbol(InnerHTML.innerHTML, Decl(lib.dom.d.ts, --, --)) ->root : Symbol(root, Decl(contextuallyTypedParametersWithInitializers.ts, 74, 20)) +>root : Symbol(root, Decl(contextuallyTypedParametersWithInitializers1.ts, 74, 20)) >innerHTML : Symbol(InnerHTML.innerHTML, Decl(lib.dom.d.ts, --, --)) } }); } const fz1 = (debug = true) => false; ->fz1 : Symbol(fz1, Decl(contextuallyTypedParametersWithInitializers.ts, 81, 5)) ->debug : Symbol(debug, Decl(contextuallyTypedParametersWithInitializers.ts, 81, 13)) +>fz1 : Symbol(fz1, Decl(contextuallyTypedParametersWithInitializers1.ts, 81, 5)) +>debug : Symbol(debug, Decl(contextuallyTypedParametersWithInitializers1.ts, 81, 13)) const fz2: Function = (debug = true) => false; ->fz2 : Symbol(fz2, Decl(contextuallyTypedParametersWithInitializers.ts, 82, 5)) +>fz2 : Symbol(fz2, Decl(contextuallyTypedParametersWithInitializers1.ts, 82, 5)) >Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->debug : Symbol(debug, Decl(contextuallyTypedParametersWithInitializers.ts, 82, 23)) +>debug : Symbol(debug, Decl(contextuallyTypedParametersWithInitializers1.ts, 82, 23)) diff --git a/tests/baselines/reference/contextuallyTypedParametersWithInitializers.types b/tests/baselines/reference/contextuallyTypedParametersWithInitializers1.types similarity index 95% rename from tests/baselines/reference/contextuallyTypedParametersWithInitializers.types rename to tests/baselines/reference/contextuallyTypedParametersWithInitializers1.types index e55c3685d7ab8..5a178b7bb7efb 100644 --- a/tests/baselines/reference/contextuallyTypedParametersWithInitializers.types +++ b/tests/baselines/reference/contextuallyTypedParametersWithInitializers1.types @@ -1,6 +1,6 @@ -//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts] //// +//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers1.ts] //// -=== contextuallyTypedParametersWithInitializers.ts === +=== contextuallyTypedParametersWithInitializers1.ts === declare function id1(input: T): T; >id1 : (input: T) => T >input : T diff --git a/tests/baselines/reference/contextuallyTypedParametersWithInitializers2.symbols b/tests/baselines/reference/contextuallyTypedParametersWithInitializers2.symbols new file mode 100644 index 0000000000000..53a8082c893bf --- /dev/null +++ b/tests/baselines/reference/contextuallyTypedParametersWithInitializers2.symbols @@ -0,0 +1,58 @@ +//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers2.ts] //// + +=== contextuallyTypedParametersWithInitializers2.ts === +declare function test1< +>test1 : Symbol(test1, Decl(contextuallyTypedParametersWithInitializers2.ts, 0, 0)) + + TContext, +>TContext : Symbol(TContext, Decl(contextuallyTypedParametersWithInitializers2.ts, 0, 23)) + + TMethods extends Record unknown>, +>TMethods : Symbol(TMethods, Decl(contextuallyTypedParametersWithInitializers2.ts, 1, 11)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>ctx : Symbol(ctx, Decl(contextuallyTypedParametersWithInitializers2.ts, 2, 35)) +>TContext : Symbol(TContext, Decl(contextuallyTypedParametersWithInitializers2.ts, 0, 23)) +>args : Symbol(args, Decl(contextuallyTypedParametersWithInitializers2.ts, 2, 49)) + +>(context: TContext, methods: TMethods): void; +>context : Symbol(context, Decl(contextuallyTypedParametersWithInitializers2.ts, 3, 2)) +>TContext : Symbol(TContext, Decl(contextuallyTypedParametersWithInitializers2.ts, 0, 23)) +>methods : Symbol(methods, Decl(contextuallyTypedParametersWithInitializers2.ts, 3, 20)) +>TMethods : Symbol(TMethods, Decl(contextuallyTypedParametersWithInitializers2.ts, 1, 11)) + +test1( +>test1 : Symbol(test1, Decl(contextuallyTypedParametersWithInitializers2.ts, 0, 0)) + { + count: 0, +>count : Symbol(count, Decl(contextuallyTypedParametersWithInitializers2.ts, 6, 3)) + + }, + { + checkLimit: (ctx, max = 500) => {}, +>checkLimit : Symbol(checkLimit, Decl(contextuallyTypedParametersWithInitializers2.ts, 9, 3)) +>ctx : Symbol(ctx, Decl(contextuallyTypedParametersWithInitializers2.ts, 10, 17)) +>max : Symbol(max, Decl(contextuallyTypedParametersWithInitializers2.ts, 10, 21)) + + hasAccess: (ctx, user: { name: string }) => {}, +>hasAccess : Symbol(hasAccess, Decl(contextuallyTypedParametersWithInitializers2.ts, 10, 39)) +>ctx : Symbol(ctx, Decl(contextuallyTypedParametersWithInitializers2.ts, 11, 16)) +>user : Symbol(user, Decl(contextuallyTypedParametersWithInitializers2.ts, 11, 20)) +>name : Symbol(name, Decl(contextuallyTypedParametersWithInitializers2.ts, 11, 28)) + + }, +); + +declare const num: number; +>num : Symbol(num, Decl(contextuallyTypedParametersWithInitializers2.ts, 15, 13)) + +const test2: (arg: 1 | 2) => void = (arg = num) => {}; +>test2 : Symbol(test2, Decl(contextuallyTypedParametersWithInitializers2.ts, 16, 5)) +>arg : Symbol(arg, Decl(contextuallyTypedParametersWithInitializers2.ts, 16, 14)) +>arg : Symbol(arg, Decl(contextuallyTypedParametersWithInitializers2.ts, 16, 37)) +>num : Symbol(num, Decl(contextuallyTypedParametersWithInitializers2.ts, 15, 13)) + +const test3: (arg: number) => void = (arg = 1) => {}; +>test3 : Symbol(test3, Decl(contextuallyTypedParametersWithInitializers2.ts, 18, 5)) +>arg : Symbol(arg, Decl(contextuallyTypedParametersWithInitializers2.ts, 18, 14)) +>arg : Symbol(arg, Decl(contextuallyTypedParametersWithInitializers2.ts, 18, 38)) + diff --git a/tests/baselines/reference/contextuallyTypedParametersWithInitializers2.types b/tests/baselines/reference/contextuallyTypedParametersWithInitializers2.types new file mode 100644 index 0000000000000..cc18f89dd35f9 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypedParametersWithInitializers2.types @@ -0,0 +1,63 @@ +//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers2.ts] //// + +=== contextuallyTypedParametersWithInitializers2.ts === +declare function test1< +>test1 : unknown>>(context: TContext, methods: TMethods) => void + + TContext, + TMethods extends Record unknown>, +>ctx : TContext +>args : never[] + +>(context: TContext, methods: TMethods): void; +>context : TContext +>methods : TMethods + +test1( +>test1( { count: 0, }, { checkLimit: (ctx, max = 500) => {}, hasAccess: (ctx, user: { name: string }) => {}, },) : void +>test1 : unknown>>(context: TContext, methods: TMethods) => void + { +>{ count: 0, } : { count: number; } + + count: 0, +>count : number +>0 : 0 + + }, + { +>{ checkLimit: (ctx, max = 500) => {}, hasAccess: (ctx, user: { name: string }) => {}, } : { checkLimit: (ctx: { count: number; }, max?: number) => void; hasAccess: (ctx: { count: number; }, user: { name: string;}) => void; } + + checkLimit: (ctx, max = 500) => {}, +>checkLimit : (ctx: { count: number; }, max?: number) => void +>(ctx, max = 500) => {} : (ctx: { count: number; }, max?: number) => void +>ctx : { count: number; } +>max : number +>500 : 500 + + hasAccess: (ctx, user: { name: string }) => {}, +>hasAccess : (ctx: { count: number; }, user: { name: string;}) => void +>(ctx, user: { name: string }) => {} : (ctx: { count: number; }, user: { name: string;}) => void +>ctx : { count: number; } +>user : { name: string; } +>name : string + + }, +); + +declare const num: number; +>num : number + +const test2: (arg: 1 | 2) => void = (arg = num) => {}; +>test2 : (arg: 1 | 2) => void +>arg : 1 | 2 +>(arg = num) => {} : (arg?: number) => void +>arg : number +>num : number + +const test3: (arg: number) => void = (arg = 1) => {}; +>test3 : (arg: number) => void +>arg : number +>(arg = 1) => {} : (arg?: number) => void +>arg : number +>1 : 1 + diff --git a/tests/baselines/reference/contextuallyTypedParametersWithInitializers3.symbols b/tests/baselines/reference/contextuallyTypedParametersWithInitializers3.symbols new file mode 100644 index 0000000000000..5e59d656f61ca --- /dev/null +++ b/tests/baselines/reference/contextuallyTypedParametersWithInitializers3.symbols @@ -0,0 +1,40 @@ +//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers3.ts] //// + +=== contextuallyTypedParametersWithInitializers3.ts === +type CanvasDirection = "RIGHT" | "LEFT"; +>CanvasDirection : Symbol(CanvasDirection, Decl(contextuallyTypedParametersWithInitializers3.ts, 0, 0)) + +interface GraphActions { +>GraphActions : Symbol(GraphActions, Decl(contextuallyTypedParametersWithInitializers3.ts, 0, 40)) + + setDirection: (direction: CanvasDirection) => void; +>setDirection : Symbol(GraphActions.setDirection, Decl(contextuallyTypedParametersWithInitializers3.ts, 2, 24)) +>direction : Symbol(direction, Decl(contextuallyTypedParametersWithInitializers3.ts, 3, 17)) +>CanvasDirection : Symbol(CanvasDirection, Decl(contextuallyTypedParametersWithInitializers3.ts, 0, 0)) +} + +export declare function create(config: T): void; +>create : Symbol(create, Decl(contextuallyTypedParametersWithInitializers3.ts, 4, 1)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers3.ts, 6, 31)) +>config : Symbol(config, Decl(contextuallyTypedParametersWithInitializers3.ts, 6, 34)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers3.ts, 6, 31)) + +declare function takesDirection(direction: CanvasDirection): void; +>takesDirection : Symbol(takesDirection, Decl(contextuallyTypedParametersWithInitializers3.ts, 6, 51)) +>direction : Symbol(direction, Decl(contextuallyTypedParametersWithInitializers3.ts, 8, 32)) +>CanvasDirection : Symbol(CanvasDirection, Decl(contextuallyTypedParametersWithInitializers3.ts, 0, 0)) + +create({ +>create : Symbol(create, Decl(contextuallyTypedParametersWithInitializers3.ts, 4, 1)) +>GraphActions : Symbol(GraphActions, Decl(contextuallyTypedParametersWithInitializers3.ts, 0, 40)) + + setDirection: (direction = "RIGHT") => { +>setDirection : Symbol(setDirection, Decl(contextuallyTypedParametersWithInitializers3.ts, 10, 22)) +>direction : Symbol(direction, Decl(contextuallyTypedParametersWithInitializers3.ts, 11, 17)) + + takesDirection(direction); +>takesDirection : Symbol(takesDirection, Decl(contextuallyTypedParametersWithInitializers3.ts, 6, 51)) +>direction : Symbol(direction, Decl(contextuallyTypedParametersWithInitializers3.ts, 11, 17)) + + }, +}); diff --git a/tests/baselines/reference/contextuallyTypedParametersWithInitializers3.types b/tests/baselines/reference/contextuallyTypedParametersWithInitializers3.types new file mode 100644 index 0000000000000..096e964c7a1f7 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypedParametersWithInitializers3.types @@ -0,0 +1,38 @@ +//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers3.ts] //// + +=== contextuallyTypedParametersWithInitializers3.ts === +type CanvasDirection = "RIGHT" | "LEFT"; +>CanvasDirection : "RIGHT" | "LEFT" + +interface GraphActions { + setDirection: (direction: CanvasDirection) => void; +>setDirection : (direction: CanvasDirection) => void +>direction : CanvasDirection +} + +export declare function create(config: T): void; +>create : (config: T) => void +>config : T + +declare function takesDirection(direction: CanvasDirection): void; +>takesDirection : (direction: CanvasDirection) => void +>direction : CanvasDirection + +create({ +>create({ setDirection: (direction = "RIGHT") => { takesDirection(direction); },}) : void +>create : (config: T) => void +>{ setDirection: (direction = "RIGHT") => { takesDirection(direction); },} : { setDirection: (direction?: CanvasDirection) => void; } + + setDirection: (direction = "RIGHT") => { +>setDirection : (direction?: CanvasDirection) => void +>(direction = "RIGHT") => { takesDirection(direction); } : (direction?: CanvasDirection) => void +>direction : CanvasDirection +>"RIGHT" : "RIGHT" + + takesDirection(direction); +>takesDirection(direction) : void +>takesDirection : (direction: CanvasDirection) => void +>direction : CanvasDirection + + }, +}); diff --git a/tests/baselines/reference/contextuallyTypedParametersWithInitializers4.symbols b/tests/baselines/reference/contextuallyTypedParametersWithInitializers4.symbols new file mode 100644 index 0000000000000..9f003f9d3ca65 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypedParametersWithInitializers4.symbols @@ -0,0 +1,38 @@ +//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers4.ts] //// + +=== contextuallyTypedParametersWithInitializers4.ts === +declare function test< +>test : Symbol(test, Decl(contextuallyTypedParametersWithInitializers4.ts, 0, 0)) + + TContext, +>TContext : Symbol(TContext, Decl(contextuallyTypedParametersWithInitializers4.ts, 0, 22)) + + TMethods extends Record unknown>, +>TMethods : Symbol(TMethods, Decl(contextuallyTypedParametersWithInitializers4.ts, 1, 11)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>ctx : Symbol(ctx, Decl(contextuallyTypedParametersWithInitializers4.ts, 2, 35)) +>TContext : Symbol(TContext, Decl(contextuallyTypedParametersWithInitializers4.ts, 0, 22)) +>args : Symbol(args, Decl(contextuallyTypedParametersWithInitializers4.ts, 2, 49)) + +>(context: TContext, methods: TMethods): void; +>context : Symbol(context, Decl(contextuallyTypedParametersWithInitializers4.ts, 3, 2)) +>TContext : Symbol(TContext, Decl(contextuallyTypedParametersWithInitializers4.ts, 0, 22)) +>methods : Symbol(methods, Decl(contextuallyTypedParametersWithInitializers4.ts, 3, 20)) +>TMethods : Symbol(TMethods, Decl(contextuallyTypedParametersWithInitializers4.ts, 1, 11)) + +test( +>test : Symbol(test, Decl(contextuallyTypedParametersWithInitializers4.ts, 0, 0)) + { + count: 0, +>count : Symbol(count, Decl(contextuallyTypedParametersWithInitializers4.ts, 6, 3)) + + }, + { + checkLimit: (ctx, max = 3) => {}, +>checkLimit : Symbol(checkLimit, Decl(contextuallyTypedParametersWithInitializers4.ts, 9, 3)) +>ctx : Symbol(ctx, Decl(contextuallyTypedParametersWithInitializers4.ts, 10, 17)) +>max : Symbol(max, Decl(contextuallyTypedParametersWithInitializers4.ts, 10, 21)) + + }, +); + diff --git a/tests/baselines/reference/contextuallyTypedParametersWithInitializers4.types b/tests/baselines/reference/contextuallyTypedParametersWithInitializers4.types new file mode 100644 index 0000000000000..66dd8aa532828 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypedParametersWithInitializers4.types @@ -0,0 +1,39 @@ +//// [tests/cases/compiler/contextuallyTypedParametersWithInitializers4.ts] //// + +=== contextuallyTypedParametersWithInitializers4.ts === +declare function test< +>test : unknown>>(context: TContext, methods: TMethods) => void + + TContext, + TMethods extends Record unknown>, +>ctx : TContext +>args : (1 | 2)[] + +>(context: TContext, methods: TMethods): void; +>context : TContext +>methods : TMethods + +test( +>test( { count: 0, }, { checkLimit: (ctx, max = 3) => {}, },) : void +>test : unknown>>(context: TContext, methods: TMethods) => void + { +>{ count: 0, } : { count: number; } + + count: 0, +>count : number +>0 : 0 + + }, + { +>{ checkLimit: (ctx, max = 3) => {}, } : { checkLimit: (ctx: { count: number; }, max?: number) => void; } + + checkLimit: (ctx, max = 3) => {}, +>checkLimit : (ctx: { count: number; }, max?: number) => void +>(ctx, max = 3) => {} : (ctx: { count: number; }, max?: number) => void +>ctx : { count: number; } +>max : number +>3 : 3 + + }, +); + diff --git a/tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts b/tests/cases/compiler/contextuallyTypedParametersWithInitializers1.ts similarity index 100% rename from tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts rename to tests/cases/compiler/contextuallyTypedParametersWithInitializers1.ts diff --git a/tests/cases/compiler/contextuallyTypedParametersWithInitializers2.ts b/tests/cases/compiler/contextuallyTypedParametersWithInitializers2.ts new file mode 100644 index 0000000000000..d80e45ad859f0 --- /dev/null +++ b/tests/cases/compiler/contextuallyTypedParametersWithInitializers2.ts @@ -0,0 +1,22 @@ +// @strict: true +// @noEmit: true + +declare function test1< + TContext, + TMethods extends Record unknown>, +>(context: TContext, methods: TMethods): void; + +test1( + { + count: 0, + }, + { + checkLimit: (ctx, max = 500) => {}, + hasAccess: (ctx, user: { name: string }) => {}, + }, +); + +declare const num: number; +const test2: (arg: 1 | 2) => void = (arg = num) => {}; + +const test3: (arg: number) => void = (arg = 1) => {}; diff --git a/tests/cases/compiler/contextuallyTypedParametersWithInitializers3.ts b/tests/cases/compiler/contextuallyTypedParametersWithInitializers3.ts new file mode 100644 index 0000000000000..25b4dd9391277 --- /dev/null +++ b/tests/cases/compiler/contextuallyTypedParametersWithInitializers3.ts @@ -0,0 +1,18 @@ +// @strict: true +// @noEmit: true + +type CanvasDirection = "RIGHT" | "LEFT"; + +interface GraphActions { + setDirection: (direction: CanvasDirection) => void; +} + +export declare function create(config: T): void; + +declare function takesDirection(direction: CanvasDirection): void; + +create({ + setDirection: (direction = "RIGHT") => { + takesDirection(direction); + }, +}); \ No newline at end of file diff --git a/tests/cases/compiler/contextuallyTypedParametersWithInitializers4.ts b/tests/cases/compiler/contextuallyTypedParametersWithInitializers4.ts new file mode 100644 index 0000000000000..a28258acaf416 --- /dev/null +++ b/tests/cases/compiler/contextuallyTypedParametersWithInitializers4.ts @@ -0,0 +1,16 @@ +// @strict: true +// @noEmit: true + +declare function test< + TContext, + TMethods extends Record unknown>, +>(context: TContext, methods: TMethods): void; + +test( + { + count: 0, + }, + { + checkLimit: (ctx, max = 3) => {}, + }, +);