mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-16 15:51:35 -05:00
* Property handle private/protected properties in unions of object types * Add regression test Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
e261cdd2f6
commit
b7d34594ba
@@ -10477,10 +10477,10 @@ namespace ts {
|
||||
}
|
||||
|
||||
function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: __String): Symbol | undefined {
|
||||
const propSet = createMap<Symbol>();
|
||||
let singleProp: Symbol | undefined;
|
||||
let propSet: Map<Symbol> | undefined;
|
||||
let indexTypes: Type[] | undefined;
|
||||
const isUnion = containingType.flags & TypeFlags.Union;
|
||||
const excludeModifiers = isUnion ? ModifierFlags.NonPublicAccessibilityModifier : 0;
|
||||
// Flags we want to propagate to the result if they exist in all source symbols
|
||||
let optionalFlag = isUnion ? SymbolFlags.None : SymbolFlags.Optional;
|
||||
let syntheticFlag = CheckFlags.SyntheticMethod;
|
||||
@@ -10490,16 +10490,25 @@ namespace ts {
|
||||
if (!(type === errorType || type.flags & TypeFlags.Never)) {
|
||||
const prop = getPropertyOfType(type, name);
|
||||
const modifiers = prop ? getDeclarationModifierFlagsFromSymbol(prop) : 0;
|
||||
if (prop && !(modifiers & excludeModifiers)) {
|
||||
if (prop) {
|
||||
if (isUnion) {
|
||||
optionalFlag |= (prop.flags & SymbolFlags.Optional);
|
||||
}
|
||||
else {
|
||||
optionalFlag &= prop.flags;
|
||||
}
|
||||
const id = "" + getSymbolId(prop);
|
||||
if (!propSet.has(id)) {
|
||||
propSet.set(id, prop);
|
||||
if (!singleProp) {
|
||||
singleProp = prop;
|
||||
}
|
||||
else if (prop !== singleProp) {
|
||||
if (!propSet) {
|
||||
propSet = createMap<Symbol>();
|
||||
propSet.set("" + getSymbolId(singleProp), singleProp);
|
||||
}
|
||||
const id = "" + getSymbolId(prop);
|
||||
if (!propSet.has(id)) {
|
||||
propSet.set(id, prop);
|
||||
}
|
||||
}
|
||||
checkFlags |= (isReadonlySymbol(prop) ? CheckFlags.Readonly : 0) |
|
||||
(!(modifiers & ModifierFlags.NonPublicAccessibilityModifier) ? CheckFlags.ContainsPublic : 0) |
|
||||
@@ -10526,13 +10535,15 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!propSet.size) {
|
||||
if (!singleProp || isUnion && (propSet || checkFlags & CheckFlags.Partial) && checkFlags & (CheckFlags.ContainsPrivate | CheckFlags.ContainsProtected)) {
|
||||
// No property was found, or, in a union, a property has a private or protected declaration in one
|
||||
// constituent, but is missing or has a different declaration in another constituent.
|
||||
return undefined;
|
||||
}
|
||||
const props = arrayFrom(propSet.values());
|
||||
if (props.length === 1 && !(checkFlags & CheckFlags.ReadPartial) && !indexTypes) {
|
||||
return props[0];
|
||||
if (!propSet && !(checkFlags & CheckFlags.ReadPartial) && !indexTypes) {
|
||||
return singleProp;
|
||||
}
|
||||
const props = propSet ? arrayFrom(propSet.values()) : [singleProp];
|
||||
let declarations: Declaration[] | undefined;
|
||||
let firstType: Type | undefined;
|
||||
let nameType: Type | undefined;
|
||||
|
||||
Reference in New Issue
Block a user