1+ // make input suggestions work
2+ type StringQueryType = `?${keyof KnownAsTypeMap } ` | ( string & { } )
3+ type BaseQueryType = StringQueryType | Record < string , string | number | boolean >
4+
15export interface ImportGlobOptions <
26 Eager extends boolean ,
37 AsType extends string ,
8+ QueryType extends BaseQueryType ,
49> {
510 /**
611 * Import type for the import url.
@@ -21,7 +26,7 @@ export interface ImportGlobOptions<
2126 /**
2227 * Custom queries
2328 */
24- query ?: string | Record < string , string | number | boolean >
29+ query ?: QueryType
2530 /**
2631 * Search files also inside `node_modules/` and hidden directories (e.g. `.git/`). This might have impact on performance.
2732 *
@@ -34,7 +39,18 @@ export interface ImportGlobOptions<
3439 base ?: string
3540}
3641
37- export type GeneralImportGlobOptions = ImportGlobOptions < boolean , string >
42+ export type ImportGlobOptionsWithoutAs <
43+ Eager extends boolean ,
44+ QueryType extends BaseQueryType ,
45+ > = Omit < ImportGlobOptions < Eager , string , QueryType > , 'as' > & {
46+ as ?: never
47+ }
48+
49+ export type GeneralImportGlobOptions = ImportGlobOptions <
50+ boolean ,
51+ string ,
52+ BaseQueryType
53+ >
3854
3955/**
4056 * Declare Worker in case DOM is not added to the tsconfig lib causing
@@ -52,19 +68,41 @@ export interface KnownAsTypeMap {
5268 worker : Worker
5369}
5470
71+ type KnownQueryTypeMap = {
72+ [ K in keyof KnownAsTypeMap as `?${K } `] : KnownAsTypeMap [ K ]
73+ }
74+
5575export interface ImportGlobFunction {
5676 /**
5777 * Import a list of files with a glob pattern.
5878 *
59- * Overload 1: No generic provided, infer the type from `eager` and `as`
79+ * Overload 1A: No generic provided, infer the type from `eager` and `query`
80+ */
81+ <
82+ Eager extends boolean ,
83+ Query extends BaseQueryType ,
84+ T = Query extends keyof KnownQueryTypeMap
85+ ? KnownQueryTypeMap [ Query ]
86+ : unknown ,
87+ > (
88+ glob : string | string [ ] ,
89+ options ?: ImportGlobOptionsWithoutAs < Eager , Query > ,
90+ ) : ( Eager extends true ? true : false ) extends true
91+ ? Record < string , T >
92+ : Record < string , ( ) => Promise < T > >
93+ /**
94+ * Import a list of files with a glob pattern.
95+ *
96+ * Overload 1B: No generic provided, infer the type from `eager` and `as`
97+ * (deprecated, use `query` instead)
6098 */
6199 <
62100 Eager extends boolean ,
63101 As extends string ,
64102 T = As extends keyof KnownAsTypeMap ? KnownAsTypeMap [ As ] : unknown ,
65103 > (
66104 glob : string | string [ ] ,
67- options ?: ImportGlobOptions < Eager , As > ,
105+ options ?: ImportGlobOptions < Eager , As , BaseQueryType > ,
68106 ) : ( Eager extends true ? true : false ) extends true
69107 ? Record < string , T >
70108 : Record < string , ( ) => Promise < T > >
@@ -75,7 +113,7 @@ export interface ImportGlobFunction {
75113 */
76114 < M > (
77115 glob : string | string [ ] ,
78- options ?: ImportGlobOptions < false , string > ,
116+ options ?: ImportGlobOptions < false , string , BaseQueryType > ,
79117 ) : Record < string , ( ) => Promise < M > >
80118 /**
81119 * Import a list of files with a glob pattern.
@@ -84,6 +122,6 @@ export interface ImportGlobFunction {
84122 */
85123 < M > (
86124 glob : string | string [ ] ,
87- options : ImportGlobOptions < true , string > ,
125+ options : ImportGlobOptions < true , string , BaseQueryType > ,
88126 ) : Record < string , M >
89127}
0 commit comments