@@ -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+
2474export const wrapEntry = template => `'use strict';\n${ template } \n` ;
2575export 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
0 commit comments