diff --git a/src/harness/unittests/extractConstants.ts b/src/harness/unittests/extractConstants.ts index c09c00b34cf..71b550cba8f 100644 --- a/src/harness/unittests/extractConstants.ts +++ b/src/harness/unittests/extractConstants.ts @@ -267,6 +267,12 @@ namespace N { // Force this test to be TS-only testExtractConstant("extractConstant_ContextualType", ` interface I { a: 1 | 2 | 3 } let i: I = [#|{ a: 1 }|]; +`); + + testExtractConstant("extractConstant_ContextualType_Lambda", ` +const myObj: { member(x: number, y: string): void } = { + member: [#|(x, y) => x + y|], +} `); }); diff --git a/tests/baselines/reference/extractConstant/extractConstant_ContextualType_Lambda.ts b/tests/baselines/reference/extractConstant/extractConstant_ContextualType_Lambda.ts new file mode 100644 index 00000000000..d5a5a55bc27 --- /dev/null +++ b/tests/baselines/reference/extractConstant/extractConstant_ContextualType_Lambda.ts @@ -0,0 +1,11 @@ +// ==ORIGINAL== + +const myObj: { member(x: number, y: string): void } = { + member: /*[#|*/(x, y) => x + y/*|]*/, +} + +// ==SCOPE::Extract to constant in enclosing scope== +const newLocal: (x: number, y: string) => void = (x, y) => x + y; +const myObj: { member(x: number, y: string): void } = { + member: /*RENAME*/newLocal, +}