UNPKG

4.5 kBTypeScriptView Raw
1declare const System: {
2 /**
3 * Loads a javascript module from either a url or bare specifier that is in an import map.
4 * You may optionally provide a parentUrl that will be used for resolving relative urls.
5 */
6 import: System.ImportFn;
7
8 /**
9 * Inserts a new module into the SystemJS module registry. The System.register format is
10 * the underlying implementation that allows for ESM emulation.
11 * See https://github.com/systemjs/systemjs/blob/master/docs/system-register.md for more details.
12 * Register may be called with a name argument if you are using the named-register extra. (See
13 * https://github.com/systemjs/systemjs#extras).
14 */
15 register(dependencies: string[], declare: System.DeclareFn): void;
16 register(name: string, dependencies: string[], declare: System.DeclareFn): void;
17
18 /**
19 * Resolve any moduleId to its full URL. For a moduleId that is in the import map, this will resolve
20 * the full import map URL. For a moduleId that is a relative url, the returned url will be resolved
21 * relative to the parentUrl or the current browser page's base url. For a full url, resolve() is
22 * a no-op.
23 */
24 resolve(moduleId: string, parentUrl?: string): string;
25
26 /**
27 * Delete a module from the module registry. Note that the moduleId almost always must be a full url and that
28 * you might need to call System.resolve() to obtain the moduleId for modules in an import map.
29 * The returned function is intended for use after re-importing the module. Calling the function
30 * will re-bind all the exports of the re-imported module to every module that depends on the module.
31 */
32 delete(moduleId: string): false | System.UpdateModuleFn;
33
34 /**
35 * Get a module from the SystemJS module registry. Note that the moduleId almost always must be a full url
36 * and that you might need to call System.resolve() to obtain the moduleId. If the module does not exist in
37 * the registry, null is returned.
38 */
39 get(moduleId: string): System.Module | null;
40 // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
41 get<T>(moduleId: string): T | null;
42
43 /**
44 * Indicates whether the SystemJS module registry contains a module. Note that the moduleId almost always
45 * must be a full url and that you might need to call System.resolve() to obtain the moduleId.
46 */
47 has(moduleId: string): boolean;
48
49 /**
50 * An alternative to System.register(), this allows you to insert a module into the module registry. Note that
51 * the moduleId you provide will go straight into the registry without being resolved first.
52 */
53 set(moduleId: string, module: System.Module): void;
54
55 /**
56 * Use for (let entry of System.entries()) to access all of the modules in the SystemJS registry.
57 */
58 entries(): Iterable<[string, System.Module]>;
59
60 /**
61 * Dynamically extend additional mappings into the import map at any time.
62 * Any existing map entries will be overridden with the new values.
63 */
64 addImportMap(importMap: System.ImportMap): void;
65
66 /**
67 * Gets combined import map.
68 */
69 getImportMap(): System.ImportMap;
70};
71
72declare namespace System {
73 // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
74 type ImportFn = <T extends Module>(moduleId: string, parentUrl?: string) => Promise<T>;
75
76 type DeclareFn = (_export: ExportFn, _context: Context) => Declare;
77 interface Declare {
78 setters?: SetterFn[] | undefined;
79 execute?(): any;
80 }
81 type SetterFn = (moduleValue: Module) => any;
82 type ExecuteFn = () => any;
83
84 interface ExportFn {
85 (exportName: string, value: any): void;
86 (exports: object): void;
87 }
88
89 type UpdateModuleFn = () => void;
90
91 type GetFn = GetFnModule | GetFnGeneric;
92 type GetFnModule = (moduleId: string) => Module;
93 // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
94 type GetFnGeneric = <T>(moduleId: string) => T;
95
96 interface Context {
97 import: ImportFn;
98 meta: {
99 url: string;
100 };
101 }
102
103 interface Module {
104 default?: any;
105 [exportName: string]: any;
106 }
107
108 /** The importmap standard is defined here: https://github.com/WICG/import-maps */
109 interface ImportMap {
110 imports?: Record<string, string>;
111 scopes?: Record<string, Record<string, string>>;
112 integrity?: Record<string, string>;
113 }
114}