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 with extends and return will fail compilation #17794

Closed
jsgoupil opened this issue Aug 15, 2017 · 6 comments
Closed

Generic with extends and return will fail compilation #17794

jsgoupil opened this issue Aug 15, 2017 · 6 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@jsgoupil
Copy link

TypeScript Version: 2.4.2

class A {

}

export class B {
    public method<T extends A>(val: T): Promise<T> {
        return new Promise(resolver => {
            resolver(new A());
        });
    }
}

It fails with this
Argument of type 'A' is not assignable to parameter of type 'T | PromiseLike'.
Type 'A' is not assignable to type 'PromiseLike'.
Property 'then' is missing in type 'A'.

This code compiled just fine in 2.3

It looks similar to this old bug which compiled fine with 2.3, but fails with 2.4
#13993

@kitsonk
Copy link
Contributor

kitsonk commented Aug 15, 2017

Not reproducible in the playground.

@ahejlsberg
Copy link
Member

This is working as intended and is an effect of #15104. Type A is not assignable to type T because T represents some type that derives from A.

We also now handle #13993 correctly (by reporting an error), but for a different reason. It was fixed by #16368.

@ahejlsberg ahejlsberg added the Working as Intended The behavior described is the intended behavior; this is not a bug label Aug 15, 2017
@jsgoupil
Copy link
Author

@ahejlsberg then maybe I am looking at this where T : A C# thing but in TypeScript?

The documentation does not make any other mention of this? https://www.typescriptlang.org/docs/handbook/generics.html

Is it possible in 2.4?

@mhegazy
Copy link
Contributor

mhegazy commented Aug 29, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Aug 29, 2017
@jsgoupil
Copy link
Author

@mhegazy could you kindly let me know if there is such a thing as I asked in the previous comment?
I am staying on 2.3 until I figure this out...

@mhegazy
Copy link
Contributor

mhegazy commented Aug 29, 2017

Is it possible in 2.4?

no. this is flagged as error in 2.4 +

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants