Skip to content

Commit 1098e06

Browse files
committed
Fix prototype template
1 parent c6c47e0 commit 1098e06

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

scripts/build-entries/templates.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ function getGenericsForNamespace(namespace) {
5555
return '';
5656
}
5757

58+
function getAnyGenericsForNamespace(namespace) {
59+
if (namespacesWithTwoGeneric.includes(namespace)) {
60+
return '<any, any>';
61+
}
62+
if (namespacesWithOneGeneric.includes(namespace)) {
63+
return '<any>';
64+
}
65+
return '';
66+
}
67+
5868
function getCommonGenericsForNamespace(namespace) {
5969
if (namespacesWithTwoGeneric.includes(namespace)) {
6070
return '<K, V>';
@@ -89,7 +99,8 @@ export const $prototype = p => ({
8999
`,
90100
types: dedent`
91101
declare module '${ buildModulePath(p) }' {
92-
type method${ getGenericsForNamespace(p.namespace) } = ${ p.prefix ?? '' }${ p.namespace }${ getCommonGenericsForNamespace(p.namespace) }['${ p.name }'];
102+
type methodType${ getGenericsForNamespace(p.namespace) } = ${ p.prefix ?? '' }${ p.namespace }${ getCommonGenericsForNamespace(p.namespace) }['${ p.name }'];
103+
const method: methodType${ getAnyGenericsForNamespace(p.namespace) };
93104
export = method;
94105
}
95106
`,

tests/type-definitions/templates.import.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import '@core-js/pure/full/array-buffer/detached';
44
import detached from '@core-js/pure/full/array-buffer/detached';
55

66
// $prototype
7-
// import at from '@core-js/pure/full/array/prototype/at';
8-
// const atResult1: number = at.call([1, 2, 3], -2);
9-
// at.apply([1, 2, 3], [-2]);
10-
// // @ts-expect-error
11-
// at.call([1, 2, 3], null);
12-
// // @ts-expect-error
13-
// at.call(123);
14-
// // @ts-expect-error
15-
// at('string');
16-
// // @ts-expect-error
17-
// at(null);
7+
import at from '@core-js/pure/full/array/prototype/at';
8+
const atResult1: number = at.call([1, 2, 3], -2);
9+
at.apply([1, 2, 3], [-2]);
10+
// @ts-expect-error
11+
at.call([1, 2, 3], null);
12+
// @ts-expect-error
13+
at.call(123);
14+
// @ts-expect-error
15+
at('string');
16+
// @ts-expect-error
17+
at(null);
1818

1919
// $prototypeIterator
2020
import arrayVirtualIterator from '@core-js/pure/full/array/prototype/iterator';

0 commit comments

Comments
 (0)