From b9c3a992e1fb2fc1f437986a9dee113ab6c98f71 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 17 May 2017 08:26:00 -0700 Subject: [PATCH 1/2] getAllPossiblePropertiesOfTypes: Skip primitives --- src/compiler/checker.ts | 4 ++++ src/compiler/types.ts | 1 + tests/cases/fourslash/completionListOfUnion.ts | 2 ++ 3 files changed, 7 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2d464886653..953a72e2ecf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5785,6 +5785,10 @@ namespace ts { if (type.flags & TypeFlags.Union) { const props = createMap(); 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)); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 0283c45f2e1..d0962ac41d9 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -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[]; } diff --git a/tests/cases/fourslash/completionListOfUnion.ts b/tests/cases/fourslash/completionListOfUnion.ts index 6026615f8c1..8e6d1f20a32 100644 --- a/tests/cases/fourslash/completionListOfUnion.ts +++ b/tests/cases/fourslash/completionListOfUnion.ts @@ -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 From c4c9bf70c429fd5a22537691f841cfc5867db0b9 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 17 May 2017 12:51:37 -0700 Subject: [PATCH 2/2] Add `| undefined` to test --- tests/cases/fourslash/completionListOfUnion.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cases/fourslash/completionListOfUnion.ts b/tests/cases/fourslash/completionListOfUnion.ts index 8e6d1f20a32..5ffaf89e5b3 100644 --- a/tests/cases/fourslash/completionListOfUnion.ts +++ b/tests/cases/fourslash/completionListOfUnion.ts @@ -2,8 +2,8 @@ // @strictNullChecks: true -// Non-objects should be skipped, so `| number | null` should have no effect on completions. -////const x: { a: number, b: number } | { a: string, c: string } | { b: boolean } | number | null = { /*x*/ }; +// Primitives should be skipped, so `| number | null | undefined` should have no effect on completions. +////const x: { a: number, b: number } | { a: string, c: string } | { b: boolean } | number | null | undefined = { /*x*/ }; ////interface I { a: number; } ////function f(...args: Array) {}