Skip to content

Commit 2ebdf07

Browse files
committed
lib: fix internalBinding type definitions
1 parent 0e79635 commit 2ebdf07

File tree

20 files changed

+67
-37
lines changed

20 files changed

+67
-37
lines changed

lib/internal/bootstrap/realm.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ const experimentalModuleList = new SafeSet();
170170
};
171171
}
172172

173-
// Set up internalBinding() in the closure.
174173
/**
174+
* Set up internalBinding() in the closure.
175175
* @type {InternalBinding}
176176
*/
177177
let internalBinding;
@@ -439,3 +439,4 @@ setInternalLoaders(internalBinding, requireBuiltin);
439439

440440
// Setup per-realm bindings.
441441
setupPrepareStackTrace();
442+
setInternalLoaders(internalBinding, requireBuiltin);

tsconfig.json

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,8 @@
22
"include": ["lib", "doc"],
33
"exclude": ["src", "tools", "out"],
44
"files": [
5-
"./typings/internalBinding/async_wrap.d.ts",
6-
"./typings/internalBinding/blob.d.ts",
7-
"./typings/internalBinding/config.d.ts",
8-
"./typings/internalBinding/constants.d.ts",
9-
"./typings/internalBinding/fs.d.ts",
10-
"./typings/internalBinding/http_parser.d.ts",
11-
"./typings/internalBinding/messaging.d.ts",
12-
"./typings/internalBinding/options.d.ts",
13-
"./typings/internalBinding/os.d.ts",
14-
"./typings/internalBinding/serdes.d.ts",
15-
"./typings/internalBinding/symbols.d.ts",
16-
"./typings/internalBinding/timers.d.ts",
17-
"./typings/internalBinding/types.d.ts",
18-
"./typings/internalBinding/url.d.ts",
19-
"./typings/internalBinding/util.d.ts",
20-
"./typings/internalBinding/worker.d.ts",
5+
"./typings/internalBinding/*.d.ts",
6+
"./typings/bindings.d.ts",
217
"./typings/globals.d.ts",
228
"./typings/primordials.d.ts"
239
],

typings/bindings.d.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { AsyncWrapBinding } from './internalBinding/async_wrap';
2+
import type { BlobBinding } from "./internalBinding/blob";
3+
import type { ConfigBinding } from "./internalBinding/config";
4+
import type { ConstantsBinding } from "./internalBinding/constants";
5+
import type { FSBinding } from "./internalBinding/fs";
6+
import type { HttpParserBinding } from "./internalBinding/http_parser";
7+
import type { MessagingBinding } from "./internalBinding/messaging";
8+
import type { OptionsBinding } from "./internalBinding/options";
9+
import type { OSBinding } from "./internalBinding/os";
10+
import type { SerdesBinding } from "./internalBinding/serdes";
11+
import type { SymbolsBinding } from "./internalBinding/symbols";
12+
import type { TimersBinding } from "./internalBinding/timers";
13+
import type { TypesBinding } from "./internalBinding/types";
14+
import type { URLBinding } from "./internalBinding/url";
15+
import type { UtilBindings } from "./internalBinding/util";
16+
import type { WorkerBinding } from "./internalBinding/worker";
17+
18+
export type InternalBindingMap = {
19+
async_wrap: AsyncWrapBinding;
20+
blob: BlobBinding;
21+
config: ConfigBinding;
22+
constants: ConstantsBinding;
23+
fs: FSBinding;
24+
http_parser: HttpParserBinding;
25+
messaging: MessagingBinding;
26+
options: OptionsBinding;
27+
os: OSBinding;
28+
serdes: SerdesBinding;
29+
symbols: SymbolsBinding;
30+
timers: TimersBinding;
31+
types: TypesBinding;
32+
url: URLBinding;
33+
util: UtilBindings;
34+
worker: WorkerBinding;
35+
}
36+
37+
export type InternalBinding<T extends keyof InternalBindingMap> = (binding: T) => InternalBindingMap[T];

typings/internalBinding/async_wrap.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ declare namespace InternalAsyncWrapBinding {
7272
}
7373
}
7474

75-
declare function InternalBinding(binding: 'async_wrap'): {
75+
export type AsyncWrapBinding = {
7676
setupHooks(): {
7777
init: (
7878
asyncId: number,
@@ -129,4 +129,4 @@ declare function InternalBinding(binding: 'async_wrap'): {
129129
kDefaultTriggerAsyncId: 3;
130130
};
131131
Providers: InternalAsyncWrapBinding.Providers;
132-
};
132+
}

typings/internalBinding/blob.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare namespace InternalBlobBinding {
1010
}
1111
}
1212

13-
declare function InternalBinding(binding: 'blob'): {
13+
export type BlobBinding = {
1414
createBlob(sources: Array<Uint8Array | InternalBlobBinding.BlobHandle>, length: number): InternalBlobBinding.BlobHandle;
1515
FixedSizeBlobCopyJob: typeof InternalBlobBinding.FixedSizeBlobCopyJob;
1616
getDataObject(id: string): [handle: InternalBlobBinding.BlobHandle | undefined, length: number, type: string] | undefined;

typings/internalBinding/config.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare function InternalBinding(binding: 'config'): {
1+
export type ConfigBinding = {
22
isDebugBuild: boolean;
33
hasOpenSSL: boolean;
44
fipsMode: boolean;

typings/internalBinding/constants.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare function InternalBinding(binding: 'constants'): {
1+
export type ConstantsBinding = {
22
os: {
33
UV_UDP_REUSEADDR: 4;
44
dlopen: {

typings/internalBinding/fs.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ declare namespace InternalFSBinding {
109109

110110
function internalModuleReadJSON(path: string): [] | [string, boolean];
111111
function internalModuleStat(path: string): number;
112-
112+
113113
function lchown(path: string, uid: number, gid: number, req: FSReqCallback): void;
114114
function lchown(path: string, uid: number, gid: number, req: undefined, ctx: FSSyncContext): void;
115115
function lchown(path: string, uid: number, gid: number, usePromises: typeof kUsePromises): Promise<void>;
@@ -198,7 +198,7 @@ declare namespace InternalFSBinding {
198198
function symlink(target: StringOrBuffer, path: StringOrBuffer, type: number, req: FSReqCallback): void;
199199
function symlink(target: StringOrBuffer, path: StringOrBuffer, type: number, req: undefined, ctx: FSSyncContext): void;
200200
function symlink(target: StringOrBuffer, path: StringOrBuffer, type: number, usePromises: typeof kUsePromises): Promise<void>;
201-
201+
202202
function unlink(path: string, req: FSReqCallback): void;
203203
function unlink(path: string, req: undefined, ctx: FSSyncContext): void;
204204
function unlink(path: string, usePromises: typeof kUsePromises): Promise<void>;
@@ -220,7 +220,7 @@ declare namespace InternalFSBinding {
220220
function writeString(fd: number, value: string, pos: unknown, encoding: unknown, usePromises: typeof kUsePromises): Promise<number>;
221221
}
222222

223-
declare function InternalBinding(binding: 'fs'): {
223+
export type FSBinding = {
224224
FSReqCallback: typeof InternalFSBinding.FSReqCallback;
225225

226226
FileHandle: typeof InternalFSBinding.FileHandle;

typings/internalBinding/http_parser.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ declare namespace InternalHttpParserBinding {
3939
}
4040
}
4141

42-
declare function InternalBinding(binding: 'http_parser'): {
42+
export type HttpParserBinding = {
4343
methods: string[];
4444
HTTPParser: typeof InternalHttpParserBinding.HTTPParser;
4545
};

typings/internalBinding/messaging.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { DOMException } from 'internal/per_context/domexception';
2+
13
declare namespace InternalMessagingBinding {
24
class MessageChannel {
35
port1: MessagePort;
@@ -17,8 +19,8 @@ declare namespace InternalMessagingBinding {
1719
}
1820

1921

20-
declare function InternalBinding(binding: 'messaging'): {
21-
DOMException: typeof import('internal/per_context/domexception').DOMException;
22+
export type MessagingBinding = {
23+
DOMException: typeof DOMException;
2224
MessageChannel: typeof InternalMessagingBinding.MessageChannel;
2325
MessagePort: typeof InternalMessagingBinding.MessagePort;
2426
JSTransferable: typeof InternalMessagingBinding.JSTransferable;

0 commit comments

Comments
 (0)