Skip to content

Commit 18b08fc

Browse files
Use same error for iteration in <=ES5 (microsoft#48881)
* Use the same error for iterating over an Iterable in ES5 or lower. * Accepted baselines.
1 parent 189c2b9 commit 18b08fc

File tree

5 files changed

+8
-11
lines changed

5 files changed

+8
-11
lines changed

src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -38250,7 +38250,7 @@ namespace ts {
3825038250

3825138251
return (use & IterationUse.PossiblyOutOfBounds) ? includeUndefinedInIndexSignature(arrayElementType) : arrayElementType;
3825238252

38253-
function getIterationDiagnosticDetails(allowsStrings: boolean, downlevelIteration: boolean | undefined): [DiagnosticMessage, boolean] {
38253+
function getIterationDiagnosticDetails(allowsStrings: boolean, downlevelIteration: boolean | undefined): [error: DiagnosticMessage, maybeMissingAwait: boolean] {
3825438254
if (downlevelIteration) {
3825538255
return allowsStrings
3825638256
? [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]
@@ -38260,7 +38260,7 @@ namespace ts {
3826038260
const yieldType = getIterationTypeOfIterable(use, IterationTypeKind.Yield, inputType, /*errorNode*/ undefined);
3826138261

3826238262
if (yieldType) {
38263-
return [Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators, false];
38263+
return [Diagnostics.Type_0_can_only_be_iterated_through_when_using_the_downlevelIteration_flag_or_with_a_target_of_es2015_or_higher, false];
3826438264
}
3826538265

3826638266
if (isES2015OrLaterIterable(inputType.symbol?.escapedName)) {

src/compiler/diagnosticMessages.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -2511,10 +2511,7 @@
25112511
"category": "Error",
25122512
"code": 2568
25132513
},
2514-
"Type '{0}' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.": {
2515-
"category": "Error",
2516-
"code": 2569
2517-
},
2514+
25182515
"Could not find name '{0}'. Did you mean '{1}'?": {
25192516
"category": "Error",
25202517
"code": 2570

src/services/codefixes/addMissingAwait.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace ts.codefix {
1717
Diagnostics.This_condition_will_always_return_true_since_this_0_is_always_defined.code,
1818
Diagnostics.Type_0_is_not_an_array_type.code,
1919
Diagnostics.Type_0_is_not_an_array_type_or_a_string_type.code,
20-
Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators.code,
20+
Diagnostics.Type_0_can_only_be_iterated_through_when_using_the_downlevelIteration_flag_or_with_a_target_of_es2015_or_higher.code,
2121
Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator.code,
2222
Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator.code,
2323
Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator.code,
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck13.ts(4,19): error TS2569: Type 'Set<string>' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.
1+
tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck13.ts(4,19): error TS2802: Type 'Set<string>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
22

33

44
==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck13.ts (1 errors) ====
@@ -7,4 +7,4 @@ tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck13.ts(4,19
77
strSet.add('World')
88
for (const str of strSet) { }
99
~~~~~~
10-
!!! error TS2569: Type 'Set<string>' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.
10+
!!! error TS2802: Type 'Set<string>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck14.ts(2,17): error TS2569: Type 'Set<number>' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.
1+
tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck14.ts(2,17): error TS2802: Type 'Set<number>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
22

33

44
==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck14.ts (1 errors) ====
55
var union: string | Set<number>
66
for (const e of union) { }
77
~~~~~
8-
!!! error TS2569: Type 'Set<number>' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.
8+
!!! error TS2802: Type 'Set<number>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.

0 commit comments

Comments
 (0)