Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit d0a9bb2

Browse files
author
Andy Hanson
committed
Add description of UMD modules to Modules.md in addition to Writing Declaration Files.md
1 parent 39e298d commit d0a9bb2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

pages/Modules.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,31 @@ import x, {y} from "hot-new-module";
517517
x(y);
518518
```
519519

520+
### UMD modules
521+
522+
Some libraries can be used either through imports or through globals.
523+
524+
##### math-lib.d.ts
525+
526+
```ts
527+
export const isPrime(x: number): boolean;'
528+
export as namespace mathLib;
529+
```
530+
531+
The library can then be used as an import within modules:
532+
533+
```ts
534+
import { isPrime } from "math-lib";
535+
isPrime(2);
536+
mathLib.isPrime(2); // ERROR: can't use the global definition from inside a module
537+
```
538+
539+
It can also be used as a global variable, but only inside of a script:
540+
541+
```ts
542+
mathLib.isPrime(2);
543+
```
544+
520545
# Guidance for structuring modules
521546

522547
## Export as close to top-level as possible

0 commit comments

Comments
 (0)