Did you forget to use await? on iterables

This commit is contained in:
Andrew Branch committed 2019-07-08 13:59:59 -07:00
1 parent c48e34ef91
commit 48fc6b8b17
3 files changed
+46 -17

No files matched your search

+22 -11
View File
@@ -27922,18 +27922,28 @@ namespace ts {
// number and string input is allowed, we want to say that number is not an
// array type or a string type.
const yieldType = getIterationTypeOfIterable(use, IterationTypeKind.Yield, inputType, /*errorNode*/ undefined);
const diagnostic = !(use & IterationUse.AllowsStringInputFlag) || hasStringConstituent
const [defaultDiagnostic, missingAwaitDiagnostic]: [DiagnosticMessage, DiagnosticMessage | undefined] = !(use & IterationUse.AllowsStringInputFlag) || hasStringConstituent
? downlevelIteration
? 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, 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]
: yieldType
? Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators
: Diagnostics.Type_0_is_not_an_array_type
? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators, undefined]
: [Diagnostics.Type_0_is_not_an_array_type, Diagnostics.Type_0_is_not_an_array_type_Did_you_forget_to_use_await]
: downlevelIteration
? 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, 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]
: yieldType
? Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators
: Diagnostics.Type_0_is_not_an_array_type_or_a_string_type;
error(errorNode, diagnostic, typeToString(arrayType));
? [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators, undefined]
: [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];
if (missingAwaitDiagnostic) {
errorAndMaybeSuggestAwait(
errorNode,
!!getAwaitedTypeOfPromise(arrayType),
defaultDiagnostic,
missingAwaitDiagnostic,
typeToString(arrayType));
}
else {
error(errorNode, defaultDiagnostic, typeToString(arrayType));
}
}
return hasStringConstituent ? stringType : undefined;
}
@@ -28232,9 +28242,10 @@ namespace ts {
}
function reportTypeNotIterableError(errorNode: Node, type: Type, allowAsyncIterables: boolean): void {
error(errorNode, allowAsyncIterables
? Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator
: Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator, typeToString(type));
const [defaultDiagnostic, missingAwaitDiagnostic] = allowAsyncIterables
? [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]
: [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];
errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), defaultDiagnostic, missingAwaitDiagnostic, typeToString(type));
}
/**
+21 -5
View File
@@ -2713,26 +2713,42 @@
"category": "Error",
"code": 2777
},
"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": 2778
},
"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. Did you forget to use 'await'?": {
"category": "Error",
"code": 2779
},
"Type '{0}' has no call signatures. 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": 2780
},
"Type '{0}' has no construct signatures. 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": 2781
},
"This condition will always return '{0}' since the types '{1}' and '{2}' have no overlap. 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": 2782
},
"Argument of type '{0}' is not assignable to parameter of type '{1}'. Did you forget to use 'await'?": {
"category": "Error",
"code": 2783
},
"Type '{0}' has no call signatures. Did you forget to use 'await'?": {
"category": "Error",
"code": 2784
},
"Type '{0}' has no construct signatures. 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'?": {
"category": "Error",
"code": 2786
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
@@ -1,4 +1,4 @@
function fn(
async function fn(
a: number,
b: Promise<number>,
c: Promise<string[]>,
@@ -15,10 +15,12 @@ function fn(
b++;
--b;
a === b;
[...c];
for (const s of c) {
fn(b, b, c, d);
d.prop;
}
for await (const s of c) {}
e();
f();
new g();