Skip to content

Commit e250782

Browse files
authored
Fix / improve loader type definitions (#1175)
1 parent 13340ed commit e250782

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

lib/loader/index.d.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
/// <reference lib="esnext.bigint" />
22

3-
interface ResultObject {
4-
module: WebAssembly.Module,
5-
instance: WebAssembly.Instance
6-
};
3+
export interface ResultObject {
4+
module: WebAssembly.Module;
5+
instance: WebAssembly.Instance;
6+
}
7+
8+
type ImportValue = Function | WebAssembly.Global | WebAssembly.Memory | WebAssembly.Table | number;
79

810
/** WebAssembly imports with two levels of nesting. */
9-
interface ImportsObject extends Record<string, any> {
11+
export interface Imports extends Record<string, Record<string, ImportValue>> {
1012
env?: {
1113
memory?: WebAssembly.Memory,
1214
table?: WebAssembly.Table,
15+
seed?: () => number,
1316
abort?(msg: number, file: number, line: number, column: number): void,
1417
trace?(msg: number, numArgs?: number, ...args: number[]): void
1518
};
1619
}
1720

1821
/** Utility mixed in by the loader. */
19-
interface ASUtil {
22+
export interface ASUtil {
2023
memory?: WebAssembly.Memory;
2124
table?: WebAssembly.Table;
2225

@@ -99,19 +102,19 @@ interface ASUtil {
99102
/** Asynchronously instantiates an AssemblyScript module from anything that can be instantiated. */
100103
export declare function instantiate<T extends {}>(
101104
source: WebAssembly.Module | BufferSource | Response | PromiseLike<WebAssembly.Module | BufferSource | Response>,
102-
imports?: ImportsObject
105+
imports?: Imports
103106
): Promise<ResultObject & { exports: ASUtil & T }>;
104107

105108
/** Synchronously instantiates an AssemblyScript module from a WebAssembly.Module or binary buffer. */
106109
export declare function instantiateSync<T extends {}>(
107110
source: WebAssembly.Module | BufferSource,
108-
imports?: ImportsObject
111+
imports?: Imports
109112
): ResultObject & { exports: ASUtil & T };
110113

111114
/** Asynchronously instantiates an AssemblyScript module from a response, i.e. as obtained by `fetch`. */
112115
export declare function instantiateStreaming<T extends {}>(
113116
source: Response | PromiseLike<Response>,
114-
imports?: ImportsObject
117+
imports?: Imports
115118
): Promise<ResultObject & { exports: ASUtil & T }>;
116119

117120
/** Demangles an AssemblyScript module's exports to a friendly object structure. */

0 commit comments

Comments
 (0)