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
Copy file name to clipboardExpand all lines: docs/project/globals.md
+9-3Lines changed: 9 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,13 @@ We discussed *global* vs. *file* modules when covering [projects](./modules.md)
4
4
5
5
Nevertheless, if you have beginner TypeScript developers you can give them a `global.d.ts` file to put interfaces / types in the global namespace to make it easy to have some *types* just *magically* available for consumption in *all* your TypeScript code.
6
6
7
-
> For any code that is going to generate *JavaScript* we highly recommend using *file modules*.
7
+
Another use case for a `global.d.ts` file is to declare compile-time constants that are being injected into the source code by Webpack via the standard [DefinePlugin](https://webpack.js.org/plugins/define-plugin/) plugin.
8
8
9
-
*`global.d.ts` is great for adding extensions to `lib.d.ts` if you need to.
10
-
* It's good for quick `declare module "some-library-you-dont-care-to-get-defs-for";` when doing JS to TS migrations.
9
+
```ts
10
+
declareconst BUILD_MODE_PRODUCTION:boolean; // can be used for conditional compiling
11
+
declareconst BUILD_VERSION:string;
12
+
```
13
+
14
+
> For any code that is going to generate *JavaScript* we highly recommend using *file modules*, and only use `global.d.ts` to declare compile-time constants and/or to extend standard type declarations declared in `lib.d.ts`.
15
+
16
+
* Bonus: The `global.d.ts` file is also good for quick `declare module "some-library-you-dont-care-to-get-defs-for";` when doing JS to TS migrations.
0 commit comments