microsoft / microsoft/TypeScript
Is there a way to use TypeScript to prevent accidental global access?
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
I just spent 2 hours tracking down this issue:
- We have a class with a prototype method called
focus() - Our code was calling
focus(), but it should have been callingthis.focus() - The code compiled fine, because
window.focus()shares the same signature as ourfocus()method
Is there a way to throw a compile time error when implicitly accessing global methods (on window, global, etc.)?
If not, a compiler flag would be extremely helpful. I would happily be more explicit about commonly used globals (window.setTimeout, window.document, ...) if it meant I could more easily catch insidious bugs like this one.
Full commit here: https://github.com/coatue/SlickGrid/commit/0f8bab3fa9968173d749ccdf535c88f3a526ca8b.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin with the linked SlickGrid commit to reproduce the accidental global access described in the issue. Review the discussion to determine whether the requested behavior is a compiler diagnostic or a new flag; no source file or test is named, so completion would require an agreed design and corresponding compiler coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100