@@ -933,15 +933,16 @@ namespace ts {
933
933
}
934
934
935
935
function errorAndMaybeSuggestAwait(
936
- location: Node | undefined ,
936
+ location: Node,
937
937
maybeMissingAwait: boolean,
938
- defaultMessage: DiagnosticMessage,
939
- missingAwaitMessage: DiagnosticMessage,
938
+ message: DiagnosticMessage,
940
939
arg0?: string | number | undefined, arg1?: string | number | undefined, arg2?: string | number | undefined, arg3?: string | number | undefined): Diagnostic {
940
+ const diagnostic = error(location, message, arg0, arg1, arg2, arg3);
941
941
if (maybeMissingAwait) {
942
- return error(location, missingAwaitMessage, arg0, arg1, arg2, arg3);
942
+ const related = createDiagnosticForNode(location, Diagnostics.Did_you_forget_to_use_await);
943
+ addRelatedInfo(diagnostic, related);
943
944
}
944
- return error(location, defaultMessage, arg0, arg1, arg2, arg3) ;
945
+ return diagnostic ;
945
946
}
946
947
947
948
function createSymbol(flags: SymbolFlags, name: __String, checkFlags?: CheckFlags) {
@@ -22350,11 +22351,11 @@ namespace ts {
22350
22351
return true;
22351
22352
}
22352
22353
22353
- function invocationErrorDetails(apparentType: Type, kind: SignatureKind): DiagnosticMessageChain {
22354
+ function invocationErrorDetails(apparentType: Type, kind: SignatureKind): { messageChain: DiagnosticMessageChain, relatedMessage: DiagnosticMessage | undefined } {
22354
22355
let errorInfo: DiagnosticMessageChain | undefined;
22355
22356
const isCall = kind === SignatureKind.Call;
22356
22357
const awaitedType = getAwaitedType(apparentType);
22357
- const mightWorkWithAwait = awaitedType && getSignaturesOfType(awaitedType, kind).length > 0;
22358
+ const maybeMissingAwait = awaitedType && getSignaturesOfType(awaitedType, kind).length > 0;
22358
22359
if (apparentType.flags & TypeFlags.Union) {
22359
22360
const types = (apparentType as UnionType).types;
22360
22361
let hasSignatures = false;
@@ -22419,15 +22420,20 @@ namespace ts {
22419
22420
typeToString(apparentType)
22420
22421
);
22421
22422
}
22422
- return chainDiagnosticMessages(
22423
- errorInfo,
22424
- mightWorkWithAwait
22425
- ? 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
22426
- : isCall ? Diagnostics.This_expression_is_not_callable : Diagnostics.This_expression_is_not_constructable
22427
- );
22423
+ return {
22424
+ messageChain: chainDiagnosticMessages(
22425
+ errorInfo,
22426
+ isCall ? Diagnostics.This_expression_is_not_callable : Diagnostics.This_expression_is_not_constructable
22427
+ ),
22428
+ relatedMessage: maybeMissingAwait ? Diagnostics.Did_you_forget_to_use_await : undefined,
22429
+ };
22428
22430
}
22429
22431
function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, relatedInformation?: DiagnosticRelatedInformation) {
22430
- const diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, invocationErrorDetails(apparentType, kind));
22432
+ const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(apparentType, kind);
22433
+ const diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain);
22434
+ if (relatedInfo) {
22435
+ addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo));
22436
+ }
22431
22437
if (isCallExpression(errorTarget.parent)) {
22432
22438
const { start, length } = getDiagnosticSpanForCallNode(errorTarget.parent, /* doNotIncludeArguments */ true);
22433
22439
diagnostic.start = start;
@@ -22527,9 +22533,12 @@ namespace ts {
22527
22533
22528
22534
const headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
22529
22535
if (!callSignatures.length) {
22530
- let errorInfo = invocationErrorDetails(apparentType, SignatureKind.Call);
22531
- errorInfo = chainDiagnosticMessages(errorInfo, headMessage);
22532
- const diag = createDiagnosticForNodeFromMessageChain(node.expression, errorInfo);
22536
+ const errorDetails = invocationErrorDetails(apparentType, SignatureKind.Call);
22537
+ const messageChain = chainDiagnosticMessages(errorDetails.messageChain, headMessage);
22538
+ const diag = createDiagnosticForNodeFromMessageChain(node.expression, messageChain);
22539
+ if (errorDetails.relatedMessage) {
22540
+ addRelatedInfo(diag, createDiagnosticForNode(node.expression, errorDetails.relatedMessage));
22541
+ }
22533
22542
diagnostics.add(diag);
22534
22543
invocationErrorRecovery(apparentType, SignatureKind.Call, diag);
22535
22544
return resolveErrorCall(node);
@@ -23687,14 +23696,13 @@ namespace ts {
23687
23696
}
23688
23697
}
23689
23698
23690
- function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage, missingAwaitDiagnostic: DiagnosticMessage ): boolean {
23699
+ function checkArithmeticOperandType(operand: Node, type: Type, diagnostic: DiagnosticMessage): boolean {
23691
23700
if (!isTypeAssignableTo(type, numberOrBigIntType)) {
23692
23701
const awaitedType = getAwaitedType(type);
23693
23702
errorAndMaybeSuggestAwait(
23694
23703
operand,
23695
23704
!!awaitedType && isTypeAssignableTo(awaitedType, numberOrBigIntType),
23696
- diagnostic,
23697
- missingAwaitDiagnostic);
23705
+ diagnostic);
23698
23706
return false;
23699
23707
}
23700
23708
return true;
@@ -23892,8 +23900,7 @@ namespace ts {
23892
23900
case SyntaxKind.PlusPlusToken:
23893
23901
case SyntaxKind.MinusMinusToken:
23894
23902
const ok = checkArithmeticOperandType(node.operand, checkNonNullType(operandType, node.operand),
23895
- Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type,
23896
- Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type_Did_you_forget_to_use_await);
23903
+ Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type);
23897
23904
if (ok) {
23898
23905
// run check only if former checks succeeded to avoid reporting cascading errors
23899
23906
checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access);
@@ -23911,8 +23918,7 @@ namespace ts {
23911
23918
const ok = checkArithmeticOperandType(
23912
23919
node.operand,
23913
23920
checkNonNullType(operandType, node.operand),
23914
- Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type,
23915
- Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type_Did_you_forget_to_use_await);
23921
+ Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type);
23916
23922
if (ok) {
23917
23923
// run check only if former checks succeeded to avoid reporting cascading errors
23918
23924
checkReferenceExpression(node.operand, Diagnostics.The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access);
@@ -24304,8 +24310,8 @@ namespace ts {
24304
24310
}
24305
24311
else {
24306
24312
// otherwise just check each operand separately and report errors as normal
24307
- 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 );
24308
- 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 );
24313
+ 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);
24314
+ 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);
24309
24315
let resultType: Type;
24310
24316
// If both are any or unknown, allow operation; assume it will resolve to number
24311
24317
if ((isTypeAssignableToKind(leftType, TypeFlags.AnyOrUnknown) && isTypeAssignableToKind(rightType, TypeFlags.AnyOrUnknown)) ||
@@ -24558,7 +24564,6 @@ namespace ts {
24558
24564
errNode,
24559
24565
wouldWorkWithAwait,
24560
24566
Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2,
24561
- Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2_Did_you_forget_to_use_await,
24562
24567
tokenToString(operatorToken.kind),
24563
24568
leftStr,
24564
24569
rightStr,
@@ -24583,7 +24588,6 @@ namespace ts {
24583
24588
errNode,
24584
24589
maybeMissingAwait,
24585
24590
Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap,
24586
- Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap_Did_you_forget_to_use_await,
24587
24591
typeName, leftStr, rightStr);
24588
24592
}
24589
24593
@@ -27937,28 +27941,22 @@ namespace ts {
27937
27941
// number and string input is allowed, we want to say that number is not an
27938
27942
// array type or a string type.
27939
27943
const yieldType = getIterationTypeOfIterable(use, IterationTypeKind.Yield, inputType, /*errorNode*/ undefined);
27940
- const [defaultDiagnostic, missingAwaitDiagnostic ]: [DiagnosticMessage, DiagnosticMessage | undefined ] = !(use & IterationUse.AllowsStringInputFlag) || hasStringConstituent
27944
+ const [defaultDiagnostic, maybeMissingAwait ]: [DiagnosticMessage, boolean ] = !(use & IterationUse.AllowsStringInputFlag) || hasStringConstituent
27941
27945
? downlevelIteration
27942
- ? [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 ]
27946
+ ? [Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator, true ]
27943
27947
: yieldType
27944
- ? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators, undefined ]
27945
- : [Diagnostics.Type_0_is_not_an_array_type, Diagnostics.Type_0_is_not_an_array_type_Did_you_forget_to_use_await ]
27948
+ ? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators, false ]
27949
+ : [Diagnostics.Type_0_is_not_an_array_type, true ]
27946
27950
: downlevelIteration
27947
- ? [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 ]
27951
+ ? [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 ]
27948
27952
: yieldType
27949
- ? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators, undefined]
27950
- : [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];
27951
- if (missingAwaitDiagnostic) {
27952
- errorAndMaybeSuggestAwait(
27953
- errorNode,
27954
- !!getAwaitedTypeOfPromise(arrayType),
27955
- defaultDiagnostic,
27956
- missingAwaitDiagnostic,
27957
- typeToString(arrayType));
27958
- }
27959
- else {
27960
- error(errorNode, defaultDiagnostic, typeToString(arrayType));
27961
- }
27953
+ ? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators, false]
27954
+ : [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type, true];
27955
+ errorAndMaybeSuggestAwait(
27956
+ errorNode,
27957
+ maybeMissingAwait && !!getAwaitedTypeOfPromise(arrayType),
27958
+ defaultDiagnostic,
27959
+ typeToString(arrayType));
27962
27960
}
27963
27961
return hasStringConstituent ? stringType : undefined;
27964
27962
}
@@ -28257,10 +28255,10 @@ namespace ts {
28257
28255
}
28258
28256
28259
28257
function reportTypeNotIterableError(errorNode: Node, type: Type, allowAsyncIterables: boolean): void {
28260
- const [defaultDiagnostic, missingAwaitDiagnostic] = allowAsyncIterables
28261
- ? [ 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]
28262
- : [ 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] ;
28263
- errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), defaultDiagnostic, missingAwaitDiagnostic , typeToString(type));
28258
+ const message = allowAsyncIterables
28259
+ ? Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator
28260
+ : Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator;
28261
+ errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message , typeToString(type));
28264
28262
}
28265
28263
28266
28264
/**
0 commit comments