You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 haveany
type.Here is an example of source with such problem:
In that example, TypeScript has enough info to infer, that
detachedF
could be called only overinterface {field : string}
type.The text was updated successfully, but these errors were encountered: