-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Suggestion: typechecking of 'this' context #15
Copy link
Copy link
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already createdNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already createdNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript
A common error in TypeScript is to lose the
thiscontext, especially in class situations:The compiler should detect when this happens and issue an error:
We need a proposal here that determines why this would be an error, in a way that is not burdensome. For example, we do want it to be valid to call e.g.
function#bindonm.printX, and it should probably valid to write something likeif(m.printX) { m.printX() }.This gets even trickier when we look at the members of
window-- some of them can be invoked with anythis, but others cannot. It should be possible to describe these differences.