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

Include function this argument in function signature #9069

Closed
iskiselev opened this issue Jun 10, 2016 · 1 comment
Closed

Include function this argument in function signature #9069

iskiselev opened this issue Jun 10, 2016 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@iskiselev
Copy link

iskiselev commented Jun 10, 2016

In JavaScript each function, except normal arguments has a special call-time bound this argument. TypeScript greatly helps to find an error when any of normal arguments passed into function is incorrect, but currently doesn't help to find an error when function called against incorrect this. It is even covered in FAQ.
If only TypeScript calculate (and allow override) this type for function, and treat it as additional argument when compare functions type, all such problems would be mitigated.
If function doesn't use any this fields, such additional argument simply should have any type.

Here is an example of source with such problem:

class SampleClass{
  field : string;
  f(){ return this.field};
}

var instance = new SampleClass;
var detachedF = instance.f;
detachedF();

In that example, TypeScript has enough info to infer, that detachedF could be called only over interface {field : string} type.

@kitsonk
Copy link
Contributor

kitsonk commented Jun 10, 2016

Dupe of #3694 and already in master and will be released as part of TypeScript 2.0.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Jun 10, 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
Projects
None yet
Development

No branches or pull requests

3 participants