-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday23.ts
55 lines (48 loc) · 1.41 KB
/
day23.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
declare const argKey: unique symbol
type ArgKey = typeof argKey
interface Fn {
[argKey]: unknown
return: unknown
}
type Apply<TFn extends Fn, TArg> = (TFn & {
[argKey]: TArg
})['return']
interface Cap extends Fn {
return: Capitalize<this[ArgKey] & string>
}
interface Push extends Fn {
return: PushFunc<this[ArgKey]>
}
interface PushFunc<T> extends Fn {
return: this[ArgKey] extends unknown[] ? [...this[ArgKey], T] : never
}
interface ApplyAll extends Fn {
return: this[ArgKey] extends Fn ? ApplyAllFunc<this[ArgKey]> : never
}
interface ApplyAllFunc<TFn extends Fn, U extends unknown[] = []> extends Fn {
impl: U extends [infer F, ...infer R]
? [Apply<TFn, F>, ...ApplyAllFunc<TFn, R>['impl']]
: []
return: this[ArgKey] extends unknown[]
? ApplyAllFunc<TFn, this[ArgKey]>['impl']
: never
}
interface Extends extends Fn {
return: ExtendsFunc<this[ArgKey]>
}
interface ExtendsFunc<T> extends Fn {
return: this[ArgKey] extends T ? true : false
}
interface Filter extends Fn {
return: this[ArgKey] extends Fn ? FilterFunc<this[ArgKey]> : never
}
interface FilterFunc<TFn extends Fn, U extends unknown[] = []> extends Fn {
impl: U extends [infer F, ...infer R]
? Apply<TFn, F> extends true
? [F, ...FilterFunc<TFn, R>['impl']]
: FilterFunc<TFn, R>['impl']
: []
return: this[ArgKey] extends unknown[]
? FilterFunc<TFn, this[ArgKey]>['impl']
: never
}