Skip to content

Commit c22c078

Browse files
XMadridXinquan XU
and
Xinquan XU
authored
fix: introduce CallableFunction and NewableFunction from typescript/lib/lib.es5.d.ts (#2712)
Co-authored-by: Xinquan XU <[email protected]>
1 parent e3e4166 commit c22c078

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

NOTICE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ under the licensing terms detailed in LICENSE:
5555
* CountBleck <[email protected]>
5656
* Abdul Rauf <[email protected]>
5757
* Bach Le <[email protected]>
58+
* Xinquan Xu <[email protected]>
5859

5960
Portions of this software are derived from third-party works licensed under
6061
the following terms:

std/assembly/index.d.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,6 +2307,90 @@ interface Function {
23072307
/** Returns a string representation of this function. */
23082308
toString(): string;
23092309
}
2310+
2311+
/**
2312+
* Extracts the type of the 'this' parameter of a function type, or 'unknown' if the function type has no 'this' parameter.
2313+
*/
2314+
type ThisParameterType<T> = T extends (this: infer U, ...args: never) => any ? U : unknown;
2315+
2316+
/**
2317+
* Removes the 'this' parameter from a function type.
2318+
*/
2319+
type OmitThisParameter<T> = unknown extends ThisParameterType<T> ? T : T extends (...args: infer A) => infer R ? (...args: A) => R : T;
2320+
2321+
interface CallableFunction extends Function {
2322+
/**
2323+
* Calls the function with the specified object as the this value and the elements of specified array as the arguments.
2324+
* @param thisArg The object to be used as the this object.
2325+
*/
2326+
apply<T, R>(this: (this: T) => R, thisArg: T): R;
2327+
2328+
/**
2329+
* Calls the function with the specified object as the this value and the elements of specified array as the arguments.
2330+
* @param thisArg The object to be used as the this object.
2331+
* @param args An array of argument values to be passed to the function.
2332+
*/
2333+
apply<T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, args: A): R;
2334+
2335+
/**
2336+
* Calls the function with the specified object as the this value and the specified rest arguments as the arguments.
2337+
* @param thisArg The object to be used as the this object.
2338+
* @param args Argument values to be passed to the function.
2339+
*/
2340+
call<T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, ...args: A): R;
2341+
2342+
/**
2343+
* For a given function, creates a bound function that has the same body as the original function.
2344+
* The this object of the bound function is associated with the specified object, and has the specified initial parameters.
2345+
* @param thisArg The object to be used as the this object.
2346+
*/
2347+
bind<T>(this: T, thisArg: ThisParameterType<T>): OmitThisParameter<T>;
2348+
2349+
/**
2350+
* For a given function, creates a bound function that has the same body as the original function.
2351+
* The this object of the bound function is associated with the specified object, and has the specified initial parameters.
2352+
* @param thisArg The object to be used as the this object.
2353+
* @param args Arguments to bind to the parameters of the function.
2354+
*/
2355+
bind<T, A extends any[], B extends any[], R>(this: (this: T, ...args: [...A, ...B]) => R, thisArg: T, ...args: A): (...args: B) => R;
2356+
}
2357+
2358+
interface NewableFunction extends Function {
2359+
/**
2360+
* Calls the function with the specified object as the this value and the elements of specified array as the arguments.
2361+
* @param thisArg The object to be used as the this object.
2362+
*/
2363+
apply<T>(this: new () => T, thisArg: T): void;
2364+
/**
2365+
* Calls the function with the specified object as the this value and the elements of specified array as the arguments.
2366+
* @param thisArg The object to be used as the this object.
2367+
* @param args An array of argument values to be passed to the function.
2368+
*/
2369+
apply<T, A extends any[]>(this: new (...args: A) => T, thisArg: T, args: A): void;
2370+
2371+
/**
2372+
* Calls the function with the specified object as the this value and the specified rest arguments as the arguments.
2373+
* @param thisArg The object to be used as the this object.
2374+
* @param args Argument values to be passed to the function.
2375+
*/
2376+
call<T, A extends any[]>(this: new (...args: A) => T, thisArg: T, ...args: A): void;
2377+
2378+
/**
2379+
* For a given function, creates a bound function that has the same body as the original function.
2380+
* The this object of the bound function is associated with the specified object, and has the specified initial parameters.
2381+
* @param thisArg The object to be used as the this object.
2382+
*/
2383+
bind<T>(this: T, thisArg: any): T;
2384+
2385+
/**
2386+
* For a given function, creates a bound function that has the same body as the original function.
2387+
* The this object of the bound function is associated with the specified object, and has the specified initial parameters.
2388+
* @param thisArg The object to be used as the this object.
2389+
* @param args Arguments to bind to the parameters of the function.
2390+
*/
2391+
bind<A extends any[], B extends any[], R>(this: new (...args: [...A, ...B]) => R, thisArg: any, ...args: A): new (...args: B) => R;
2392+
}
2393+
23102394
interface IArguments {}
23112395
interface RegExp {}
23122396

0 commit comments

Comments
 (0)