Open Mouvedia opened 5 years ago
Wasn't this resolved with the ::
proposal?
ThisType::example(name: Type) => ThisType
And, if you want to document changes:
ThisType::example(name: Type) => ThisType & { foo: String }
I assume that ThisType
is akin to Foo
and not your proposal for this
@ericelliott I am talking about a dynamic type. As explained here:
…granted that you have declared the newly bound interface.
As I said in the nota bene up there that would require to return unions. Also your example can't work precisely because the signature of the function that I am talking about is not bound (i.e it may have different call-sites).
What are our priorities? Are the use cases for this feature too rare?
PRO
this
CON
ThisType
is a type variable. It does not need to be declared.
Essentially, it is the same thing as this
, and even without explicitly adding a special this
type, you could just use it, and it would be treated as a type variable:
this::method() => this
But you need the ::
to use it. That's how we know you're working with this
.
But you need the
::
to use it. That's how we know you're working withthis
.
I like this, it's explicit.
ThisType
is a type variable.
I thought we encouraged type variables to be one char long:
By convention, type variables are single letters and lowercased…
related: #68
example
You have a fluent interface but one of the method X is slightly restrictive and doesn't return
this
but a subset of itsthis
. In this case if the next method Y returnsthis
it will share its constraints.problem: if that method Y may also follow another method Z that returns
this
, its return type becomes dynamic. solution: introduce athis
return typeNB
It would be impractical to require the user to provide all the possibilities as unions. It's the job of the static type checker; it should be able to infer the correct type from the current
this
.proposal