Skip to content

thisType versus this #9096

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

Closed
electricessence opened this issue Jun 11, 2016 · 2 comments
Closed

thisType versus this #9096

electricessence opened this issue Jun 11, 2016 · 2 comments
Labels
Duplicate An existing issue was already created Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@electricessence
Copy link

electricessence commented Jun 11, 2016

#9063 (comment)

Wanted to open the discussion to possibly allowing for something other than this for polymorphic typing.

Right now...

class A<T> {
    clone():this {
       return <any> new A<T>();  // without <any> it complains.
    }
   me():this {
      return this; // doesn't complain
   }
}

And it would be really nice to be able to:

class A<T> {
    map<TResult>(mapper: (v: T) => TResult): this<TResult>{
       // ...
    }
}
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jun 11, 2016

But your clone method doesn't return something of type this, it returns something of type A<T>. If you extended A with a class named B, clone wouldn't give you something with the members that B has.

A simple way to look at it is that the this type is supposed to model the type of the expression that you're calling a method off of.

As for the second thing, I think that's a duplicate of #6223.

@kitsonk
Copy link
Contributor

kitsonk commented Jun 11, 2016

It is, and the biggest challenge discussed in there is that if the arity of the generic arguments changes, how is this handled.

@mhegazy mhegazy added Duplicate An existing issue was already created Working as Intended The behavior described is the intended behavior; this is not a bug labels Jun 11, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
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 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