From f555ad73dbd9edbcde063fa81c12fac1de3e1269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 8 Mar 2023 01:36:37 +0100 Subject: [PATCH] Fix property completion in unions of object types and string mappings (#52767) --- src/compiler/types.ts | 4 +-- ...ionsObjectLiteralUnionStringMappingType.ts | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/completionsObjectLiteralUnionStringMappingType.ts diff --git a/src/compiler/types.ts b/src/compiler/types.ts index edd3e981083..936fe425cc1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -6086,8 +6086,6 @@ export const enum TypeFlags { PossiblyFalsy = DefinitelyFalsy | String | Number | BigInt | Boolean, /** @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 | TemplateLiteral, StringLike = String | StringLiteral | TemplateLiteral | StringMapping, NumberLike = Number | NumberLiteral | Enum, BigIntLike = BigInt | BigIntLiteral, @@ -6096,6 +6094,8 @@ export const enum TypeFlags { ESSymbolLike = ESSymbol | UniqueESSymbol, VoidLike = Void | Undefined, /** @internal */ + Primitive = StringLike | NumberLike | BigIntLike | BooleanLike | EnumLike | ESSymbolLike | VoidLike | Null, + /** @internal */ DefinitelyNonNullable = StringLike | NumberLike | BigIntLike | BooleanLike | EnumLike | ESSymbolLike | Object | NonPrimitive, /** @internal */ DisjointDomains = NonPrimitive | StringLike | NumberLike | BigIntLike | BooleanLike | ESSymbolLike | VoidLike | Null, diff --git a/tests/cases/fourslash/completionsObjectLiteralUnionStringMappingType.ts b/tests/cases/fourslash/completionsObjectLiteralUnionStringMappingType.ts new file mode 100644 index 00000000000..587bc54ad4a --- /dev/null +++ b/tests/cases/fourslash/completionsObjectLiteralUnionStringMappingType.ts @@ -0,0 +1,26 @@ +/// + +////type UnionType = { +//// key1: string; +////} | { +//// key2: number; +////} | Uppercase; +//// +////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' }] +})