11import * as tasks from "./tasks" ;
2- import type { Options , RequestArgs } from "./types" ;
3- import type { DistributiveOmit } from "./utils/distributive-omit" ;
2+ import type { Options } from "./types" ;
43import { omit } from "./utils/omit" ;
4+ import { typedEntries } from "./utils/typedEntries" ;
55
66/* eslint-disable @typescript-eslint/no-empty-interface */
77/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
88
99type Task = typeof tasks ;
1010
11- type TaskWithNoAccessToken = {
12- [ key in keyof Task ] : (
13- args : DistributiveOmit < Parameters < Task [ key ] > [ 0 ] , "accessToken" > ,
14- options ?: Parameters < Task [ key ] > [ 1 ]
15- ) => ReturnType < Task [ key ] > ;
16- } ;
17-
1811export class InferenceClient {
1912 private readonly accessToken : string ;
2013 private readonly defaultOptions : Options ;
@@ -28,15 +21,19 @@ export class InferenceClient {
2821 this . accessToken = accessToken ;
2922 this . defaultOptions = defaultOptions ;
3023
31- for ( const [ name , fn ] of Object . entries ( tasks ) ) {
24+ for ( const [ name , fn ] of typedEntries ( tasks ) ) {
3225 Object . defineProperty ( this , name , {
3326 enumerable : false ,
34- value : ( params : RequestArgs , options : Options ) =>
27+ value : ( params : Parameters < typeof fn > [ 0 ] , options : Parameters < typeof fn > [ 1 ] ) =>
3528 // eslint-disable-next-line @typescript-eslint/no-explicit-any
36- fn ( { endpointUrl : defaultOptions . endpointUrl , accessToken, ...params } as any , {
37- ...omit ( defaultOptions , [ "endpointUrl" ] ) ,
38- ...options ,
39- } ) ,
29+ ( fn as any ) (
30+ /// ^ The cast of fn to any is necessary, otherwise TS can't compile because the generated union type is too complex
31+ { endpointUrl : defaultOptions . endpointUrl , accessToken, ...params } ,
32+ {
33+ ...omit ( defaultOptions , [ "endpointUrl" ] ) ,
34+ ...options ,
35+ }
36+ ) ,
4037 } ) ;
4138 }
4239 }
@@ -51,7 +48,7 @@ export class InferenceClient {
5148 }
5249}
5350
54- export interface InferenceClient extends TaskWithNoAccessToken { }
51+ export interface InferenceClient extends Task { }
5552
5653/**
5754 * For backward compatibility only, will remove soon.
0 commit comments