export default function attachLogic < K extends string , F extends ( ... args : any [ ] ) => any > ( options , key , position , fn ) { const oldFn = options [ key ] ; options [ key ] = function ( this , ... args ) : any { if ( position === 'before' ) { fn . call ( this , ... args ) ; } const result = oldFn && oldFn . call ( this , ... args ) ; if ( position === 'after' ) { fn . call ( this , ... args ) ; } return result ; } as any ; }