source: imaps-frontend/node_modules/call-bind-apply-helpers/index.d.ts@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.4 KB
Line 
1type RemoveFromTuple<
2 Tuple extends unknown[],
3 RemoveCount extends number,
4 Index extends 1[] = []
5> = Index["length"] extends RemoveCount
6 ? Tuple
7 : Tuple extends [first: unknown, ...infer Rest]
8 ? RemoveFromTuple<Rest, RemoveCount, [...Index, 1]>
9 : Tuple;
10
11type ConcatTuples<
12 Prefix extends unknown[],
13 Suffix extends unknown[]
14> = [...Prefix, ...Suffix];
15
16type ReplaceThis<T, NewThis> = T extends (this: infer OldThis, ...args: infer A) => infer R
17 ? (this: NewThis, ...args: A) => R
18 : never;
19
20type BindFunction<
21 TThis,
22 T extends (this: TThis, ...args: any[]) => any, // Allow specific types to propagate
23 TBoundArgs extends unknown[],
24 ReceiverBound extends boolean
25> = ReceiverBound extends true
26 ? (...args: RemoveFromTuple<Parameters<T>, TBoundArgs["length"] & number>) => ReturnType<ReplaceThis<T, TThis>>
27 : (...args: ConcatTuples<[TThis], RemoveFromTuple<Parameters<T>, TBoundArgs["length"] & number>>) => ReturnType<T>;
28
29declare function callBind<
30 TThis,
31 T extends (this: TThis, ...args: any[]) => any,
32 TBoundArgs extends Partial<Parameters<T>>
33>(
34 args: [fn: T, thisArg: TThis, ...boundArgs: TBoundArgs]
35): BindFunction<TThis, T, TBoundArgs, true>;
36
37declare function callBind<
38 TThis,
39 T extends (this: TThis, ...args: any[]) => any,
40 TBoundArgs extends Partial<Parameters<T>>
41>(
42 args: [fn: T, ...boundArgs: TBoundArgs]
43): BindFunction<TThis, T, TBoundArgs, false>;
44
45export as namespace callBind;
46export = callBind;
Note: See TracBrowser for help on using the repository browser.