export type BridgeMethods = Omit < typeof my , 'call' | 'ap' | 'reportCustomError' | 'reportAnalytics' | 'getRunScene' | 'SDKVersion' > ; export type APBridgeMethods = typeof my . ap ; export type PickSuccessResult < T > = T extends { success ? : ( r : infer R ) => any | void ; fail ? : ( r ? : any ) => any | void ; } ? R : never ; export type Fn = ( params : any , ... args : any [ ] ) => any | void ; export type SpecialMethods = { reportCustomError : ( error : Error ) => void ; reportAnalytics : ( eventName : string , data : Record < string , any > ) => void ; getRunScene : ( res : my . IGetRunSceneOptions ) => void ; } ; export default { call : async function call < T extends keyof R , R extends Record < string , any > = BridgeMethods & SpecialMethods > ( api , params ? ) : Promise < PickSuccessResult < Parameters < R [ T ] > [ 0 ] > > { return new Promise ( ( resolve , reject ) => { if ( typeof ( my as R extends BridgeMethods ? R : any ) [ api ] === 'function' ) { ( my as R extends BridgeMethods ? R : any ) [ api ] ( { ... ( params as any ) , success ( res ) { resolve ( res ) ; } , fail : reject , } ) ; } } ) ; } , mycall : async function mycall < R , P = Record < string , any > > ( api , params ? ) : Promise < R > { return new Promise ( resolve => { my . call ( api , params , ( result ) => { resolve ( result ) ; } ) ; } ) ; } , ap : async function ap < T extends keyof R , R extends Record < string , Fn > = APBridgeMethods > ( api , params ? ) : Promise < PickSuccessResult < Parameters < R [ T ] > [ 0 ] > > { return new Promise ( ( resolve , reject ) => { if ( typeof ( my as R extends APBridgeMethods ? R : any ) [ api ] === 'function' && params ) { ( my as R extends APBridgeMethods ? R : any ) [ api ] ( { ... params , success ( res ) { resolve ( res ) ; } , fail ( ) { reject ( ) ; } , } ) ; } } ) ; } , } ;