@@ -144,15 +144,23 @@ type ExtractCustomModelNames<TDefs extends ReadonlyArray<ExtendedModelDef>> =
144144// Factory Type Inference
145145// ===========================
146146
147+ /**
148+ * The widest factory shape `extendAdapter` accepts: any function taking a
149+ * model as its first parameter. Parameters are contravariant, so `never`
150+ * params and an `unknown` return accept every factory without resorting
151+ * to `any`.
152+ */
153+ type AnyAdapterFactory = ( model : never , ...args : Array < never > ) => unknown
154+
147155/**
148156 * Infer the model parameter type from an adapter factory function.
149157 * For generic functions like `<T extends Union>(model: T)`, this gets `T` which
150158 * TypeScript treats as the constraint union when used in parameter position.
151159 */
152160type InferFactoryModels < TFactory > = TFactory extends (
153161 model : infer TModel ,
154- ...args : Array < any >
155- ) => any
162+ ...args : Array < never >
163+ ) => unknown
156164 ? TModel extends string
157165 ? TModel
158166 : string
@@ -162,7 +170,7 @@ type InferFactoryModels<TFactory> = TFactory extends (
162170 * Infer the adapter return type from a factory function.
163171 */
164172type InferAdapterReturn < TFactory > = TFactory extends (
165- ...args : Array < any >
173+ ...args : Array < never >
166174) => infer TReturn
167175 ? TReturn
168176 : never
@@ -173,16 +181,16 @@ type InferAdapterReturn<TFactory> = TFactory extends (
173181 * Note: overloaded factories resolve against their last overload (a
174182 * `Parameters` limitation).
175183 */
176- type InferRestArgs < TFactory extends ( ... args : Array < any > ) => any > =
177- Parameters < TFactory > extends [ any ?, ...infer TRest ] ? TRest : [ ]
184+ type InferRestArgs < TFactory extends AnyAdapterFactory > =
185+ Parameters < TFactory > extends [ unknown ?, ...infer TRest ] ? TRest : [ ]
178186
179187/**
180188 * The factory signature produced by `extendAdapter`: accepts both original
181189 * and custom model names while preserving all remaining parameters and the
182190 * return type of the original factory.
183191 */
184192type ExtendedFactory <
185- TFactory extends ( model : any , ... args : Array < any > ) => any ,
193+ TFactory extends AnyAdapterFactory ,
186194 TDefs extends ReadonlyArray < ExtendedModelDef > ,
187195> = (
188196 model : InferFactoryModels < TFactory > | ExtractCustomModelNames < TDefs > ,
@@ -237,9 +245,15 @@ type ExtendedFactory<
237245 * ```
238246 */
239247export function extendAdapter <
240- TFactory extends ( model : any , ... args : Array < any > ) => any ,
248+ TFactory extends AnyAdapterFactory ,
241249 const TDefs extends ReadonlyArray < ExtendedModelDef > ,
242- > ( factory : TFactory , _customModels : TDefs ) : ExtendedFactory < TFactory , TDefs > {
250+ > ( factory : TFactory , _customModels : TDefs ) : ExtendedFactory < TFactory , TDefs >
251+ // The implementation signature stays at the honest `AnyAdapterFactory` width;
252+ // the overload above performs the deliberate model-union widening.
253+ export function extendAdapter (
254+ factory : AnyAdapterFactory ,
255+ _customModels : ReadonlyArray < ExtendedModelDef > ,
256+ ) : AnyAdapterFactory {
243257 // At runtime, we simply pass through to the original factory.
244258 // The _customModels parameter is only used for type inference.
245259 // No runtime validation - users are trusted to pass valid model names.
0 commit comments