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
I can understand the reasoning behind including this line -- it might seem like the most expedient and convenient way to make sure those using Sugar as a global get the benefits of typings. Unfortunately, it irreversibly prevents all consumers of this library from having a variable named Sugar anywhere in their code. This is even true for consumers of a package that depends on Sugar -- if Sugar exists anywhere in their chain of dependencies, they're prevented from having a variable named Sugar. What's more, they'll always receive autocomplete suggestions in their tooling to use this global var Sugar, which can lead to runtime undefined errors; it also prevents auto-import tooling in editors like VSCode from working properly.
Given that that vast majority of people who've adopted TypeScript today are not using globals, this approach seems to hurt more than it helps, and it's out of line with best practices for typings. I'd suggest removing this line and instead recommending anyone using TS who needs Sugar as a global to make it accessible themselves via their own .d.ts file that declares that global itself; the handful of TS users working with legacy unscoped codebases should be familiar with how to do this.
The text was updated successfully, but these errors were encountered:
So v3 is currently being worked on that will use regular ES6 modules that do not expose the Sugar object as a global. As part of this the typings are being re-written from the ground up so this should be solved there. As for v2 this accurately represents the fact that Sugar is in fact exposed as a global so I think this is the correct typings for them no? If you have another suggestion about how to correctly type globals with TS I could change it as a patch for v2.
Hi there, I noticed the typings include a global variable declaration at the bottom:
Sugar/sugar.d.ts
Line 1235 in 3ca5781
I can understand the reasoning behind including this line -- it might seem like the most expedient and convenient way to make sure those using Sugar as a global get the benefits of typings. Unfortunately, it irreversibly prevents all consumers of this library from having a variable named
Sugar
anywhere in their code. This is even true for consumers of a package that depends on Sugar -- if Sugar exists anywhere in their chain of dependencies, they're prevented from having a variable namedSugar
. What's more, they'll always receive autocomplete suggestions in their tooling to use this global varSugar
, which can lead to runtime undefined errors; it also prevents auto-import tooling in editors like VSCode from working properly.Given that that vast majority of people who've adopted TypeScript today are not using globals, this approach seems to hurt more than it helps, and it's out of line with best practices for typings. I'd suggest removing this line and instead recommending anyone using TS who needs Sugar as a global to make it accessible themselves via their own
.d.ts
file that declares that global itself; the handful of TS users working with legacy unscoped codebases should be familiar with how to do this.The text was updated successfully, but these errors were encountered: