getAllPossiblePropertiesOfTypes: Skip primitives

This commit is contained in:
Andy Hanson
2017-05-17 08:26:00 -07:00
parent fc4dd2b4e5
commit b9c3a992e1
3 changed files with 7 additions and 0 deletions

View File

@@ -5785,6 +5785,10 @@ namespace ts {
if (type.flags & TypeFlags.Union) {
const props = createMap<Symbol>();
for (const memberType of (type as UnionType).types) {
if (memberType.flags & TypeFlags.Primitive) {
continue;
}
for (const { name } of getPropertiesOfType(memberType)) {
if (!props.has(name)) {
props.set(name, createUnionOrIntersectionProperty(type as UnionType, name));

View File

@@ -2587,6 +2587,7 @@ namespace ts {
/**
* For a union, will include a property if it's defined in *any* of the member types.
* So for `{ a } | { b }`, this will include both `a` and `b`.
* Does not include properties of primitive types.
*/
/* @internal */ getAllPossiblePropertiesOfType(type: Type): Symbol[];
}

View File

@@ -10,9 +10,11 @@
////f({ /*f*/ });
goTo.marker("x");
verify.completionListCount(3);
verify.completionListContains("a", "(property) a: string | number");
verify.completionListContains("b", "(property) b: number | boolean");
verify.completionListContains("c", "(property) c: string");
goTo.marker("f");
verify.completionListContains("a", "(property) a: number");
// Also contains array members