From df6b9e57542b3c5c68cee0e340d1c82207e41dbc Mon Sep 17 00:00:00 2001 From: Tobias S Date: Tue, 14 Feb 2023 19:50:53 +0100 Subject: [PATCH] fix property completion in unions of object types and template literal types (#52196) --- src/compiler/types.ts | 2 +- ...nsObjectLiteralUnionTemplateLiteralType.ts | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionsObjectLiteralUnionTemplateLiteralType.ts diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 64f4f4075d4..94ae76b448b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -6053,7 +6053,7 @@ export const enum TypeFlags { /** @internal */ Intrinsic = Any | Unknown | String | Number | BigInt | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never | NonPrimitive, /** @internal */ - Primitive = String | Number | BigInt | Boolean | Enum | EnumLiteral | ESSymbol | Void | Undefined | Null | Literal | UniqueESSymbol, + Primitive = String | Number | BigInt | Boolean | Enum | EnumLiteral | ESSymbol | Void | Undefined | Null | Literal | UniqueESSymbol | TemplateLiteral, StringLike = String | StringLiteral | TemplateLiteral | StringMapping, NumberLike = Number | NumberLiteral | Enum, BigIntLike = BigInt | BigIntLiteral, diff --git a/tests/cases/fourslash/completionsObjectLiteralUnionTemplateLiteralType.ts b/tests/cases/fourslash/completionsObjectLiteralUnionTemplateLiteralType.ts new file mode 100644 index 00000000000..f1cdb69ce6f --- /dev/null +++ b/tests/cases/fourslash/completionsObjectLiteralUnionTemplateLiteralType.ts @@ -0,0 +1,26 @@ +/// + +////type UnionType = { +//// key1: string; +////} | { +//// key2: number; +////} | `string literal ${string}`; +//// +////const obj1: UnionType = { +//// /*1*/ +////}; +//// +////const obj2: UnionType = { +//// key1: "abc", +//// /*2*/ +////}; + +verify.completions({ + marker: '1', + exact: [{ name: 'key1' }, { name: 'key2' }] +}) + +verify.completions({ + marker: '2', + exact: [{ name: 'key2' }] +})