Is there a way to use TypeScript to prevent accidental global access?
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 calling `this.focus()` - The code compiled fine, because `window.focus()` shares the same signature as our `focus()` 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.
Posted by bcherny on Feb 25, 2017, 1:29 AM
Tags
Related issues
- [BUG] Cowork (Windows): all Plan9 shares fail with "Plan9 mount failed: invalid argument" after Windows update KB5124008 (26200.9445) — uninstalling the KB fixe
- Feature Request: Auto-resume CLI session when usage limit resets
- Please deobfuscate the Python
- [Bug] MLX version of Gemma 4 26B fails to load: "Model type gemma4 not supported" (macOS)
- # 233 Developers Discussed Abandoning the Office Add-in Platform — An Open Letter on the Office.js Stability, Security & Trust Crisis
- [FEATURE] Allow users to configure which shell the Bash tool uses or inherit initial shell
Raise real-world problems, find people facing the same issue, and discuss solutions.4,500 issues0 comments
reliability (Software)
[BUG] Cowork (Windows): all Plan9 shares fail with "Plan9 mount failed: invalid argument" after Windows update KB5124008 (26200.9445) — uninstalling the KB fixe
Feature Request: Auto-resume CLI session when usage limit resets
Please deobfuscate the Python
[Bug] MLX version of Gemma 4 26B fails to load: "Model type gemma4 not supported" (macOS)
# 233 Developers Discussed Abandoning the Office Add-in Platform — An Open Letter on the Office.js Stability, Security & Trust Crisis
[FEATURE] Allow users to configure which shell the Bash tool uses or inherit initial shell
Admin Materials and Surfaces
AMD Support
Is there a way to use TypeScript to prevent accidental global access?
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 calling `this.focus()` - The code compiled fine, because `window.focus()` shares the same signature as our `focus()` 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.
Comments (0)
No comments yet. Start the discussion.