Skip to content

Commit ab966e1

Browse files
authored
Merge pull request basarat#581 from simon-robertson/patch-1
Extended the use case for the global.d.ts file
2 parents 3aada08 + 0e1fdcb commit ab966e1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

docs/project/globals.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ We discussed *global* vs. *file* modules when covering [projects](./modules.md)
44

55
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.
66

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.
88

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+
declare const BUILD_MODE_PRODUCTION: boolean; // can be used for conditional compiling
11+
declare const 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

Comments
 (0)