When it comes to the Date object, you can create an instance using either a number or a string:
new Date("...");
new Date(123456);
Interestingly, while both number and string types are accepted, the union type string|number is not:
if (typeof value === "string" || typeof value === "number") {
object = new Date(value); // Error.
}
Argument of type 'string | number' is not assignable to parameter of type 'string'. Type 'number' is not assignable to type 'string'.
This raises the question - what is the reasoning behind this behavior? It seems unnecessary to use an if...else chain when both accepted types should work. Why restrict usage in this case?