Skip to content

Commit 953c6d6

Browse files
committed
Types refactoring
1 parent 8946dd7 commit 953c6d6

23 files changed

+50
-62
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
interface AsyncIteratorObject<T, TReturn, TNext> extends AsyncIterator<T, TReturn, TNext> {
2+
[Symbol.asyncIterator](): AsyncIteratorObject<T, TReturn, TNext>;
3+
}
4+
5+
interface AsyncIterableIterator<T, TReturn, TNext> extends AsyncIterator<T, TReturn, TNext> {
6+
[Symbol.asyncIterator](): AsyncIterableIterator<T, TReturn, TNext>;
7+
}
8+
9+
interface AsyncIterator<T, TReturn = any, TNext = any> {
10+
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
11+
next(...[value]: [] | [TNext]): Promise<IteratorResult<T, TReturn>>;
12+
return?(value?: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<T, TReturn>>;
13+
throw?(e?: any): Promise<IteratorResult<T, TReturn>>;
14+
}
15+
16+
interface AsyncIteratorConstructor {}
17+
18+
declare var AsyncIterator: AsyncIteratorConstructor;
19+
20+
interface AsyncIterable<T, TReturn = any, TNext = any> {
21+
[Symbol.asyncIterator](): AsyncIterator<T, TReturn, TNext>;
22+
}

packages/core-js-types/src/base/core-js-types/core-js-types.d.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
declare namespace CoreJS {
2-
export interface CoreJSIteratorObject<T, TReturn = any, TNext = any> extends Iterator<T, TReturn, TNext> {}
3-
}
1+
interface IteratorObject<T, TReturn, TNext> extends Iterator<T, TReturn, TNext> {}

packages/core-js-types/src/base/proposals/array-flat-map.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference types="../core-js-types/flat-array.d.ts" />
1+
/// <reference types="../core-js-types/flat-array" />
22

33
// https://github.com/tc39/proposal-flatMap
44

packages/core-js-types/src/base/proposals/array-from-async.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference types="../core-js-types/core-js-types" />
1+
/// <reference types="../core-js-types/async-iterator" />
22

33
// https://github.com/tc39/proposal-array-from-async
44

packages/core-js-types/src/base/proposals/async-iterator-helpers.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference types="../core-js-types/core-js-types" />
1+
/// <reference types="../core-js-types/async-iterator" />
22

33
// https://github.com/tc39/proposal-async-iterator-helpers
44

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference types="../core-js-types/iterator-object.ts" />
1+
/// <reference types="../core-js-types/iterator-object" />
22

33
// https://github.com/tc39/proposal-iterator-chunking
44

@@ -9,13 +9,13 @@ interface Iterator<T> {
99
* @param chunkSize - The maximum number of elements per chunk. Must be a positive integer.
1010
* @returns An iterator yielding arrays of at most `chunkSize` elements from the source iterator.
1111
*/
12-
chunks(chunkSize: number): CoreJS.CoreJSIteratorObject<T[]>;
12+
chunks(chunkSize: number): IteratorObject<T[]>;
1313

1414
/**
1515
* Yields overlapping arrays (windows) of the given size from the iterator.
1616
* @param windowSize - The size of each window. Must be a positive integer.
1717
* @param undersized - 'only-full' (default) to yield only full windows | 'allow-partial' to yield all windows.
1818
* @returns An iterator yielding arrays of the specified window size.
1919
*/
20-
windows(windowSize: number, undersized?: 'only-full' | 'allow-partial' | undefined): CoreJS.CoreJSIteratorObject<T[]>;
20+
windows(windowSize: number, undersized?: 'only-full' | 'allow-partial' | undefined): IteratorObject<T[]>;
2121
}

packages/core-js-types/src/base/proposals/iterator-helpers.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference types="../core-js-types/core-js-types" />
1+
/// <reference types="../core-js-types/iterator-object" />
22

33
// https://github.com/tc39/proposal-iterator-helpers
44

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference types="../core-js-types/iterator-object.ts" />
1+
/// <reference types="../core-js-types/iterator-object" />
22

33
// https://github.com/tc39/proposal-iterator-sequencing
44

@@ -8,7 +8,7 @@ interface IteratorConstructor { // @type-options: no-extends
88
* @param iterators - The iterables to concatenate.
99
* @returns An iterator yielding values from each input iterable in sequence.
1010
*/
11-
concat<T>(...iterators: Iterable<T>[]): CoreJS.CoreJSIteratorObject<T>;
11+
concat<T>(...iterators: Iterable<T>[]): IteratorObject<T>;
1212
}
1313

1414
declare var Iterator: IteratorConstructor;

packages/core-js-types/src/base/pure/core-js-types/iterator-object.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference types="../proposals/iterator.ts" />
1+
/// <reference types="../proposals/iterator" />
22

33
declare namespace CoreJS {
44
export interface CoreJSIteratorObject<T, TReturn = any, TNext = any> extends CoreJSIterator<T, TReturn, TNext> {}

0 commit comments

Comments
 (0)