From 5fe84781592a08b5294e01a2fbf42d1def07111d Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 29 Jan 2016 14:46:01 -0800 Subject: [PATCH] Add overloads for Function.apply/call/bind The new overloads use this types to specify the return type of these functions as well as the type of `thisArg`. --- src/lib/core.d.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index 31cf0ca3136..fe2fd6b79f6 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -215,14 +215,16 @@ interface Function { * @param thisArg The object to be used as the this object. * @param argArray A set of arguments to be passed to the function. */ - apply(thisArg: any, argArray?: any): any; + apply(this: (this: T, ...argArray: any[]) => U, thisArg: T, argArray?: any): U; + apply(this: Function, thisArg: any, argArray?: any): any; /** * Calls a method of an object, substituting another object for the current object. * @param thisArg The object to be used as the current object. * @param argArray A list of arguments to be passed to the method. */ - call(thisArg: any, ...argArray: any[]): any; + call(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): U; + call(this: Function, thisArg: any, ...argArray: any[]): any; /** * For a given function, creates a bound function that has the same body as the original function. @@ -230,7 +232,8 @@ interface Function { * @param thisArg An object to which the this keyword can refer inside the new function. * @param argArray A list of arguments to be passed to the new function. */ - bind(thisArg: any, ...argArray: any[]): any; + bind(this: (this: T, ...argArray: any[]) => U, thisArg: T, ...argArray: any[]): (...argArray: any[]) => U; + bind(this: Function, thisArg: any, ...argArray: any[]): any; prototype: any; readonly length: number;