Skip to content

Commit ef8642b

Browse files
authored
fix(eslint-plugin): handle unions in await...for (#10110)
* bug: Handle unions in await...for * fix: fix PR comments * fix: fix style comments
1 parent c6f9196 commit ef8642b

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎packages/eslint-plugin/src/rules/await-thenable.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,16 @@ export default createRule<[], MessageId>({
8080
return;
8181
}
8282

83-
const asyncIteratorSymbol = tsutils.getWellKnownSymbolPropertyOfType(
84-
type,
85-
'asyncIterator',
86-
checker,
87-
);
83+
const asyncIteratorSymbol = tsutils
84+
.unionTypeParts(type)
85+
.map(t =>
86+
tsutils.getWellKnownSymbolPropertyOfType(
87+
t,
88+
'asyncIterator',
89+
checker,
90+
),
91+
)
92+
.find(symbol => symbol != null);
8893

8994
if (asyncIteratorSymbol == null) {
9095
context.report({

‎packages/eslint-plugin/tests/rules/await-thenable.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ async function forAwait() {
217217
for await (const value of anee) {
218218
console.log(value);
219219
}
220+
}
221+
`,
222+
},
223+
{
224+
code: `
225+
declare const asyncIter: AsyncIterable<string> | Iterable<string>;
226+
for await (const s of asyncIter) {
220227
}
221228
`,
222229
},

0 commit comments

Comments
 (0)