Skip to content

Commit 5e20c1c

Browse files
author
Andy
authored
Merge pull request #15910 from Microsoft/primitives
getAllPossiblePropertiesOfTypes: Skip primitives
2 parents afee4fb + c4c9bf7 commit 5e20c1c

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5794,6 +5794,10 @@ namespace ts {
57945794
if (type.flags & TypeFlags.Union) {
57955795
const props = createMap<Symbol>();
57965796
for (const memberType of (type as UnionType).types) {
5797+
if (memberType.flags & TypeFlags.Primitive) {
5798+
continue;
5799+
}
5800+
57975801
for (const { name } of getPropertiesOfType(memberType)) {
57985802
if (!props.has(name)) {
57995803
props.set(name, createUnionOrIntersectionProperty(type as UnionType, name));

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2587,6 +2587,7 @@ namespace ts {
25872587
/**
25882588
* For a union, will include a property if it's defined in *any* of the member types.
25892589
* So for `{ a } | { b }`, this will include both `a` and `b`.
2590+
* Does not include properties of primitive types.
25902591
*/
25912592
/* @internal */ getAllPossiblePropertiesOfType(type: Type): Symbol[];
25922593
}

tests/cases/fourslash/completionListOfUnion.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
// @strictNullChecks: true
44

5-
// Non-objects should be skipped, so `| number | null` should have no effect on completions.
6-
////const x: { a: number, b: number } | { a: string, c: string } | { b: boolean } | number | null = { /*x*/ };
5+
// Primitives should be skipped, so `| number | null | undefined` should have no effect on completions.
6+
////const x: { a: number, b: number } | { a: string, c: string } | { b: boolean } | number | null | undefined = { /*x*/ };
77

88
////interface I { a: number; }
99
////function f(...args: Array<I | I[]>) {}
1010
////f({ /*f*/ });
1111

1212
goTo.marker("x");
13+
verify.completionListCount(3);
1314
verify.completionListContains("a", "(property) a: string | number");
1415
verify.completionListContains("b", "(property) b: number | boolean");
1516
verify.completionListContains("c", "(property) c: string");
1617

1718
goTo.marker("f");
1819
verify.completionListContains("a", "(property) a: number");
20+
// Also contains array members

0 commit comments

Comments
 (0)