declare function MACRO < T > ( t ) ; const MAP = MACRO ( < T , L > ( inputConst , visitor ) => { const input = inputConst ; const length = input . length ; const result = new Array ( length ) as L [ ] ; for ( let i = 0 ; i < length ; i ++ ) { result [ i ] = visitor ( input [ i ] , i , input ) ; } return result ; } ) ; declare interface Array < T > { MAP : Array < T > [ "map" ] ; } console . log ( [ 1 , 2 , 3 ] . MAP ( n => 3 * n + 1 ) ) ;