Skip to content

Commit 3cb60f0

Browse files
slowcheetahzloirock
authored andcommitted
Update proposal types & type tests
1 parent 00b11c0 commit 3cb60f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+613
-70
lines changed

packages/core-js/types/proposals/iterator-joint.d.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ type ZipOptions = {
99
padding?: object;
1010
};
1111

12-
interface Iterator<T> {
13-
zip<U>(iterables: Iterable<U>, options?: ZipOptions): CoreJsIteratorObject<[T, U]>;
12+
interface IteratorConstructor {
13+
zip<T, U>(iterables: Iterable<U>, options?: ZipOptions): CoreJsIteratorObject<[T, U]>;
1414

15-
zipKeyed<U>(iterables: Iterable<U>, options?: ZipOptions): CoreJsIteratorObject<[number, T, U]>;
16-
zipKeyed<U>(record: Record<PropertyKey, Iterable<U>>, options?: ZipOptions): CoreJsIteratorObject<[PropertyKey, T, U]>;
15+
zipKeyed<T, U>(iterables: Iterable<U>, options?: ZipOptions): CoreJsIteratorObject<[number, T, U]>;
16+
zipKeyed<T, U>(record: Record<PropertyKey, Iterable<U>>, options?: ZipOptions): CoreJsIteratorObject<[PropertyKey, T, U]>;
1717
}
18+
19+
declare var Iterator: IteratorConstructor;
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// proposal stage: 2.7
22
// https://github.com/tc39/proposal-iterator-sequencing
3-
interface Iterator<T> {
4-
concat<U>(...iterators: Iterable<U>[]): CoreJsIteratorObject<T | U>;
3+
interface IteratorConstructor {
4+
concat<T, U>(...iterators: Iterable<U>[]): CoreJsIteratorObject<T | U>;
55
}
6+
7+
declare var Iterator: IteratorConstructor;

scripts/build-entries/templates.mjs

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,56 @@ function isAllowedFunctionName(name) {
2121
}
2222
}
2323

24+
const namespacesWithTwoGeneric = [
25+
'Map',
26+
'ReadonlyMap',
27+
'WeakMap',
28+
];
29+
30+
const namespacesWithOneGeneric = [
31+
'Array',
32+
'ReadonlyArray',
33+
'Set',
34+
'ReadonlySet',
35+
'WeakSet',
36+
'Promise',
37+
'Iterator',
38+
'AsyncIterator',
39+
];
40+
41+
function getGenericsForNamespace(namespace) {
42+
if (namespace === 'WeakMap') {
43+
return '<K extends WeakKey, V>';
44+
}
45+
if (namespacesWithTwoGeneric.includes(namespace)) {
46+
return '<K, V>';
47+
}
48+
if (namespacesWithOneGeneric.includes(namespace)) {
49+
return '<T>';
50+
}
51+
return '';
52+
}
53+
54+
function getCommonGenericsForNamespace(namespace) {
55+
if (namespacesWithTwoGeneric.includes(namespace)) {
56+
return '<K, V>';
57+
}
58+
if (namespacesWithOneGeneric.includes(namespace)) {
59+
return '<T>';
60+
}
61+
return '';
62+
}
63+
64+
function getAnyGenericsForNamespace(namespace) {
65+
if (namespacesWithTwoGeneric.includes(namespace)) {
66+
return '<any, any>';
67+
}
68+
if (namespacesWithOneGeneric.includes(namespace)) {
69+
return '<any>';
70+
}
71+
return '';
72+
}
73+
2474
export const wrapEntry = template => `'use strict';\n${ template }\n`;
2575
export const wrapDts = (template, p) => `${ importTypes(p) }${ p.types.length ? '\n\n' : '' }${ template }\n`;
2676

@@ -68,11 +118,11 @@ export const $uncurried = p => ({
68118
module.exports = entryUnbind('${ p.namespace }', '${ p.name }');
69119
`,
70120
dts: dedent`
71-
declare const method: (
72-
thisArg: any,
73-
...args: Parameters<typeof ${ p.namespace }.prototype.${ p.name }>
74-
) => ReturnType<typeof ${ p.namespace }.prototype.${ p.name }>;
75-
export default method;
121+
type method = ${ p.namespace }${ getAnyGenericsForNamespace(p.namespace) }['${ p.name }'];
122+
type uncurriedMethod${ getGenericsForNamespace(p.namespace) } = (self: ${ p.namespace }${ getCommonGenericsForNamespace(p.namespace) }, ...args: Parameters<method>) => ReturnType<method>;
123+
declare const resultMethod: uncurriedMethod${ getAnyGenericsForNamespace(p.namespace) };
124+
125+
export default resultMethod;
76126
`,
77127
});
78128

@@ -86,11 +136,11 @@ export const $uncurriedIterator = p => ({
86136
module.exports = uncurryThis(getIteratorMethod(${ p.source }));
87137
`,
88138
dts: dedent`
89-
declare const method: (
90-
thisArg: any,
91-
...args: Parameters<typeof ${ p.namespace }.prototype[typeof Symbol.iterator]>
92-
) => ReturnType<typeof ${ p.namespace }.prototype[typeof Symbol.iterator]>;
93-
export default method;
139+
type method = ${ p.namespace }<any>[typeof Symbol.iterator];
140+
type uncurriedMethod<T> = (self: ${ p.namespace }<T>, ...args: Parameters<method>) => ReturnType<method>;
141+
declare const resultMethod: uncurriedMethod<any>;
142+
143+
export default resultMethod;
94144
`,
95145
});
96146

tests/type-definitions/proposals/array-buffer-base64.test.ts renamed to tests/type-definitions/proposals/global/array-buffer-base64.test.ts

File renamed without changes.

tests/type-definitions/proposals/array-filtering.test.ts renamed to tests/type-definitions/proposals/global/array-filtering.test.ts

File renamed without changes.

tests/type-definitions/proposals/array-from-async.test.ts renamed to tests/type-definitions/proposals/global/array-from-async.test.ts

File renamed without changes.

tests/type-definitions/proposals/array-is-template-object.test.ts renamed to tests/type-definitions/proposals/global/array-is-template-object.test.ts

File renamed without changes.

tests/type-definitions/proposals/array-unique.test.ts renamed to tests/type-definitions/proposals/global/array-unique.test.ts

File renamed without changes.

tests/type-definitions/proposals/async-iterator-helper.test.ts renamed to tests/type-definitions/proposals/global/async-iterator-helper.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ AsyncIterator.from({});
2828
// @ts-expect-error
2929
AsyncIterator.from();
3030
// @ts-expect-error
31-
AsyncIterator.from(null);
32-
// @ts-expect-error
33-
AsyncIterator.from(undefined);
34-
// @ts-expect-error
3531
AsyncIterator.from({ next: () => 1 });
3632

3733
const raits: AsyncIterator<string> = is.toAsync();

tests/type-definitions/proposals/collection-of-from.test.ts renamed to tests/type-definitions/proposals/global/collection-of-from.test.ts

File renamed without changes.

0 commit comments

Comments
 (0)