This repository was archived by the owner on Oct 12, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -517,6 +517,35 @@ import x, {y} from "hot-new-module";
517
517
x (y );
518
518
```
519
519
520
+ ### UMD modules
521
+
522
+ Some libraries are designed to be used in many module loaders, or with no module loading (global variables).
523
+ These are known as [ UMD] ( https://github.com/umdjs/umd ) or [ Isomorphic] ( http://isomorphic.net ) modules.
524
+ These libraries can be accessed through either an import or a global variable.
525
+ For example:
526
+
527
+ ##### math-lib.d.ts
528
+
529
+ ``` ts
530
+ export const isPrime(x: number ): boolean ;'
531
+ export as namespace mathLib;
532
+ ```
533
+
534
+ The library can then be used as an import within modules:
535
+
536
+ ``` ts
537
+ import { isPrime } from " math-lib" ;
538
+ isPrime (2 );
539
+ mathLib .isPrime (2 ); // ERROR: can't use the global definition from inside a module
540
+ ```
541
+
542
+ It can also be used as a global variable, but only inside of a script.
543
+ (A script is a file with no imports or exports.)
544
+
545
+ ``` ts
546
+ mathLib .isPrime (2 );
547
+ ```
548
+
520
549
# Guidance for structuring modules
521
550
522
551
## Export as close to top-level as possible
You can’t perform that action at this time.
0 commit comments