export type PromiseCreator < T = any > = ( ... args : any [ ] ) => Promise < T > ; export type FunctionType = ( ... args : any [ ] ) => any ; /**
 * async silent failure, do not affect other code execution
 *
 * return null if error
 */ type ReturnWithNull < FnType extends FunctionType > = ( ... args : Parameters < FnType > ) => ReturnType < FnType > | null ; type ResolveWithNull < FnType extends PromiseCreator > = ( ... args : Parameters < FnType > ) => ReturnType < FnType > | Promise < null > ; function silent < FnType extends FunctionType > ( fn ) { return ( ... args ) : ReturnType < ReturnWithNull < FnType > > => { try { return fn ( ... args ) ; } catch ( e ) { if ( typeof console !== 'undefined' && console . error ) { console . error ( e ) ; } return null ; } } ; } silent . async = < FnType extends PromiseCreator > ( fn ) : ResolveWithNull < FnType > => ( async ( ... args ) : Promise < any > => { try { return await fn ( ... args ) ; } catch ( e ) { if ( typeof console !== 'undefined' && console . error ) { console . error ( e ) ; } return null ; } } ) as ResolveWithNull < FnType > ; export default silent ;