Closed
Description
Reported by @yangchristian in #2775 (comment)
I repro @larsenwork's issue with the following:
type CreatedOrUpdatedAt =
{ createdAt: Date | string } |
{ updatedAt: Date | string };
const datePropComp = <T extends CreatedOrUpdatedAt, K extends keyof T>(a: T, b: T, field: K) => {
// The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
const dateA = a[field] instanceof Date ? a[field] : new Date(a[field]);
const dateB = b[field] instanceof Date ? b[field] : new Date(b[field]);
return dateA.getTime() - dateB.getTime();
};
datePropComp({ updatedAt: Date() }, { updatedAt: Date() }, 'updatedAt' )