Skip to content

Commit 804a13d

Browse files
committed
fix(no-undefined-types): predefine Iterable/Iterator types; fixes #1712
1 parent ebe0d08 commit 804a13d

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

docs/rules/no-undefined-types.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,5 +1269,14 @@ const b = function (foo: number) {};
12691269

12701270
/** {@link foo} */
12711271
const b = (foo: number) => {};
1272+
1273+
/**
1274+
* @param {...Iterable<any>} its
1275+
* @returns {IteratorObject<any>}
1276+
* @see https://developer.mozilla.org/Web/JavaScript/Reference/Global_Objects/Iterator/concat
1277+
*/
1278+
const concatIteratorJSDoc = (...its) => {
1279+
return Iterator.from(its.flat());
1280+
};
12721281
````
12731282

src/rules/noUndefinedTypes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@ const globalTypes = [
2828
'globalThis', 'global', 'window', 'self',
2929
];
3030

31+
const iterableIterator = [
32+
'Iterable',
33+
'Iterator',
34+
'IteratorObject',
35+
];
36+
3137
const typescriptGlobals = [
38+
...iterableIterator,
39+
3240
// https://www.typescriptlang.org/docs/handbook/utility-types.html
3341
'Awaited',
3442
'Partial',

test/rules/assertions/noUndefinedTypes.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,5 +2193,17 @@ export default /** @type {import('../index.js').TestCases} */ ({
21932193
parser: typescriptEslintParser,
21942194
},
21952195
},
2196+
{
2197+
code: `
2198+
/**
2199+
* @param {...Iterable<any>} its
2200+
* @returns {IteratorObject<any>}
2201+
* @see https://developer.mozilla.org/Web/JavaScript/Reference/Global_Objects/Iterator/concat
2202+
*/
2203+
const concatIteratorJSDoc = (...its) => {
2204+
return Iterator.from(its.flat());
2205+
};
2206+
`,
2207+
},
21962208
],
21972209
});

0 commit comments

Comments
 (0)