import { Pipe , PipeTransform } from '@angular/core' ; interface TrackByFunctionCache { [ propertyName ] : < T > ( index : number , item : T ) => any ; } const cache = { } ; @ Pipe ( { name : 'trackByProperty' , pure : true , } ) export class TrackByPropertyPipe implements PipeTransform { public transform ( propertyName ) { if ( ! cache [ propertyName ] ) { cache [ propertyName ] = function trackByProperty < T > ( index , item ) : any { return item [ propertyName ] ; } ; } return cache [ propertyName ] ; } }