@@ -839,15 +839,16 @@ namespace ts {
839
839
}
840
840
841
841
function errorAndMaybeSuggestAwait(
842
- location: Node | undefined ,
842
+ location: Node,
843
843
maybeMissingAwait: boolean,
844
- defaultMessage: DiagnosticMessage,
845
- missingAwaitMessage: DiagnosticMessage,
844
+ message: DiagnosticMessage,
846
845
arg0?: string | number | undefined, arg1?: string | number | undefined, arg2?: string | number | undefined, arg3?: string | number | undefined): Diagnostic {
846
+ const diagnostic = error(location, message, arg0, arg1, arg2, arg3);
847
847
if (maybeMissingAwait) {
848
- return error(location, missingAwaitMessage, arg0, arg1, arg2, arg3);
848
+ const related = createDiagnosticForNode(location, Diagnostics.Did_you_forget_to_use_await);
849
+ addRelatedInfo(diagnostic, related);
849
850
}
850
- return error(location, defaultMessage, arg0, arg1, arg2, arg3) ;
851
+ return diagnostic ;
851
852
}
852
853
853
854
function createSymbol(flags: SymbolFlags, name: __String, checkFlags?: CheckFlags) {
@@ -22068,11 +22069,11 @@ namespace ts {
22068
22069
return true;
22069
22070
}
22070
22071
22071
- function invocationErrorDetails(apparentType: Type, kind: SignatureKind): DiagnosticMessageChain {
22072
+ function invocationErrorDetails(apparentType: Type, kind: SignatureKind): { messageChain: DiagnosticMessageChain, relatedMessage: DiagnosticMessage | undefined } {
22072
22073
let errorInfo: DiagnosticMessageChain | undefined;
22073
22074
const isCall = kind === SignatureKind.Call;
22074
22075
const awaitedType = getAwaitedType(apparentType);
22075
- const mightWorkWithAwait = awaitedType && getSignaturesOfType(awaitedType, kind).length > 0;
22076
+ const maybeMissingAwait = awaitedType && getSignaturesOfType(awaitedType, kind).length > 0;
22076
22077
if (apparentType.flags & TypeFlags.Union) {
22077
22078
const types = (apparentType as UnionType).types;
22078
22079
let hasSignatures = false;
@@ -22137,15 +22138,20 @@ namespace ts {
22137
22138
typeToString(apparentType)
22138
22139
);
22139
22140
}
22140
- return chainDiagnosticMessages(
22141
- errorInfo,
22142
- mightWorkWithAwait
22143
- ? isCall ? Diagnostics.This_expression_is_not_callable_Did_you_forget_to_use_await : Diagnostics.This_expression_is_not_constructable_Did_you_forget_to_use_await
22144
- : isCall ? Diagnostics.This_expression_is_not_callable : Diagnostics.This_expression_is_not_constructable
22145
- );
22141
+ return {
22142
+ messageChain: chainDiagnosticMessages(
22143
+ errorInfo,
22144
+ isCall ? Diagnostics.This_expression_is_not_callable : Diagnostics.This_expression_is_not_constructable
22145
+ ),
22146
+ relatedMessage: maybeMissingAwait ? Diagnostics.Did_you_forget_to_use_await : undefined,
22147
+ };
22146
22148
}
22147
22149
function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, relatedInformation?: DiagnosticRelatedInformation) {
22148
- const diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, invocationErrorDetails(apparentType, kind));
22150
+ const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(apparentType, kind);
22151
+ const diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain);
22152
+ if (relatedInfo) {
22153
+ addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo));
22154
+ }
22149
22155
if (isCallExpression(errorTarget.parent)) {
22150
22156
const { start, length } = getDiagnosticSpanForCallNode(errorTarget.parent, /* doNotIncludeArguments */ true);
22151
22157
diagnostic.start = start;
@@ -22245,9 +22251,12 @@ namespace ts {
22245
22251
22246
22252
const headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
22247
22253
if (!callSignatures.length) {
22248
- let errorInfo = invocationErrorDetails(apparentType, SignatureKind.Call);
22249
- errorInfo = chainDiagnosticMessages(errorInfo, headMessage);
22250
- const diag = createDiagnosticForNodeFromMessageChain(node.expression, errorInfo);
22254
+ const errorDetails = invocationErrorDetails(apparentType, SignatureKind.Call);
22255
+ const messageChain = chainDiagnosticMessages(errorDetails.messageChain, headMessage);
22256
+ const diag = createDiagnosticForNodeFromMessageChain(node.expression, messageChain);
22257
+ if (errorDetails.relatedMessage) {
22258
+ addRelatedInfo(diag, createDiagnosticForNode(node.expression, errorDetails.relatedMessage));
22259
+ }
22251
22260
diagnostics.add(diag);
22252
22261
invocationErrorRecovery(apparentType, SignatureKind.Call, diag);
22253
22262
return resolveErrorCall(node);
@@ -23381,14 +23390,13 @@ namespace ts {
23381
23390
}
23382
23391
}
23383
23392
23384
- function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage, missingAwaitDiagnostic: DiagnosticMessage ): boolean {
23393
+ function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage): boolean {
23385
23394
if (!isTypeAssignableTo(type, numberOrBigIntType)) {
23386
23395
const awaitedType = getAwaitedType(type);
23387
23396
errorAndMaybeSuggestAwait(
23388
23397
operand,
23389
23398
!!awaitedType && isTypeAssignableTo(awaitedType, numberOrBigIntType),
23390
- diagnostic,
23391
- missingAwaitDiagnostic);
23399
+ diagnostic);
23392
23400
return false;
23393
23401
}
23394
23402
return true;
@@ -23586,8 +23594,7 @@ namespace ts {
23586
23594
case SyntaxKind.PlusPlusToken:
23587
23595
case SyntaxKind.MinusMinusToken:
23588
23596
const ok = checkArithmeticOperandType(node.operand, checkNonNullType(operandType, node.operand),
23589
- Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type,
23590
- Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type_Did_you_forget_to_use_await);
23597
+ Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type);
23591
23598
if (ok) {
23592
23599
// run check only if former checks succeeded to avoid reporting cascading errors
23593
23600
checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access);
@@ -23605,8 +23612,7 @@ namespace ts {
23605
23612
const ok = checkArithmeticOperandType(
23606
23613
node.operand,
23607
23614
checkNonNullType(operandType, node.operand),
23608
- Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type,
23609
- Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type_Did_you_forget_to_use_await);
23615
+ Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type);
23610
23616
if (ok) {
23611
23617
// run check only if former checks succeeded to avoid reporting cascading errors
23612
23618
checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access);
@@ -23996,8 +24002,8 @@ namespace ts {
23996
24002
}
23997
24003
else {
23998
24004
// otherwise just check each operand separately and report errors as normal
23999
- const leftOk = checkArithmeticOperandType(left, leftType, Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type, Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_Did_you_forget_to_use_await );
24000
- const rightOk = checkArithmeticOperandType(right, rightType, Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type, Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_Did_you_forget_to_use_await );
24005
+ const leftOk = checkArithmeticOperandType(left, leftType, Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type);
24006
+ const rightOk = checkArithmeticOperandType(right, rightType, Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type);
24001
24007
let resultType: Type;
24002
24008
// If both are any or unknown, allow operation; assume it will resolve to number
24003
24009
if ((isTypeAssignableToKind(leftType, TypeFlags.AnyOrUnknown) && isTypeAssignableToKind(rightType, TypeFlags.AnyOrUnknown)) ||
@@ -24250,7 +24256,6 @@ namespace ts {
24250
24256
errNode,
24251
24257
wouldWorkWithAwait,
24252
24258
Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2,
24253
- Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2_Did_you_forget_to_use_await,
24254
24259
tokenToString(operatorToken.kind),
24255
24260
leftStr,
24256
24261
rightStr,
@@ -24275,7 +24280,6 @@ namespace ts {
24275
24280
errNode,
24276
24281
maybeMissingAwait,
24277
24282
Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap,
24278
- Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap_Did_you_forget_to_use_await,
24279
24283
typeName, leftStr, rightStr);
24280
24284
}
24281
24285
@@ -27588,28 +27592,22 @@ namespace ts {
27588
27592
// number and string input is allowed, we want to say that number is not an
27589
27593
// array type or a string type.
27590
27594
const isIterable = !!getIteratedTypeOfIterable(inputType, /* errorNode */ undefined, allowAsyncIterables, /*allowSyncIterables*/ true, checkAssignability);
27591
- const [defaultDiagnostic, missingAwaitDiagnostic ]: [DiagnosticMessage, DiagnosticMessage | undefined ] = !allowStringInput || hasStringConstituent
27595
+ const [defaultDiagnostic, maybeMissingAwait ]: [DiagnosticMessage, boolean ] = !allowStringInput || hasStringConstituent
27592
27596
? downlevelIteration
27593
- ? [Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator, Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator_Did_you_forget_to_use_await ]
27597
+ ? [Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator, true ]
27594
27598
: isIterable
27595
- ? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators, undefined ]
27596
- : [Diagnostics.Type_0_is_not_an_array_type, Diagnostics.Type_0_is_not_an_array_type_Did_you_forget_to_use_await ]
27599
+ ? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators, false ]
27600
+ : [Diagnostics.Type_0_is_not_an_array_type, true ]
27597
27601
: downlevelIteration
27598
- ? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator, Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator_Did_you_forget_to_use_await ]
27602
+ ? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator, true ]
27599
27603
: isIterable
27600
- ? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators, undefined]
27601
- : [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type, Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Did_you_forget_to_use_await];
27602
- if (missingAwaitDiagnostic) {
27603
- errorAndMaybeSuggestAwait(
27604
- errorNode,
27605
- !!getAwaitedTypeOfPromise(arrayType),
27606
- defaultDiagnostic,
27607
- missingAwaitDiagnostic,
27608
- typeToString(arrayType));
27609
- }
27610
- else {
27611
- error(errorNode, defaultDiagnostic, typeToString(arrayType));
27612
- }
27604
+ ? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators, false]
27605
+ : [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type, true];
27606
+ errorAndMaybeSuggestAwait(
27607
+ errorNode,
27608
+ maybeMissingAwait && !!getAwaitedTypeOfPromise(arrayType),
27609
+ defaultDiagnostic,
27610
+ typeToString(arrayType));
27613
27611
}
27614
27612
return hasStringConstituent ? stringType : undefined;
27615
27613
}
@@ -27740,10 +27738,10 @@ namespace ts {
27740
27738
}
27741
27739
27742
27740
function reportTypeNotIterableError(errorNode: Node, type: Type, allowAsyncIterables: boolean): void {
27743
- const [defaultDiagnostic, missingAwaitDiagnostic] = allowAsyncIterables
27744
- ? [ Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator, Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator_Did_you_forget_to_use_await]
27745
- : [ Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator, Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator_Did_you_forget_to_use_await] ;
27746
- errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), defaultDiagnostic, missingAwaitDiagnostic , typeToString(type));
27741
+ const message = allowAsyncIterables
27742
+ ? Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator
27743
+ : Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator;
27744
+ errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message , typeToString(type));
27747
27745
}
27748
27746
27749
27747
/**
0 commit comments