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

Cannot use 'this' type in type argument on base types #7289

Closed
DanielRosenwasser opened this issue Feb 29, 2016 · 5 comments
Closed

Cannot use 'this' type in type argument on base types #7289

DanielRosenwasser opened this issue Feb 29, 2016 · 5 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@DanielRosenwasser
Copy link
Member

interface Foo<T> {
    thing: T;
}

interface Bar extends Foo<this> {
    thing: this;
}
class Foo<T> {
    thing: T;
}

class Bar extends Foo<this> {
    thing: this;
}
interface Foo<T> {
    thing: T;
}

class Bar implements Foo<this> {
    thing: this;
}

These examples have an error on the 'this' type argument of Foo:

TS2526  A 'this' type is available only in a non-static member of a class or interface.

Since an object type cannot reference a type parameter directly within a heritage clause, we shouldn't be giving this error.

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript and removed Bug A bug in TypeScript labels Feb 29, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Apr 26, 2016

The class is by design, as the type parameter could be used in the constructor. but the interface seems reasonable.

@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus and removed Bug A bug in TypeScript labels Apr 26, 2016
@DanielRosenwasser
Copy link
Member Author

as the type parameter could be used in the constructor

Can you elaborate what you mean? I'm not necessarily seeing the issue in that case.

@kitsonk
Copy link
Contributor

kitsonk commented May 17, 2016

Related to #6223. While subtly different, I suspect they are in the same problem space.

@dead-claudia
Copy link

Well...we could use it for Mithril.js types, where we were looking to add class support. We could avoid creating an entire boilerplate type by just allowing this as a generic parameter in the implements clause. Just thought I'd bring that up.

(Oh, and this would also help quite a bit from the other end.)

@RyanCavanaugh
Copy link
Member

Seems to not be a very popular scenario

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants