Skip to content

Commit efd6815

Browse files
anonrigruyadorno
authored andcommitted
lib: fix internalBinding typings
PR-URL: #49742 Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Zeyu "Alex" Yang <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
1 parent 3db9b40 commit efd6815

20 files changed

+88
-61
lines changed

lib/internal/bootstrap/realm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ const experimentalModuleList = new SafeSet();
174174
};
175175
}
176176

177-
// Set up internalBinding() in the closure.
178177
/**
179-
* @type {InternalBinding}
178+
* Set up internalBinding() in the closure.
179+
* @type {import('typings/globals').internalBinding}
180180
*/
181181
let internalBinding;
182182
{

tsconfig.json

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,14 @@
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",
215
"./typings/globals.d.ts",
226
"./typings/primordials.d.ts"
237
],
248
"compilerOptions": {
259
"allowJs": true,
2610
"checkJs": false,
2711
"noEmit": true,
28-
"lib": ["ESNext"],
12+
"lib": ["ESNext", "DOM"],
2913
"target": "ESNext",
3014
"module": "CommonJS",
3115
"baseUrl": ".",

typings/globals.d.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
import {AsyncWrapBinding} from "./internalBinding/async_wrap";
2+
import {BlobBinding} from "./internalBinding/blob";
3+
import {ConfigBinding} from "./internalBinding/config";
4+
import {ConstantsBinding} from "./internalBinding/constants";
5+
import {HttpParserBinding} from "./internalBinding/http_parser";
6+
import {FsBinding} from "./internalBinding/fs";
7+
import {MessagingBinding} from "./internalBinding/messaging";
8+
import {OptionsBinding} from "./internalBinding/options";
9+
import {OSBinding} from "./internalBinding/os";
10+
import {SerdesBinding} from "./internalBinding/serdes";
11+
import {SymbolsBinding} from "./internalBinding/symbols";
12+
import {TimersBinding} from "./internalBinding/timers";
13+
import {TypesBinding} from "./internalBinding/types";
14+
import {URLBinding} from "./internalBinding/url";
15+
import {UtilBinding} from "./internalBinding/util";
16+
import {WorkerBinding} from "./internalBinding/worker";
17+
118
declare type TypedArray =
219
| Uint8Array
320
| Uint8ClampedArray
@@ -10,3 +27,34 @@ declare type TypedArray =
1027
| Float64Array
1128
| BigUint64Array
1229
| BigInt64Array;
30+
31+
interface InternalBindingMap {
32+
async_wrap: AsyncWrapBinding;
33+
blob: BlobBinding;
34+
config: ConfigBinding;
35+
constants: ConstantsBinding;
36+
fs: FsBinding;
37+
http_parser: HttpParserBinding;
38+
messaging: MessagingBinding;
39+
options: OptionsBinding;
40+
os: OSBinding;
41+
serdes: SerdesBinding;
42+
symbols: SymbolsBinding;
43+
timers: TimersBinding;
44+
types: TypesBinding;
45+
url: URLBinding;
46+
util: UtilBinding;
47+
worker: WorkerBinding;
48+
}
49+
50+
type InternalBindingKeys = keyof InternalBindingMap;
51+
52+
declare function internalBinding<T extends InternalBindingKeys>(binding: T): InternalBindingMap[T]
53+
54+
declare global {
55+
namespace NodeJS {
56+
interface Global {
57+
internalBinding<T extends InternalBindingKeys>(binding: T): InternalBindingMap[T]
58+
}
59+
}
60+
}

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 interface 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ declare namespace InternalBlobBinding {
1010
}
1111
}
1212

13-
declare function InternalBinding(binding: 'blob'): {
13+
export interface 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;
1717
storeDataObject(id: string, handle: InternalBlobBinding.BlobHandle, size: number, type: string): void;
1818
revokeDataObject(id: string): void;
19-
};
19+
}

typings/internalBinding/config.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare function InternalBinding(binding: 'config'): {
1+
export interface ConfigBinding {
22
isDebugBuild: boolean;
33
hasOpenSSL: boolean;
44
fipsMode: boolean;
@@ -9,4 +9,4 @@ declare function InternalBinding(binding: 'config'): {
99
noBrowserGlobals: boolean;
1010
bits: number;
1111
hasDtrace: boolean;
12-
};
12+
}

typings/internalBinding/constants.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare function InternalBinding(binding: 'constants'): {
1+
export interface ConstantsBinding {
22
os: {
33
UV_UDP_REUSEADDR: 4;
44
dlopen: {
@@ -382,4 +382,4 @@ declare function InternalBinding(binding: 'constants'): {
382382
TRACE_EVENT_PHASE_LEAVE_CONTEXT: 41;
383383
TRACE_EVENT_PHASE_LINK_IDS: 61;
384384
};
385-
};
385+
}

typings/internalBinding/fs.d.ts

Lines changed: 4 additions & 4 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 interface FsBinding {
224224
FSReqCallback: typeof InternalFSBinding.FSReqCallback;
225225

226226
FileHandle: typeof InternalFSBinding.FileHandle;
@@ -269,4 +269,4 @@ declare function InternalBinding(binding: 'fs'): {
269269
writeBuffer: typeof InternalFSBinding.writeBuffer;
270270
writeBuffers: typeof InternalFSBinding.writeBuffers;
271271
writeString: typeof InternalFSBinding.writeString;
272-
};
272+
}

typings/internalBinding/http_parser.d.ts

Lines changed: 2 additions & 2 deletions
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 interface HttpParserBinding {
4343
methods: string[];
4444
HTTPParser: typeof InternalHttpParserBinding.HTTPParser;
45-
};
45+
}

typings/internalBinding/messaging.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ declare namespace InternalMessagingBinding {
1717
}
1818

1919

20-
declare function InternalBinding(binding: 'messaging'): {
20+
export interface MessagingBinding {
2121
DOMException: typeof import('internal/per_context/domexception').DOMException;
2222
MessageChannel: typeof InternalMessagingBinding.MessageChannel;
2323
MessagePort: typeof InternalMessagingBinding.MessagePort;
@@ -29,4 +29,4 @@ declare function InternalBinding(binding: 'messaging'): {
2929
moveMessagePortToContext(port: typeof InternalMessagingBinding.MessagePort, context: any): typeof InternalMessagingBinding.MessagePort;
3030
setDeserializerCreateObjectFunction(func: (deserializeInfo: string) => any): void;
3131
broadcastChannel(name: string): typeof InternalMessagingBinding.MessagePort;
32-
};
32+
}

0 commit comments

Comments
 (0)