UNPKG

9.25 kBTypeScriptView Raw
1// Declare "static" methods in Error
2interface ErrorConstructor {
3 /** Create .stack property on a target object */
4 captureStackTrace(targetObject: object, constructorOpt?: Function): void;
5
6 /**
7 * Optional override for formatting stack traces
8 *
9 * @see https://v8.dev/docs/stack-trace-api#customizing-stack-traces
10 */
11 prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
12
13 stackTraceLimit: number;
14}
15
16/*-----------------------------------------------*
17 * *
18 * GLOBAL *
19 * *
20 ------------------------------------------------*/
21
22// For backwards compability
23interface NodeRequire extends NodeJS.Require { }
24interface RequireResolve extends NodeJS.RequireResolve { }
25interface NodeModule extends NodeJS.Module { }
26
27declare var process: NodeJS.Process;
28declare var console: Console;
29
30declare var __filename: string;
31declare var __dirname: string;
32
33declare var require: NodeRequire;
34declare var module: NodeModule;
35
36// Same as module.exports
37declare var exports: any;
38
39/**
40 * Only available if `--expose-gc` is passed to the process.
41 */
42declare var gc: undefined | (() => void);
43
44//#region borrowed
45// from https://github.com/microsoft/TypeScript/blob/38da7c600c83e7b31193a62495239a0fe478cb67/lib/lib.webworker.d.ts#L633 until moved to separate lib
46/** A controller object that allows you to abort one or more DOM requests as and when desired. */
47interface AbortController {
48 /**
49 * Returns the AbortSignal object associated with this object.
50 */
51
52 readonly signal: AbortSignal;
53 /**
54 * Invoking this method will set this object's AbortSignal's aborted flag and signal to any observers that the associated activity is to be aborted.
55 */
56 abort(): void;
57}
58
59/** A signal object that allows you to communicate with a DOM request (such as a Fetch) and abort it if required via an AbortController object. */
60interface AbortSignal {
61 /**
62 * Returns true if this AbortSignal's AbortController has signaled to abort, and false otherwise.
63 */
64 readonly aborted: boolean;
65}
66
67declare var AbortController: {
68 prototype: AbortController;
69 new(): AbortController;
70};
71
72declare var AbortSignal: {
73 prototype: AbortSignal;
74 new(): AbortSignal;
75 // TODO: Add abort() static
76};
77//#endregion borrowed
78
79//#region ArrayLike.at()
80interface RelativeIndexable<T> {
81 /**
82 * Takes an integer value and returns the item at that index,
83 * allowing for positive and negative integers.
84 * Negative integers count back from the last item in the array.
85 */
86 at(index: number): T | undefined;
87}
88interface String extends RelativeIndexable<string> {}
89interface Array<T> extends RelativeIndexable<T> {}
90interface Int8Array extends RelativeIndexable<number> {}
91interface Uint8Array extends RelativeIndexable<number> {}
92interface Uint8ClampedArray extends RelativeIndexable<number> {}
93interface Int16Array extends RelativeIndexable<number> {}
94interface Uint16Array extends RelativeIndexable<number> {}
95interface Int32Array extends RelativeIndexable<number> {}
96interface Uint32Array extends RelativeIndexable<number> {}
97interface Float32Array extends RelativeIndexable<number> {}
98interface Float64Array extends RelativeIndexable<number> {}
99interface BigInt64Array extends RelativeIndexable<bigint> {}
100interface BigUint64Array extends RelativeIndexable<bigint> {}
101//#endregion ArrayLike.at() end
102
103/**
104 * @since v17.0.0
105 *
106 * Creates a deep clone of an object.
107 */
108declare function structuredClone<T>(
109 value: T,
110 transfer?: { transfer: ReadonlyArray<import('worker_threads').TransferListItem> },
111): T;
112
113/*----------------------------------------------*
114* *
115* GLOBAL INTERFACES *
116* *
117*-----------------------------------------------*/
118declare namespace NodeJS {
119 interface CallSite {
120 /**
121 * Value of "this"
122 */
123 getThis(): unknown;
124
125 /**
126 * Type of "this" as a string.
127 * This is the name of the function stored in the constructor field of
128 * "this", if available. Otherwise the object's [[Class]] internal
129 * property.
130 */
131 getTypeName(): string | null;
132
133 /**
134 * Current function
135 */
136 getFunction(): Function | undefined;
137
138 /**
139 * Name of the current function, typically its name property.
140 * If a name property is not available an attempt will be made to try
141 * to infer a name from the function's context.
142 */
143 getFunctionName(): string | null;
144
145 /**
146 * Name of the property [of "this" or one of its prototypes] that holds
147 * the current function
148 */
149 getMethodName(): string | null;
150
151 /**
152 * Name of the script [if this function was defined in a script]
153 */
154 getFileName(): string | null;
155
156 /**
157 * Current line number [if this function was defined in a script]
158 */
159 getLineNumber(): number | null;
160
161 /**
162 * Current column number [if this function was defined in a script]
163 */
164 getColumnNumber(): number | null;
165
166 /**
167 * A call site object representing the location where eval was called
168 * [if this function was created using a call to eval]
169 */
170 getEvalOrigin(): string | undefined;
171
172 /**
173 * Is this a toplevel invocation, that is, is "this" the global object?
174 */
175 isToplevel(): boolean;
176
177 /**
178 * Does this call take place in code defined by a call to eval?
179 */
180 isEval(): boolean;
181
182 /**
183 * Is this call in native V8 code?
184 */
185 isNative(): boolean;
186
187 /**
188 * Is this a constructor call?
189 */
190 isConstructor(): boolean;
191 }
192
193 interface ErrnoException extends Error {
194 errno?: number | undefined;
195 code?: string | undefined;
196 path?: string | undefined;
197 syscall?: string | undefined;
198 }
199
200 interface ReadableStream extends EventEmitter {
201 readable: boolean;
202 read(size?: number): string | Buffer;
203 setEncoding(encoding: BufferEncoding): this;
204 pause(): this;
205 resume(): this;
206 isPaused(): boolean;
207 pipe<T extends WritableStream>(destination: T, options?: { end?: boolean | undefined; }): T;
208 unpipe(destination?: WritableStream): this;
209 unshift(chunk: string | Uint8Array, encoding?: BufferEncoding): void;
210 wrap(oldStream: ReadableStream): this;
211 [Symbol.asyncIterator](): AsyncIterableIterator<string | Buffer>;
212 }
213
214 interface WritableStream extends EventEmitter {
215 writable: boolean;
216 write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean;
217 write(str: string, encoding?: BufferEncoding, cb?: (err?: Error | null) => void): boolean;
218 end(cb?: () => void): this;
219 end(data: string | Uint8Array, cb?: () => void): this;
220 end(str: string, encoding?: BufferEncoding, cb?: () => void): this;
221 }
222
223 interface ReadWriteStream extends ReadableStream, WritableStream { }
224
225 interface RefCounted {
226 ref(): this;
227 unref(): this;
228 }
229
230 type TypedArray =
231 | Uint8Array
232 | Uint8ClampedArray
233 | Uint16Array
234 | Uint32Array
235 | Int8Array
236 | Int16Array
237 | Int32Array
238 | BigUint64Array
239 | BigInt64Array
240 | Float32Array
241 | Float64Array;
242 type ArrayBufferView = TypedArray | DataView;
243
244 interface Require {
245 (id: string): any;
246 resolve: RequireResolve;
247 cache: Dict<NodeModule>;
248 /**
249 * @deprecated
250 */
251 extensions: RequireExtensions;
252 main: Module | undefined;
253 }
254
255 interface RequireResolve {
256 (id: string, options?: { paths?: string[] | undefined; }): string;
257 paths(request: string): string[] | null;
258 }
259
260 interface RequireExtensions extends Dict<(m: Module, filename: string) => any> {
261 '.js': (m: Module, filename: string) => any;
262 '.json': (m: Module, filename: string) => any;
263 '.node': (m: Module, filename: string) => any;
264 }
265 interface Module {
266 /**
267 * `true` if the module is running during the Node.js preload
268 */
269 isPreloading: boolean;
270 exports: any;
271 require: Require;
272 id: string;
273 filename: string;
274 loaded: boolean;
275 /** @deprecated since v14.6.0 Please use `require.main` and `module.children` instead. */
276 parent: Module | null | undefined;
277 children: Module[];
278 /**
279 * @since v11.14.0
280 *
281 * The directory name of the module. This is usually the same as the path.dirname() of the module.id.
282 */
283 path: string;
284 paths: string[];
285 }
286
287 interface Dict<T> {
288 [key: string]: T | undefined;
289 }
290
291 interface ReadOnlyDict<T> {
292 readonly [key: string]: T | undefined;
293 }
294}