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
Expected behavior:
The type checker should catch that bar will be called with a this of undefined (assuming strict mode). Methods should have an implicit this of the containing class (in this case this: Foo), or at least an interface with the properties accessed within the method (this: { name: string }).
Actual behavior:
No compile error is emitted and a runtime error is the result.
In #14936, @RyanCavanaugh mentions there being a performance cost to adding in implicit this types. At least in my case, since I was bit by this, I would be willing to pay the extra cost during compile to catch these kind of errors. Perhaps a compiler option would be worthwhile.
The text was updated successfully, but these errors were encountered:
TypeScript Version: 2.3.4
Code
This is a repro of an actual bug that bit me which I was surprised the type checker did not catch.
Expected behavior:
The type checker should catch that
bar
will be called with athis
ofundefined
(assuming strict mode). Methods should have an implicitthis
of the containing class (in this casethis: Foo
), or at least an interface with the properties accessed within the method (this: { name: string }
).Actual behavior:
No compile error is emitted and a runtime error is the result.
In #14936, @RyanCavanaugh mentions there being a performance cost to adding in implicit
this
types. At least in my case, since I was bit by this, I would be willing to pay the extra cost during compile to catch these kind of errors. Perhaps a compiler option would be worthwhile.The text was updated successfully, but these errors were encountered: