ag grid - What is the typescript type for columnDefs callback functions?


Keywords:ag  grid 


Question: 

I have a columnDefs declaration that looks as following:

constColumnDefs = [
{headerName: 'a', field:'a', valueGetter: myValueGetter, ....
]

So when defining myValueGetter function, whats the type for params? I am using "any" and it works, but I would like to make it more "typescripty"

const myValueGetter = function(params: any) {
   if (!params || !params.data) {
       return null;
   }
   etc....
}

thank you


1 Answer: 

The definition of valueGetter is as below.

valueGetter?: ((params: ValueGetterParams) => any) | string;

If you are curious about ValueGetterParams, its as below.

export interface ValueGetterParams extends BaseColDefParams {
    getValue: (field: string) => any;
}
export interface BaseColDefParams {
    node: RowNode;
    data: any;
    colDef: ColDef;
    column: Column;
    api: GridApi;
    columnApi: ColumnApi;
    context: any;
}

You can find it inside colDef.d.ts file of the node_module.