@@ -2279,7 +2279,7 @@ namespace ts {
2279
2279
Debug.assert(typeNode !== undefined, "should always get typenode?");
2280
2280
const options = { removeComments: true };
2281
2281
const writer = createTextWriter("");
2282
- const printer = createPrinter(options, writer );
2282
+ const printer = createPrinter(options);
2283
2283
const sourceFile = enclosingDeclaration && getSourceFileOfNode(enclosingDeclaration);
2284
2284
printer.writeNode(EmitHint.Unspecified, typeNode, /*sourceFile*/ sourceFile, writer);
2285
2285
const result = writer.getText();
@@ -8668,6 +8668,7 @@ namespace ts {
8668
8668
let expandingFlags: number;
8669
8669
let depth = 0;
8670
8670
let overflow = false;
8671
+ let dynamicDisableWeakTypeErrors = false;
8671
8672
8672
8673
Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
8673
8674
@@ -8944,11 +8945,17 @@ namespace ts {
8944
8945
}
8945
8946
}
8946
8947
8947
- function typeRelatedToEachType(source: Type, target: UnionOrIntersectionType , reportErrors: boolean): Ternary {
8948
+ function typeRelatedToEachType(source: Type, target: IntersectionType , reportErrors: boolean): Ternary {
8948
8949
let result = Ternary.True;
8949
8950
const targetTypes = target.types;
8951
+ // disable weak-type detection for the main check
8952
+ // unless all of target.types are weak, in which case run weak type detection on the *combined* properties of target
8953
+ // at a minimum, do the first part.
8954
+ // but the thing should be flexible enough to easily do the second part as a separate call
8950
8955
for (const targetType of targetTypes) {
8956
+ dynamicDisableWeakTypeErrors = true;
8951
8957
const related = isRelatedTo(source, targetType, reportErrors);
8958
+ dynamicDisableWeakTypeErrors = false;
8952
8959
if (!related) {
8953
8960
return Ternary.False;
8954
8961
}
@@ -9326,7 +9333,7 @@ namespace ts {
9326
9333
}
9327
9334
}
9328
9335
}
9329
- if (!foundMatchingProperty && getPropertiesOfType(source).length > 0) {
9336
+ if (!foundMatchingProperty && !dynamicDisableWeakTypeErrors && getPropertiesOfType(source).length > 0) {
9330
9337
if (reportErrors) {
9331
9338
reportError(Diagnostics.Weak_type_0_has_no_properties_in_common_with_1, typeToString(target), typeToString(source));
9332
9339
}
@@ -10596,7 +10603,7 @@ namespace ts {
10596
10603
let props = getPropertiesOfType(type);
10597
10604
return type.flags & TypeFlags.Object &&
10598
10605
props.length > 0 &&
10599
- !forEach (props, p => !(p.flags & SymbolFlags.Optional)) &&
10606
+ every (props, p => ! !(p.flags & SymbolFlags.Optional)) &&
10600
10607
!getIndexTypeOfType(type, IndexKind.String) &&
10601
10608
!getIndexTypeOfType(type, IndexKind.Number);
10602
10609
}
@@ -22655,12 +22662,12 @@ namespace ts {
22655
22662
return symbols;
22656
22663
}
22657
22664
else if (symbol.flags & SymbolFlags.Transient) {
22658
- if (( symbol as SymbolLinks).leftSpread) {
22659
- const links = symbol as SymbolLinks;
22660
- return [...getRootSymbols(links .leftSpread), ...getRootSymbols(links .rightSpread)];
22665
+ const transient = symbol as TransientSymbol;
22666
+ if (transient.leftSpread) {
22667
+ return [...getRootSymbols(transient .leftSpread), ...getRootSymbols(transient .rightSpread)];
22661
22668
}
22662
- if ((symbol as SymbolLinks) .syntheticOrigin) {
22663
- return getRootSymbols((symbol as SymbolLinks) .syntheticOrigin);
22669
+ if (transient .syntheticOrigin) {
22670
+ return getRootSymbols(transient .syntheticOrigin);
22664
22671
}
22665
22672
22666
22673
let target: Symbol;
0 commit comments