-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Closed
Copy link
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this
Milestone
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'.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this