In my dataset, there are dates in different formats that Typescript doesn't recognize. To address this issue, I developed a "safeDateParse" function to handle extended conversions and modified the Date.parse() method accordingly.
/** Custom overload */
Date.parse = function parse(dateAsString: string) {
return safeDateParse(dateAsString).valueOf();
};
This modification works well when creating a Date object using the syntax below.
const lastUsedDate = new Date(Date.parse(lastUsed));
However, I also want to override the constructor so I can use the following syntax.
let newDate = new Date(dateString);
I attempted to do this by defining a function, but it didn't produce the desired result as it replaced the Date class instead of extending it. I believe there should be some kind of "super" or "parent" call within it to maintain the core functionality of the Date object.
Is it feasible to override the constructor in this context, and if yes, what would be the correct syntax?