@@ -4148,7 +4148,9 @@ namespace ts {
4148
4148
return undefined!; // TODO: GH#18217
4149
4149
}
4150
4150
4151
- type = getReducedType(type);
4151
+ if (!(context.flags & NodeBuilderFlags.NoTypeReduction)) {
4152
+ type = getReducedType(type);
4153
+ }
4152
4154
4153
4155
if (type.flags & TypeFlags.Any) {
4154
4156
context.approximateLength += 3;
@@ -8460,17 +8462,20 @@ namespace ts {
8460
8462
error(baseTypeNode.expression, Diagnostics.No_base_constructor_has_the_specified_number_of_type_arguments);
8461
8463
return type.resolvedBaseTypes = emptyArray;
8462
8464
}
8463
- baseType = getReducedType( getReturnTypeOfSignature(constructors[0]) );
8465
+ baseType = getReturnTypeOfSignature(constructors[0]);
8464
8466
}
8465
8467
8466
8468
if (baseType === errorType) {
8467
8469
return type.resolvedBaseTypes = emptyArray;
8468
8470
}
8469
- if (!isValidBaseType(baseType)) {
8470
- error(baseTypeNode.expression, Diagnostics.Base_constructor_return_type_0_is_not_an_object_type_or_intersection_of_object_types_with_statically_known_members, typeToString(baseType));
8471
+ const reducedBaseType = getReducedType(baseType);
8472
+ if (!isValidBaseType(reducedBaseType)) {
8473
+ const elaboration = elaborateNeverIntersection(/*errorInfo*/ undefined, baseType);
8474
+ const diagnostic = chainDiagnosticMessages(elaboration, Diagnostics.Base_constructor_return_type_0_is_not_an_object_type_or_intersection_of_object_types_with_statically_known_members, typeToString(reducedBaseType));
8475
+ diagnostics.add(createDiagnosticForNodeFromMessageChain(baseTypeNode.expression, diagnostic));
8471
8476
return type.resolvedBaseTypes = emptyArray;
8472
8477
}
8473
- if (type === baseType || hasBaseType(baseType , type)) {
8478
+ if (type === reducedBaseType || hasBaseType(reducedBaseType , type)) {
8474
8479
error(type.symbol.valueDeclaration, Diagnostics.Type_0_recursively_references_itself_as_a_base_type,
8475
8480
typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType));
8476
8481
return type.resolvedBaseTypes = emptyArray;
@@ -8482,7 +8487,7 @@ namespace ts {
8482
8487
// partial instantiation of the members without the base types fully resolved
8483
8488
type.members = undefined;
8484
8489
}
8485
- return type.resolvedBaseTypes = [baseType ];
8490
+ return type.resolvedBaseTypes = [reducedBaseType ];
8486
8491
}
8487
8492
8488
8493
function areAllOuterTypeParametersApplied(type: Type): boolean { // TODO: GH#18217 Shouldn't this take an InterfaceType?
@@ -10457,7 +10462,7 @@ namespace ts {
10457
10462
else if (type.flags & TypeFlags.Intersection) {
10458
10463
if (!((<IntersectionType>type).objectFlags & ObjectFlags.IsNeverIntersectionComputed)) {
10459
10464
(<IntersectionType>type).objectFlags |= ObjectFlags.IsNeverIntersectionComputed |
10460
- (some(getPropertiesOfUnionOrIntersectionType(<IntersectionType>type), isDiscriminantWithNeverType ) ? ObjectFlags.IsNeverIntersection : 0);
10465
+ (some(getPropertiesOfUnionOrIntersectionType(<IntersectionType>type), isNeverReducedProperty ) ? ObjectFlags.IsNeverIntersection : 0);
10461
10466
}
10462
10467
return (<IntersectionType>type).objectFlags & ObjectFlags.IsNeverIntersection ? neverType : type;
10463
10468
}
@@ -10476,12 +10481,39 @@ namespace ts {
10476
10481
return reduced;
10477
10482
}
10478
10483
10484
+ function isNeverReducedProperty(prop: Symbol) {
10485
+ return isDiscriminantWithNeverType(prop) || isConflictingPrivateProperty(prop);
10486
+ }
10487
+
10479
10488
function isDiscriminantWithNeverType(prop: Symbol) {
10489
+ // Return true for a synthetic non-optional property with non-uniform types, where at least one is
10490
+ // a literal type and none is never, that reduces to never.
10480
10491
return !(prop.flags & SymbolFlags.Optional) &&
10481
10492
(getCheckFlags(prop) & (CheckFlags.Discriminant | CheckFlags.HasNeverType)) === CheckFlags.Discriminant &&
10482
10493
!!(getTypeOfSymbol(prop).flags & TypeFlags.Never);
10483
10494
}
10484
10495
10496
+ function isConflictingPrivateProperty(prop: Symbol) {
10497
+ // Return true for a synthetic property with multiple declarations, at least one of which is private.
10498
+ return !prop.valueDeclaration && !!(getCheckFlags(prop) & CheckFlags.ContainsPrivate);
10499
+ }
10500
+
10501
+ function elaborateNeverIntersection(errorInfo: DiagnosticMessageChain | undefined, type: Type) {
10502
+ if (getObjectFlags(type) & ObjectFlags.IsNeverIntersection) {
10503
+ const neverProp = find(getPropertiesOfUnionOrIntersectionType(<IntersectionType>type), isDiscriminantWithNeverType);
10504
+ if (neverProp) {
10505
+ return chainDiagnosticMessages(errorInfo, Diagnostics.The_intersection_0_was_reduced_to_never_because_property_1_has_conflicting_types_in_some_constituents,
10506
+ typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.NoTypeReduction), symbolToString(neverProp));
10507
+ }
10508
+ const privateProp = find(getPropertiesOfUnionOrIntersectionType(<IntersectionType>type), isConflictingPrivateProperty);
10509
+ if (privateProp) {
10510
+ return chainDiagnosticMessages(errorInfo, Diagnostics.The_intersection_0_was_reduced_to_never_because_property_1_exists_in_multiple_constituents_and_is_private_in_some,
10511
+ typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.NoTypeReduction), symbolToString(privateProp));
10512
+ }
10513
+ }
10514
+ return errorInfo;
10515
+ }
10516
+
10485
10517
/**
10486
10518
* Return the symbol for the property with the given name in the given type. Creates synthetic union properties when
10487
10519
* necessary, maps primitive types and type parameters are to their apparent types, and augments with properties from
@@ -15609,6 +15641,9 @@ namespace ts {
15609
15641
return result;
15610
15642
}
15611
15643
}
15644
+ else {
15645
+ errorInfo = elaborateNeverIntersection(errorInfo, originalTarget);
15646
+ }
15612
15647
if (!headMessage && maybeSuppress) {
15613
15648
lastSkippedInfo = [source, target];
15614
15649
// Used by, eg, missing property checking to replace the top-level message with a more informative one
@@ -16490,14 +16525,7 @@ namespace ts {
16490
16525
const sourcePropFlags = getDeclarationModifierFlagsFromSymbol(sourceProp);
16491
16526
const targetPropFlags = getDeclarationModifierFlagsFromSymbol(targetProp);
16492
16527
if (sourcePropFlags & ModifierFlags.Private || targetPropFlags & ModifierFlags.Private) {
16493
- const hasDifferingDeclarations = sourceProp.valueDeclaration !== targetProp.valueDeclaration;
16494
- if (getCheckFlags(sourceProp) & CheckFlags.ContainsPrivate && hasDifferingDeclarations) {
16495
- if (reportErrors) {
16496
- reportError(Diagnostics.Property_0_has_conflicting_declarations_and_is_inaccessible_in_type_1, symbolToString(sourceProp), typeToString(source));
16497
- }
16498
- return Ternary.False;
16499
- }
16500
- if (hasDifferingDeclarations) {
16528
+ if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) {
16501
16529
if (reportErrors) {
16502
16530
if (sourcePropFlags & ModifierFlags.Private && targetPropFlags & ModifierFlags.Private) {
16503
16531
reportError(Diagnostics.Types_have_separate_declarations_of_a_private_property_0, symbolToString(targetProp));
@@ -23634,12 +23662,6 @@ namespace ts {
23634
23662
const flags = getDeclarationModifierFlagsFromSymbol(prop);
23635
23663
const errorNode = node.kind === SyntaxKind.QualifiedName ? node.right : node.kind === SyntaxKind.ImportType ? node : node.name;
23636
23664
23637
- if (getCheckFlags(prop) & CheckFlags.ContainsPrivate) {
23638
- // Synthetic property with private constituent property
23639
- error(errorNode, Diagnostics.Property_0_has_conflicting_declarations_and_is_inaccessible_in_type_1, symbolToString(prop), typeToString(type));
23640
- return false;
23641
- }
23642
-
23643
23665
if (isSuper) {
23644
23666
// TS 1.0 spec (April 2014): 4.8.2
23645
23667
// - In a constructor, instance member function, instance member accessor, or
@@ -24135,7 +24157,7 @@ namespace ts {
24135
24157
relatedInfo = suggestion.valueDeclaration && createDiagnosticForNode(suggestion.valueDeclaration, Diagnostics._0_is_declared_here, suggestedName);
24136
24158
}
24137
24159
else {
24138
- errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
24160
+ errorInfo = chainDiagnosticMessages(elaborateNeverIntersection( errorInfo, containingType) , Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
24139
24161
}
24140
24162
}
24141
24163
}
0 commit comments