I am trying to use Ag-Grid for my angular application and create a custom cell renderer. In the implementation that I have followed, it uses ICellRendererParams for the type of params being passed to the init event.
agInit(params: ICellRendererParams): void {
this.params = params;
this.type = this.params.type || null;
}
But now when I try to access custom prop from that params the lint gives the error Property 'type' does not exist on type 'ICellRendererParams'.. Which works perfectly fine when I change the type to any. I have tried creating a custom model class inheriting from ICellRendererParams and adding a property type in it and using that class instead of ICellRendererParams. I wanted to ask if this is the right approach or is there any other cleaner approach to access a property from the interface.
Late answer, but this is the proper way to do it.
type ICellRendererParamsWithGridType = ICellRendererParams & { type: string;};
@Component({
selector: 'cc-course-timing-grid-cell',
templateUrl: './course-timing-grid-cell.component.html',
styleUrls: ['./course-timing-grid-cell.component.scss'],
})
export class CourseTimingGridCellComponent {
gridType!: string;
getEntitiesToolTip
constructor() {}
//...
}
Here we are using Intersection Types. The above code is the short-hand for,
interface CustomParamsType{
type: string;
}
type ICellRendererParamsWithGridType = ICellRendererParams & CustomParamsType;