Skip to content

Commit 5887169

Browse files
author
Andy
authored
Fix bug: result of createUnionOrIntersectionProperty may be undefined (#21332)
1 parent a3ecfd8 commit 5887169

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5995,7 +5995,9 @@ namespace ts {
59955995
for (const memberType of types) {
59965996
for (const { escapedName } of getAugmentedPropertiesOfType(memberType)) {
59975997
if (!props.has(escapedName)) {
5998-
props.set(escapedName, createUnionOrIntersectionProperty(unionType as UnionType, escapedName));
5998+
const prop = createUnionOrIntersectionProperty(unionType as UnionType, escapedName);
5999+
// May be undefined if the property is private
6000+
if (prop) props.set(escapedName, prop);
59996001
}
60006002
}
60016003
}
@@ -6177,7 +6179,7 @@ namespace ts {
61776179
t;
61786180
}
61796181

6180-
function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: __String): Symbol {
6182+
function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: __String): Symbol | undefined {
61816183
let props: Symbol[];
61826184
const isUnion = containingType.flags & TypeFlags.Union;
61836185
const excludeModifiers = isUnion ? ModifierFlags.NonPublicAccessibilityModifier : 0;

tests/cases/fourslash/completionsUnion.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
////interface I { x: number; }
44
////interface Many<T> extends ReadonlyArray<T> { extra: number; }
5-
////const x: I | I[] | Many<string> = { /**/ };
5+
////class C { private priv: number; }
6+
////const x: I | I[] | Many<string> | C = { /**/ };
67

78
// We specifically filter out any array-like types.
9+
// Private members will be excluded by `createUnionOrIntersectionProperty`.
810
verify.completionsAt("", ["x"]);

0 commit comments

Comments
 (0)