Skip to content

Generic type constraint ignored when applied to interface expecting a different signature. #15458

@rjamesnw

Description

@rjamesnw

Not sure if I found a bug or not, so just checking first. The code below should not work, but it compiles fine:

interface IType<TInstance> {
    new (value: boolean, ...args: any[]): TInstance;
}

class Test<T extends string> {
    constructor(value: T) { }
}

function doSomething(_type: IType<any>) { }

doSomething(Test);

(here)

If I change constructor(value: T) { } to constructor(value: string) { } it fails. It should fail anyhow, since T could NEVER be of the expected type. :/

This also just seems wrong:

interface IType<TInstance> {
    new (value: boolean, ...args: any[]): TInstance;
}

class Test<T extends Object> {
    constructor(value: T) { }
}

function doSomething(_type: IType<any>) { }

doSomething(Test);

class O extends Object { }

class TO extends Test<O> { }

doSomething(TO);

Compiles just fine. :/

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions