@@ -17929,13 +17929,13 @@ namespace ts {
17929
17929
let overflow = false;
17930
17930
let overrideNextErrorInfo = 0; // How many `reportRelationError` calls should be skipped in the elaboration pyramid
17931
17931
let lastSkippedInfo: [Type, Type] | undefined;
17932
- let incompatibleStack: [DiagnosticMessage, (string | number)?, (string | number)?, (string | number)?, (string | number)?][] = [] ;
17932
+ let incompatibleStack: [DiagnosticMessage, (string | number)?, (string | number)?, (string | number)?, (string | number)?][] | undefined ;
17933
17933
let inPropertyCheck = false;
17934
17934
17935
17935
Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
17936
17936
17937
17937
const result = isRelatedTo(source, target, RecursionFlags.Both, /*reportErrors*/ !!errorNode, headMessage);
17938
- if (incompatibleStack.length ) {
17938
+ if (incompatibleStack) {
17939
17939
reportIncompatibleStack();
17940
17940
}
17941
17941
if (overflow) {
@@ -17997,21 +17997,21 @@ namespace ts {
17997
17997
return {
17998
17998
errorInfo,
17999
17999
lastSkippedInfo,
18000
- incompatibleStack: incompatibleStack.slice(),
18000
+ incompatibleStack: incompatibleStack ? incompatibleStack .slice() : undefined ,
18001
18001
overrideNextErrorInfo,
18002
- relatedInfo: ! relatedInfo ? undefined : relatedInfo.slice() as ( [DiagnosticRelatedInformation, ...DiagnosticRelatedInformation[]] | undefined)
18002
+ relatedInfo: relatedInfo ? relatedInfo.slice() as [DiagnosticRelatedInformation, ...DiagnosticRelatedInformation[]] : undefined,
18003
18003
};
18004
18004
}
18005
18005
18006
18006
function reportIncompatibleError(message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number) {
18007
18007
overrideNextErrorInfo++; // Suppress the next relation error
18008
18008
lastSkippedInfo = undefined; // Reset skipped info cache
18009
- incompatibleStack.push([message, arg0, arg1, arg2, arg3]);
18009
+ ( incompatibleStack || (incompatibleStack = [])) .push([message, arg0, arg1, arg2, arg3]);
18010
18010
}
18011
18011
18012
18012
function reportIncompatibleStack() {
18013
- const stack = incompatibleStack;
18014
- incompatibleStack = [] ;
18013
+ const stack = incompatibleStack || [] ;
18014
+ incompatibleStack = undefined ;
18015
18015
const info = lastSkippedInfo;
18016
18016
lastSkippedInfo = undefined;
18017
18017
if (stack.length === 1) {
@@ -18025,7 +18025,7 @@ namespace ts {
18025
18025
// The first error will be the innermost, while the last will be the outermost - so by popping off the end,
18026
18026
// we can build from left to right
18027
18027
let path = "";
18028
- const secondaryRootErrors: typeof incompatibleStack = [];
18028
+ const secondaryRootErrors: [DiagnosticMessage, (string | number)?, (string | number)?, (string | number)?, (string | number)?][] = [];
18029
18029
while (stack.length) {
18030
18030
const [msg, ...args] = stack.pop()!;
18031
18031
switch (msg.code) {
@@ -18119,7 +18119,7 @@ namespace ts {
18119
18119
18120
18120
function reportError(message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): void {
18121
18121
Debug.assert(!!errorNode);
18122
- if (incompatibleStack.length ) reportIncompatibleStack();
18122
+ if (incompatibleStack) reportIncompatibleStack();
18123
18123
if (message.elidedInCompatabilityPyramid) return;
18124
18124
errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2, arg3);
18125
18125
}
@@ -18135,7 +18135,7 @@ namespace ts {
18135
18135
}
18136
18136
18137
18137
function reportRelationError(message: DiagnosticMessage | undefined, source: Type, target: Type) {
18138
- if (incompatibleStack.length ) reportIncompatibleStack();
18138
+ if (incompatibleStack) reportIncompatibleStack();
18139
18139
const [sourceType, targetType] = getTypeNamesForErrorDisplay(source, target);
18140
18140
let generalizedSource = source;
18141
18141
let generalizedSourceType = sourceType;
@@ -18308,41 +18308,41 @@ namespace ts {
18308
18308
if (relation === comparableRelation && !(target.flags & TypeFlags.Never) && isSimpleTypeRelatedTo(target, source, relation) ||
18309
18309
isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True;
18310
18310
18311
- const isPerformingExcessPropertyChecks = !(intersectionState & IntersectionState.Target) && (isObjectLiteralType(source) && getObjectFlags(source) & ObjectFlags.FreshLiteral);
18312
- if (isPerformingExcessPropertyChecks) {
18313
- if (hasExcessProperties(source as FreshObjectLiteralType, target, reportErrors)) {
18314
- if (reportErrors) {
18315
- reportRelationError(headMessage, source, originalTarget.aliasSymbol ? originalTarget : target);
18311
+ if (source.flags & TypeFlags.StructuredOrInstantiable || target.flags & TypeFlags.StructuredOrInstantiable) {
18312
+ const isPerformingExcessPropertyChecks = !(intersectionState & IntersectionState.Target) && (isObjectLiteralType(source) && getObjectFlags(source) & ObjectFlags.FreshLiteral);
18313
+ if (isPerformingExcessPropertyChecks) {
18314
+ if (hasExcessProperties(source as FreshObjectLiteralType, target, reportErrors)) {
18315
+ if (reportErrors) {
18316
+ reportRelationError(headMessage, source, originalTarget.aliasSymbol ? originalTarget : target);
18317
+ }
18318
+ return Ternary.False;
18316
18319
}
18317
- return Ternary.False;
18318
18320
}
18319
- }
18320
18321
18321
- const isPerformingCommonPropertyChecks = relation !== comparableRelation && !(intersectionState & IntersectionState.Target) &&
18322
- source.flags & (TypeFlags.Primitive | TypeFlags.Object | TypeFlags.Intersection) && source !== globalObjectType &&
18323
- target.flags & (TypeFlags.Object | TypeFlags.Intersection) && isWeakType(target) &&
18324
- (getPropertiesOfType(source).length > 0 || typeHasCallOrConstructSignatures(source));
18325
- const isComparingJsxAttributes = !!(getObjectFlags(source) & ObjectFlags.JsxAttributes);
18326
- if (isPerformingCommonPropertyChecks && !hasCommonProperties(source, target, isComparingJsxAttributes)) {
18327
- if (reportErrors) {
18328
- const sourceString = typeToString(originalSource.aliasSymbol ? originalSource : source);
18329
- const targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
18330
- const calls = getSignaturesOfType(source, SignatureKind.Call);
18331
- const constructs = getSignaturesOfType(source, SignatureKind.Construct);
18332
- if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, RecursionFlags.Source, /*reportErrors*/ false) ||
18333
- constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, RecursionFlags.Source, /*reportErrors*/ false)) {
18334
- reportError(Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
18335
- }
18336
- else {
18337
- reportError(Diagnostics.Type_0_has_no_properties_in_common_with_type_1, sourceString, targetString);
18322
+ const isPerformingCommonPropertyChecks = relation !== comparableRelation && !(intersectionState & IntersectionState.Target) &&
18323
+ source.flags & (TypeFlags.Primitive | TypeFlags.Object | TypeFlags.Intersection) && source !== globalObjectType &&
18324
+ target.flags & (TypeFlags.Object | TypeFlags.Intersection) && isWeakType(target) &&
18325
+ (getPropertiesOfType(source).length > 0 || typeHasCallOrConstructSignatures(source));
18326
+ const isComparingJsxAttributes = !!(getObjectFlags(source) & ObjectFlags.JsxAttributes);
18327
+ if (isPerformingCommonPropertyChecks && !hasCommonProperties(source, target, isComparingJsxAttributes)) {
18328
+ if (reportErrors) {
18329
+ const sourceString = typeToString(originalSource.aliasSymbol ? originalSource : source);
18330
+ const targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
18331
+ const calls = getSignaturesOfType(source, SignatureKind.Call);
18332
+ const constructs = getSignaturesOfType(source, SignatureKind.Construct);
18333
+ if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, RecursionFlags.Source, /*reportErrors*/ false) ||
18334
+ constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, RecursionFlags.Source, /*reportErrors*/ false)) {
18335
+ reportError(Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
18336
+ }
18337
+ else {
18338
+ reportError(Diagnostics.Type_0_has_no_properties_in_common_with_type_1, sourceString, targetString);
18339
+ }
18338
18340
}
18341
+ return Ternary.False;
18339
18342
}
18340
- return Ternary.False;
18341
- }
18342
18343
18343
- traceUnionsOrIntersectionsTooLarge(source, target);
18344
+ traceUnionsOrIntersectionsTooLarge(source, target);
18344
18345
18345
- if (source.flags & TypeFlags.StructuredOrInstantiable || target.flags & TypeFlags.StructuredOrInstantiable) {
18346
18346
const skipCaching = source.flags & TypeFlags.Union && (source as UnionType).types.length < 4 && !(target.flags & TypeFlags.Union) ||
18347
18347
target.flags & TypeFlags.Union && (target as UnionType).types.length < 4 && !(source.flags & TypeFlags.StructuredOrInstantiable);
18348
18348
let result = skipCaching ?
0 commit comments