diff --git a/src/harness/unittests/extractConstants.ts b/src/harness/unittests/extractConstants.ts index 61ffbd01a63..c09c00b34cf 100644 --- a/src/harness/unittests/extractConstants.ts +++ b/src/harness/unittests/extractConstants.ts @@ -262,6 +262,12 @@ namespace N { // Force this test to be TS-only y = [#|this.x|]; } }`); + + // TODO (https://github.com/Microsoft/TypeScript/issues/20727): the extracted constant should have a type annotation. + testExtractConstant("extractConstant_ContextualType", ` +interface I { a: 1 | 2 | 3 } +let i: I = [#|{ a: 1 }|]; +`); }); function testExtractConstant(caption: string, text: string) { diff --git a/tests/baselines/reference/extractConstant/extractConstant_ContextualType.ts b/tests/baselines/reference/extractConstant/extractConstant_ContextualType.ts new file mode 100644 index 00000000000..fcec7db3bf4 --- /dev/null +++ b/tests/baselines/reference/extractConstant/extractConstant_ContextualType.ts @@ -0,0 +1,10 @@ +// ==ORIGINAL== + +interface I { a: 1 | 2 | 3 } +let i: I = /*[#|*/{ a: 1 }/*|]*/; + +// ==SCOPE::Extract to constant in enclosing scope== + +interface I { a: 1 | 2 | 3 } +const newLocal = { a: 1 }; +let i: I = /*RENAME*/newLocal;