Closed
Description
TypeScript Version: 2.7.0-dev.20171121, 2.6.1
Type unions coming specifically from an interface and passed to an overloaded generic constructor (like new Date
) seems to break the type inference. Neither of the possible constructor overloads are matched, even though both parts of the type union are supported by the constructor.
Code
interface Foo {
publishDate: Date | string;
}
const source: Foo = { publishDate: new Date() };
const target = new Date(source.publishDate);
Expected behavior:
target => 2017-11-22T04:08:13.477Z
Actual behavior:
Argument of type 'string | Date' is not assignable to parameter of type 'VarDate'. Type 'Date' is not assignable to type 'VarDate'.