-
Notifications
You must be signed in to change notification settings - Fork 0
/
universal.ts
41 lines (35 loc) · 939 Bytes
/
universal.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
export {
Universal
}
import type { any } from "../any/exports.js"
type parseNumeric<type> = type extends `${infer x extends number}` ? x : never
namespace Universal { export const never: never = void 0 as never }
declare namespace Universal {
type key<key extends any.index> =
| `${Exclude<key, symbol>}`
| parseNumeric<key>
| key
;
type keyof<type>
= type extends any.array
? Universal.key<Extract<keyof type, `${number}`>>
: Universal.key<keyof type>
;
type get<index extends any.key, type>
= index extends keyof type ? type[index]
: parseNumeric<index> extends any.number<infer x>
? x extends keyof type ? type[x]
: never
: `${index}` extends any.string<infer s>
? s extends keyof type ? type[s]
: never
: never
;
type values<type>
= type extends any.array
? type[number]
: type extends any.object
? type[keyof type]
: type
;
}