Skip to content

Type inference for union type passed to overloaded generic function seems broken #20215

Closed
@nickjs

Description

@nickjs

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

No one assigned

    Labels

    BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions