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