microsoft / microsoft/TypeScript
Is there a way to use TypeScript to prevent accidental global access?
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit dem verlinkten SlickGrid-Commit, um den im Issue beschriebenen versehentlichen globalen Zugriff zu reproduzieren. Prüfen Sie die Diskussion, um festzustellen, ob das angeforderte Verhalten eine Compilerdiagnose oder ein neues Flag ist; es wird keine Quelldatei und kein Test genannt, daher würde der Abschluss ein abgestimmtes Design und eine entsprechende Compiler-Abdeckung erfordern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 35/100