From 1bc438961579496fc9ebfe83d039afb6cdb284b0 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 24 Jan 2019 17:07:44 -0800 Subject: [PATCH] Add tests --- ...extuallyTypedParametersWithInitializers.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts diff --git a/tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts b/tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts new file mode 100644 index 00000000000..e68be5b7bfd --- /dev/null +++ b/tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts @@ -0,0 +1,32 @@ +// @strict: true +// @declaration: true + +declare function id1(input: T): T; +declare function id2 any>(input: T): T; +declare function id3 any>(input: T): T; +declare function id4 any>(input: T): T; +declare function id5 any>(input: T): T; + +const f10 = function ({ foo = 42 }) { return foo }; +const f11 = id1(function ({ foo = 42 }) { return foo }); // Implicit any error +const f12 = id2(function ({ foo = 42 }) { return foo }); +const f13 = id3(function ({ foo = 42 }) { return foo }); +const f14 = id4(function ({ foo = 42 }) { return foo }); + +const f20 = function (foo = 42) { return foo }; +const f21 = id1(function (foo = 42) { return foo }); // Implicit any error +const f22 = id2(function (foo = 42) { return foo }); +const f25 = id5(function (foo = 42) { return foo }); + +// Repro from #28816 + +function id(input: T): T { return input } + +function getFoo ({ foo = 42 }) { + return foo; +} + +const newGetFoo = id(getFoo); +const newGetFoo2 = id(function getFoo ({ foo = 42 }) { + return foo; +});