Skip to content

Commit 1189eb4

Browse files
Xinquan XUXinquan XU
Xinquan XU
authored and
Xinquan XU
committed
fix: introduce CallableFunction and NewableFunction from typescript/lib/lib.es5.d.ts
1 parent a0c27fa commit 1189eb4

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

NOTICE

+1
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

+71
Original file line numberDiff line numberDiff line change
@@ -2307,6 +2307,77 @@ 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+
* @param args An array of argument values to be passed to the function.
2326+
*/
2327+
apply<T, R>(this: (this: T) => R, thisArg: T): R;
2328+
apply<T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, args: A): R;
2329+
2330+
/**
2331+
* Calls the function with the specified object as the this value and the specified rest arguments as the arguments.
2332+
* @param thisArg The object to be used as the this object.
2333+
* @param args Argument values to be passed to the function.
2334+
*/
2335+
call<T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, ...args: A): R;
2336+
2337+
/**
2338+
* For a given function, creates a bound function that has the same body as the original function.
2339+
* The this object of the bound function is associated with the specified object, and has the specified initial parameters.
2340+
* @param thisArg The object to be used as the this object.
2341+
* @param args Arguments to bind to the parameters of the function.
2342+
*/
2343+
bind<T>(this: T, thisArg: ThisParameterType<T>): OmitThisParameter<T>;
2344+
bind<T, A0, A extends any[], R>(this: (this: T, arg0: A0, ...args: A) => R, thisArg: T, arg0: A0): (...args: A) => R;
2345+
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;
2346+
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;
2347+
bind<T, A0, A1, A2, A3, A extends any[], R>(this: (this: T, arg0: A0, arg1: A1, arg2: A2, arg3: A3, ...args: A) => R, thisArg: T, arg0: A0, arg1: A1, arg2: A2, arg3: A3): (...args: A) => R;
2348+
bind<T, AX, R>(this: (this: T, ...args: AX[]) => R, thisArg: T, ...args: AX[]): (...args: AX[]) => R;
2349+
}
2350+
2351+
interface NewableFunction extends Function {
2352+
/**
2353+
* Calls the function with the specified object as the this value and the elements of specified array as the arguments.
2354+
* @param thisArg The object to be used as the this object.
2355+
* @param args An array of argument values to be passed to the function.
2356+
*/
2357+
apply<T>(this: new () => T, thisArg: T): void;
2358+
apply<T, A extends any[]>(this: new (...args: A) => T, thisArg: T, args: A): void;
2359+
2360+
/**
2361+
* Calls the function with the specified object as the this value and the specified rest arguments as the arguments.
2362+
* @param thisArg The object to be used as the this object.
2363+
* @param args Argument values to be passed to the function.
2364+
*/
2365+
call<T, A extends any[]>(this: new (...args: A) => T, thisArg: T, ...args: A): void;
2366+
2367+
/**
2368+
* For a given function, creates a bound function that has the same body as the original function.
2369+
* The this object of the bound function is associated with the specified object, and has the specified initial parameters.
2370+
* @param thisArg The object to be used as the this object.
2371+
* @param args Arguments to bind to the parameters of the function.
2372+
*/
2373+
bind<T>(this: T, thisArg: any): T;
2374+
bind<A0, A extends any[], R>(this: new (arg0: A0, ...args: A) => R, thisArg: any, arg0: A0): new (...args: A) => R;
2375+
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;
2376+
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;
2377+
bind<A0, A1, A2, A3, A extends any[], R>(this: new (arg0: A0, arg1: A1, arg2: A2, arg3: A3, ...args: A) => R, thisArg: any, arg0: A0, arg1: A1, arg2: A2, arg3: A3): new (...args: A) => R;
2378+
bind<AX, R>(this: new (...args: AX[]) => R, thisArg: any, ...args: AX[]): new (...args: AX[]) => R;
2379+
}
2380+
23102381
interface IArguments {}
23112382
interface RegExp {}
23122383

0 commit comments

Comments
 (0)