Is it possible to modify the signature of sortArrayItemsByDate
in order to add the following additional constraints cumulatively:
T
must have a key namedpropName
(with a value in object key-names)T[propName]
should be a string at the same time
Here is a link to the StackBlitz playground
const sortArrayItemsByDate = <T>(items: T[], propName: string): T[] =>
items.sort((a: T, b: T) => Date.parse(a[propName]) - Date.parse(b[propName]));
interface StudentModel {
name: string;
birthday: string;
}
const s0: StudentModel = {
name: "Peter",
birthday: "2001-11-23",
};
const s1: StudentModel = {
name: "John",
birthday: "2003-11-30",
};
const students: StudentModel[] = [s0, s1];
const studentsSorted = sortArrayItemsByDate(students, 'birthday');