-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
59 lines (55 loc) · 1.49 KB
/
index.d.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
56
57
58
59
// Type definitions for builderio-type-extensions
// Project: https://github.com/davedbase/builderio-field-types#readme
// Definitions by: David Di Biase <https://github.com/davedbase>
// TypeScript Version: 4.0
/**
* Builder Type Extensions is a set of helpful extension definitions for writing
* powerful well structured TypeScript codebases. The current library contains
* support for input field extraction.
*/
declare type BuilderFields<T> = T extends object
? T extends infer O
? { [K in keyof O]: BuilderFields<O[K]> }
: never
: T;
declare type GenerateItem<T> = T extends {
subFields: infer S extends readonly any[];
}
? GenerateItems<S>[]
: T extends { type: infer Type extends string }
? Type extends "string"
? T extends { enum: infer SE extends readonly string[] }
? SE[number]
: string
: Type extends
| "file"
| "date"
| "richText"
| "color"
| "email"
| "longText"
| "url"
? string
: Type extends "boolean"
? boolean
: Type extends "number"
? number
: Type extends "reference" | "object"
? object
: never
: never;
declare type GenerateItems<T extends readonly any[]> = {
[K in keyof T & `${bigint}` as T[K] extends {
name: infer N extends string;
required?: false;
}
? N
: never]?: GenerateItem<T[K]>;
} & {
[K in keyof T & `${bigint}` as T[K] extends {
name: infer N extends string;
required: true;
}
? N
: never]: GenerateItem<T[K]>;
};