Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rjamesnw opened this issue Apr 29, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@rjamesnw
Copy link

rjamesnw commented Apr 29, 2017

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. :/

@mhegazy
Copy link
Contributor

mhegazy commented May 17, 2017

Duplicate of #8397

@mhegazy mhegazy added the Duplicate An existing issue was already created label May 17, 2017
@mhegazy mhegazy closed this as completed May 17, 2017
@mhegazy
Copy link
Contributor

mhegazy commented May 18, 2017

Tracked by #5616

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants