From a3a076d79f46bc52c6fc4e1ddbda90783568a07b Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 3 Jul 2019 09:33:03 -0700 Subject: [PATCH] Did you forget to use await? for call and construct signatures --- src/compiler/checker.ts | 8 ++-- src/compiler/diagnosticMessages.json | 40 +++++++++++-------- .../operationsAvailableOnPromisedType.ts | 1 + 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 63fa0f7e889..1a99c2642fd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -22342,6 +22342,8 @@ namespace ts { function invocationErrorDetails(apparentType: Type, kind: SignatureKind): DiagnosticMessageChain { let errorInfo: DiagnosticMessageChain | undefined; const isCall = kind === SignatureKind.Call; + const awaitedType = getAwaitedType(apparentType); + const mightWorkWithAwait = awaitedType && getSignaturesOfType(awaitedType, kind).length > 0; if (apparentType.flags & TypeFlags.Union) { const types = (apparentType as UnionType).types; let hasSignatures = false; @@ -22408,9 +22410,9 @@ namespace ts { } return chainDiagnosticMessages( errorInfo, - isCall ? - Diagnostics.This_expression_is_not_callable : - Diagnostics.This_expression_is_not_constructable + mightWorkWithAwait + ? 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 + : isCall ? Diagnostics.This_expression_is_not_callable : Diagnostics.This_expression_is_not_constructable ); } function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, relatedInformation?: DiagnosticRelatedInformation) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index a7b62838249..e3774296e0d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2705,50 +2705,58 @@ "category": "Error", "code": 2775 }, + "This expression is not callable. Did you forget to use 'await'?": { + "category": "Error", + "code": 2776 + }, + "This expression is not constructable. Did you forget to use 'await'?": { + "category": "Error", + "code": 2777 + }, "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'?": { - "category": "Error", - "code": 2777 - }, - "Type '{0}' must have a '[Symbol.iterator]()' method that returns an iterator. Did you forget to use 'await'?": { - "category": "Error", - "code": 2777 - }, - "Type '{0}' must have a '[Symbol.asyncIterator]()' method that returns an async iterator. Did you forget to use 'await'?": { "category": "Error", "code": 2778 }, - "Type '{0}' is not an array type. Did you forget to use 'await'?": { + "Type '{0}' must have a '[Symbol.iterator]()' method that returns an iterator. Did you forget to use 'await'?": { "category": "Error", "code": 2779 }, - "Type '{0}' is not an array type or a string type. Did you forget to use 'await'?": { + "Type '{0}' must have a '[Symbol.asyncIterator]()' method that returns an async iterator. Did you forget to use 'await'?": { "category": "Error", "code": 2780 }, - "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'?": { + "Type '{0}' is not an array type. Did you forget to use 'await'?": { "category": "Error", "code": 2781 }, - "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'?": { + "Type '{0}' is not an array type or a string type. Did you forget to use 'await'?": { "category": "Error", "code": 2782 }, - "Argument of type '{0}' is not assignable to parameter of type '{1}'. Did you forget to use 'await'?": { + "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'?": { "category": "Error", "code": 2783 }, - "Type '{0}' has no call signatures. Did you forget to use 'await'?": { + "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'?": { "category": "Error", "code": 2784 }, - "Type '{0}' has no construct signatures. Did you forget to use 'await'?": { + "Argument of type '{0}' is not assignable to parameter of type '{1}'. Did you forget to use 'await'?": { "category": "Error", "code": 2785 }, - "This condition will always return '{0}' since the types '{1}' and '{2}' have no overlap. Did you forget to use 'await'?": { + "Type '{0}' has no call signatures. Did you forget to use 'await'?": { "category": "Error", "code": 2786 }, + "Type '{0}' has no construct signatures. Did you forget to use 'await'?": { + "category": "Error", + "code": 2787 + }, + "This condition will always return '{0}' since the types '{1}' and '{2}' have no overlap. Did you forget to use 'await'?": { + "category": "Error", + "code": 2788 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/tests/cases/compiler/operationsAvailableOnPromisedType.ts b/tests/cases/compiler/operationsAvailableOnPromisedType.ts index 76e2cea6dd8..f6e339eab7f 100644 --- a/tests/cases/compiler/operationsAvailableOnPromisedType.ts +++ b/tests/cases/compiler/operationsAvailableOnPromisedType.ts @@ -24,4 +24,5 @@ async function fn( e(); f(); new g(); + b(); }