im_wower
·
2026-03-28
node-shims.d.ts
1declare function setTimeout(callback: () => void, delay?: number): unknown;
2declare function clearTimeout(handle: unknown): void;
3
4declare class Buffer extends Uint8Array {
5 static from(value: string, encoding?: string): Buffer;
6 toString(encoding?: string): string;
7}
8
9declare const process: {
10 argv: string[];
11 cwd(): string;
12 env: Record<string, string | undefined>;
13 execPath: string;
14 exitCode?: number;
15 off?(event: string, listener: () => void): unknown;
16 on?(event: string, listener: () => void): unknown;
17 pid?: number;
18};
19
20declare module "node:child_process" {
21 export interface SpawnOptions {
22 cwd?: string;
23 env?: Record<string, string | undefined>;
24 stdio?: readonly string[] | string;
25 }
26
27 export interface WritableStreamLike {
28 end(chunk?: string | Uint8Array): unknown;
29 write(chunk: string | Uint8Array): boolean;
30 }
31
32 export interface ReadableStreamLike {
33 on(event: "data", listener: (chunk: string | Uint8Array) => void): this;
34 on(event: "end", listener: () => void): this;
35 on(event: "error", listener: (error: Error) => void): this;
36 setEncoding?(encoding: string): this;
37 }
38
39 export interface ChildProcess {
40 pid?: number;
41 stdin?: WritableStreamLike;
42 stderr?: ReadableStreamLike;
43 stdout?: ReadableStreamLike;
44 kill(signal?: string): boolean;
45 on(event: "error", listener: (error: Error) => void): this;
46 on(event: "exit", listener: (code: number | null, signal: string | null) => void): this;
47 on(event: "spawn", listener: () => void): this;
48 once(event: "error", listener: (error: Error) => void): this;
49 once(event: "exit", listener: (code: number | null, signal: string | null) => void): this;
50 once(event: "spawn", listener: () => void): this;
51 }
52
53 export function spawn(command: string, args?: readonly string[], options?: SpawnOptions): ChildProcess;
54}
55
56declare module "node:crypto" {
57 export function randomUUID(): string;
58}
59
60declare module "node:fs/promises" {
61 export function mkdir(path: string, options?: { recursive?: boolean }): Promise<void>;
62 export function readFile(path: string, encoding: string): Promise<string>;
63 export function writeFile(path: string, data: string, encoding: string): Promise<void>;
64 export function appendFile(path: string, data: string, encoding: string): Promise<void>;
65}
66
67declare module "node:path" {
68 export function join(...paths: string[]): string;
69 export function resolve(...paths: string[]): string;
70}
71
72declare module "node:net" {
73 export interface AddressInfo {
74 address: string;
75 family: string;
76 port: number;
77 }
78}
79
80declare module "node:http" {
81 import type { AddressInfo } from "node:net";
82
83 export interface IncomingMessage {
84 headers: Record<string, string | string[] | undefined>;
85 method?: string;
86 on?(event: "data", listener: (chunk: string | Uint8Array) => void): this;
87 on?(event: "end", listener: () => void): this;
88 on?(event: "error", listener: (error: Error) => void): this;
89 setEncoding?(encoding: string): void;
90 url?: string;
91 }
92
93 export interface ServerResponse<Request extends IncomingMessage = IncomingMessage> {
94 end(chunk?: string): void;
95 setHeader(name: string, value: string): this;
96 statusCode: number;
97 write(chunk: string): boolean;
98 flushHeaders(): void;
99 }
100
101 export interface Server {
102 address(): AddressInfo | string | null;
103 close(callback?: (error?: Error) => void): this;
104 closeAllConnections?(): void;
105 listen(options: { host: string; port: number }): this;
106 off(event: "error", listener: (error: Error) => void): this;
107 off(event: "listening", listener: () => void): this;
108 once(event: "error", listener: (error: Error) => void): this;
109 once(event: "listening", listener: () => void): this;
110 }
111
112 export function createServer(
113 handler: (request: IncomingMessage, response: ServerResponse<IncomingMessage>) => void
114 ): Server;
115}