Skip to content

Unexpected overload signature is matched with constructor type #51899

@markostanimirovic

Description

@markostanimirovic

Bug Report

🔎 Search Terms

overload, constructor type

🕗 Version & Regression Information

I tested with different TS v4 versions. This bug does not seem like a regression.

⏯ Playground Link

Playground link with relevant code

💻 Code

type Type<T> = new (...args: any[]) => T;

function inject<T>(t: Type<T>): T;
function inject(t: any): any; // comment out this line => the type of `c2` will be `ClassWithCtorArgs`
function inject(t: any): any {
    return t;
}

class Class {}

class ClassWithCtorArgs {
    constructor(x: number) {}
}

// type: Class ✅
const c1 = inject(Class);

// type: any ❌
const c2 = inject(ClassWithCtorArgs);

🙁 Actual behavior

The type of c2 constant from the example is any.

🙂 Expected behavior

The type of c2 constant from the example should be ClassWithCtorArgs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions