UNPKG

2.45 kBTypeScriptView Raw
1export interface ImportGlobOptions<
2 Eager extends boolean,
3 AsType extends string,
4> {
5 /**
6 * Import type for the import url.
7 */
8 as?: AsType
9 /**
10 * Import as static or dynamic
11 *
12 * @default false
13 */
14 eager?: Eager
15 /**
16 * Import only the specific named export. Set to `default` to import the default export.
17 */
18 import?: string
19 /**
20 * Custom queries
21 */
22 query?: string | Record<string, string | number | boolean>
23 /**
24 * Search files also inside `node_modules/` and hidden directories (e.g. `.git/`). This might have impact on performance.
25 *
26 * @default false
27 */
28 exhaustive?: boolean
29}
30
31export type GeneralImportGlobOptions = ImportGlobOptions<boolean, string>
32
33export interface KnownAsTypeMap {
34 raw: string
35 url: string
36 worker: Worker
37}
38
39export interface ImportGlobFunction {
40 /**
41 * Import a list of files with a glob pattern.
42 *
43 * Overload 1: No generic provided, infer the type from `eager` and `as`
44 */
45 <
46 Eager extends boolean,
47 As extends string,
48 T = As extends keyof KnownAsTypeMap ? KnownAsTypeMap[As] : unknown,
49 >(
50 glob: string | string[],
51 options?: ImportGlobOptions<Eager, As>,
52 ): (Eager extends true ? true : false) extends true
53 ? Record<string, T>
54 : Record<string, () => Promise<T>>
55 /**
56 * Import a list of files with a glob pattern.
57 *
58 * Overload 2: Module generic provided, infer the type from `eager: false`
59 */
60 <M>(
61 glob: string | string[],
62 options?: ImportGlobOptions<false, string>,
63 ): Record<string, () => Promise<M>>
64 /**
65 * Import a list of files with a glob pattern.
66 *
67 * Overload 3: Module generic provided, infer the type from `eager: true`
68 */
69 <M>(
70 glob: string | string[],
71 options: ImportGlobOptions<true, string>,
72 ): Record<string, M>
73}
74
75export interface ImportGlobEagerFunction {
76 /**
77 * Eagerly import a list of files with a glob pattern.
78 *
79 * Overload 1: No generic provided, infer the type from `as`
80 */
81 <
82 As extends string,
83 T = As extends keyof KnownAsTypeMap ? KnownAsTypeMap[As] : unknown,
84 >(
85 glob: string | string[],
86 options?: Omit<ImportGlobOptions<boolean, As>, 'eager'>,
87 ): Record<string, T>
88 /**
89 * Eagerly import a list of files with a glob pattern.
90 *
91 * Overload 2: Module generic provided
92 */
93 <M>(
94 glob: string | string[],
95 options?: Omit<ImportGlobOptions<boolean, string>, 'eager'>,
96 ): Record<string, M>
97}