I working in react typescript. I have created a common utility function like this -
interface IUpdatedRows {
rowsPerPage: number;
// this is where the confusion is -
rows: {
id: number;
name: string;
description: string;
role: string;
manager: string;
total_tasks: number;
annotator: number;
qc: number; }[];
//
page: number;
}
export const updatedRows = (args: IUpdatedRows) => (args.rowsPerPage > 0
? args.rows.slice(args.page * args.rowsPerPage, args.page * args.rowsPerPage + args.rowsPerPage)
: args.rows
);
Here I will use updatedRows function from separate components having different set of rows. Above situation works well only for 1 component where row have exactly the type I have mentioned above i.e.
row: {
id: number;
name: string;
description: string;
role: string;
manager: string;
total_tasks: number;
annotator: number;
qc: number; }[];
In a different component row have these fields -
row: {
id: number;
name: string;
code: string;
type: string;
added_by: string;
added_on: string;
};
I am not sure how to give a common type in a utility file for row which will be applicable for all the components. Any help, pointers is highly appreciated.
IUpdatedRows<T>generic with rows: T[] or any of its variations.