Skip to content

Commit b9c3a99

Browse files
author
Andy Hanson
committed
getAllPossiblePropertiesOfTypes: Skip primitives
1 parent fc4dd2b commit b9c3a99

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5785,6 +5785,10 @@ namespace ts {
57855785
if (type.flags & TypeFlags.Union) {
57865786
const props = createMap<Symbol>();
57875787
for (const memberType of (type as UnionType).types) {
5788+
if (memberType.flags & TypeFlags.Primitive) {
5789+
continue;
5790+
}
5791+
57885792
for (const { name } of getPropertiesOfType(memberType)) {
57895793
if (!props.has(name)) {
57905794
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
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)