@@ -295,6 +295,16 @@ interface FunctionConstructor {
295
295
296
296
declare const Function : FunctionConstructor ;
297
297
298
+ /**
299
+ * Extracts the type of the 'this' parameter of a function type, or 'unknown' if the function type has no 'this' parameter.
300
+ */
301
+ type ThisParameterType < T > = T extends ( this : unknown , ...args : any [ ] ) => any ? unknown : T extends ( this : infer U , ...args : any [ ] ) => any ? U : unknown ;
302
+
303
+ /**
304
+ * Removes the 'this' parameter from a function type.
305
+ */
306
+ type OmitThisParameter < T > = unknown extends ThisParameterType < T > ? T : T extends ( ...args : infer A ) => infer R ? ( ...args : A ) => R : T ;
307
+
298
308
interface CallableFunction extends Function {
299
309
/**
300
310
* Calls the function with the specified object as the this value and the elements of specified array as the arguments.
@@ -317,7 +327,7 @@ interface CallableFunction extends Function {
317
327
* @param thisArg The object to be used as the this object.
318
328
* @param args Arguments to bind to the parameters of the function.
319
329
*/
320
- bind < T , A extends any [ ] , R > ( this : ( this : T , ... args : A ) => R , thisArg : T ) : ( ... args : A ) => R ;
330
+ bind < T > ( this : T , thisArg : ThisParameterType < T > ) : OmitThisParameter < T > ;
321
331
bind < T , A0 , A extends any [ ] , R > ( this : ( this : T , arg0 : A0 , ...args : A ) => R , thisArg : T , arg0 : A0 ) : ( ...args : A ) => R ;
322
332
bind < T , A0 , A1 , A extends any [ ] , R > ( this : ( this : T , arg0 : A0 , arg1 : A1 , ...args : A ) => R , thisArg : T , arg0 : A0 , arg1 : A1 ) : ( ...args : A ) => R ;
323
333
bind < T , A0 , A1 , A2 , A extends any [ ] , R > ( this : ( this : T , arg0 : A0 , arg1 : A1 , arg2 : A2 , ...args : A ) => R , thisArg : T , arg0 : A0 , arg1 : A1 , arg2 : A2 ) : ( ...args : A ) => R ;
@@ -347,7 +357,7 @@ interface NewableFunction extends Function {
347
357
* @param thisArg The object to be used as the this object.
348
358
* @param args Arguments to bind to the parameters of the function.
349
359
*/
350
- bind < A extends any [ ] , R > ( this : new ( ... args : A ) => R , thisArg : any ) : new ( ... args : A ) => R ;
360
+ bind < T > ( this : T , thisArg : any ) : T ;
351
361
bind < A0 , A extends any [ ] , R > ( this : new ( arg0 : A0 , ...args : A ) => R , thisArg : any , arg0 : A0 ) : new ( ...args : A ) => R ;
352
362
bind < A0 , A1 , A extends any [ ] , R > ( this : new ( arg0 : A0 , arg1 : A1 , ...args : A ) => R , thisArg : any , arg0 : A0 , arg1 : A1 ) : new ( ...args : A ) => R ;
353
363
bind < A0 , A1 , A2 , A extends any [ ] , R > ( this : new ( arg0 : A0 , arg1 : A1 , arg2 : A2 , ...args : A ) => R , thisArg : any , arg0 : A0 , arg1 : A1 , arg2 : A2 ) : new ( ...args : A ) => R ;
0 commit comments