globals.d.ts (8761B)
1 // Declare "static" methods in Error 2 interface 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 23 interface NodeRequire extends NodeJS.Require {} 24 interface RequireResolve extends NodeJS.RequireResolve {} 25 interface NodeModule extends NodeJS.Module {} 26 27 declare var process: NodeJS.Process; 28 declare var console: Console; 29 30 declare var global: typeof globalThis; 31 32 declare var __filename: string; 33 declare var __dirname: string; 34 35 declare var require: NodeRequire; 36 declare var module: NodeModule; 37 38 // Same as module.exports 39 declare var exports: any; 40 41 /** 42 * Only available if `--expose-gc` is passed to the process. 43 */ 44 declare var gc: undefined | (() => void); 45 46 // #region borrowed 47 // from https://github.com/microsoft/TypeScript/blob/38da7c600c83e7b31193a62495239a0fe478cb67/lib/lib.webworker.d.ts#L633 until moved to separate lib 48 /** A controller object that allows you to abort one or more DOM requests as and when desired. */ 49 interface AbortController { 50 /** 51 * Returns the AbortSignal object associated with this object. 52 */ 53 54 readonly signal: AbortSignal; 55 /** 56 * 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. 57 */ 58 abort(reason?: any): void; 59 } 60 61 /** 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. */ 62 interface AbortSignal extends EventTarget { 63 /** 64 * Returns true if this AbortSignal's AbortController has signaled to abort, and false otherwise. 65 */ 66 readonly aborted: boolean; 67 readonly reason: any; 68 onabort: null | ((this: AbortSignal, event: Event) => any); 69 throwIfAborted(): void; 70 } 71 72 declare var AbortController: typeof globalThis extends { onmessage: any; AbortController: infer T } ? T 73 : { 74 prototype: AbortController; 75 new(): AbortController; 76 }; 77 78 declare var AbortSignal: typeof globalThis extends { onmessage: any; AbortSignal: infer T } ? T 79 : { 80 prototype: AbortSignal; 81 new(): AbortSignal; 82 abort(reason?: any): AbortSignal; 83 timeout(milliseconds: number): AbortSignal; 84 }; 85 // #endregion borrowed 86 87 /*----------------------------------------------* 88 * * 89 * GLOBAL INTERFACES * 90 * * 91 *-----------------------------------------------*/ 92 declare namespace NodeJS { 93 interface CallSite { 94 /** 95 * Value of "this" 96 */ 97 getThis(): unknown; 98 99 /** 100 * Type of "this" as a string. 101 * This is the name of the function stored in the constructor field of 102 * "this", if available. Otherwise the object's [[Class]] internal 103 * property. 104 */ 105 getTypeName(): string | null; 106 107 /** 108 * Current function 109 */ 110 getFunction(): Function | undefined; 111 112 /** 113 * Name of the current function, typically its name property. 114 * If a name property is not available an attempt will be made to try 115 * to infer a name from the function's context. 116 */ 117 getFunctionName(): string | null; 118 119 /** 120 * Name of the property [of "this" or one of its prototypes] that holds 121 * the current function 122 */ 123 getMethodName(): string | null; 124 125 /** 126 * Name of the script [if this function was defined in a script] 127 */ 128 getFileName(): string | undefined; 129 130 /** 131 * Current line number [if this function was defined in a script] 132 */ 133 getLineNumber(): number | null; 134 135 /** 136 * Current column number [if this function was defined in a script] 137 */ 138 getColumnNumber(): number | null; 139 140 /** 141 * A call site object representing the location where eval was called 142 * [if this function was created using a call to eval] 143 */ 144 getEvalOrigin(): string | undefined; 145 146 /** 147 * Is this a toplevel invocation, that is, is "this" the global object? 148 */ 149 isToplevel(): boolean; 150 151 /** 152 * Does this call take place in code defined by a call to eval? 153 */ 154 isEval(): boolean; 155 156 /** 157 * Is this call in native V8 code? 158 */ 159 isNative(): boolean; 160 161 /** 162 * Is this a constructor call? 163 */ 164 isConstructor(): boolean; 165 } 166 167 interface ErrnoException extends Error { 168 errno?: number | undefined; 169 code?: string | undefined; 170 path?: string | undefined; 171 syscall?: string | undefined; 172 } 173 174 interface ReadableStream extends EventEmitter { 175 readable: boolean; 176 read(size?: number): string | Buffer; 177 setEncoding(encoding: BufferEncoding): this; 178 pause(): this; 179 resume(): this; 180 isPaused(): boolean; 181 pipe<T extends WritableStream>(destination: T, options?: { end?: boolean | undefined }): T; 182 unpipe(destination?: WritableStream): this; 183 unshift(chunk: string | Uint8Array, encoding?: BufferEncoding): void; 184 wrap(oldStream: ReadableStream): this; 185 [Symbol.asyncIterator](): NodeJS.AsyncIterator<string | Buffer>; 186 } 187 188 interface WritableStream extends EventEmitter { 189 writable: boolean; 190 write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean; 191 write(str: string, encoding?: BufferEncoding, cb?: (err?: Error | null) => void): boolean; 192 end(cb?: () => void): void; 193 end(data: string | Uint8Array, cb?: () => void): void; 194 end(str: string, encoding?: BufferEncoding, cb?: () => void): void; 195 } 196 197 interface ReadWriteStream extends ReadableStream, WritableStream {} 198 199 interface RefCounted { 200 ref(): this; 201 unref(): this; 202 } 203 204 interface Require { 205 (id: string): any; 206 resolve: RequireResolve; 207 cache: Dict<NodeModule>; 208 /** 209 * @deprecated 210 */ 211 extensions: RequireExtensions; 212 main: Module | undefined; 213 } 214 215 interface RequireResolve { 216 (id: string, options?: { paths?: string[] | undefined }): string; 217 paths(request: string): string[] | null; 218 } 219 220 interface RequireExtensions extends Dict<(m: Module, filename: string) => any> { 221 ".js": (m: Module, filename: string) => any; 222 ".json": (m: Module, filename: string) => any; 223 ".node": (m: Module, filename: string) => any; 224 } 225 interface Module { 226 /** 227 * `true` if the module is running during the Node.js preload 228 */ 229 isPreloading: boolean; 230 exports: any; 231 require: Require; 232 id: string; 233 filename: string; 234 loaded: boolean; 235 /** @deprecated since v14.6.0 Please use `require.main` and `module.children` instead. */ 236 parent: Module | null | undefined; 237 children: Module[]; 238 /** 239 * @since v11.14.0 240 * 241 * The directory name of the module. This is usually the same as the path.dirname() of the module.id. 242 */ 243 path: string; 244 paths: string[]; 245 } 246 247 interface Dict<T> { 248 [key: string]: T | undefined; 249 } 250 251 interface ReadOnlyDict<T> { 252 readonly [key: string]: T | undefined; 253 } 254 255 /** An iterable iterator returned by the Node.js API. */ 256 // Default TReturn/TNext in v16 is `any`, for compatibility with the previously-used IterableIterator. 257 interface Iterator<T, TReturn = any, TNext = any> extends IteratorObject<T, TReturn, TNext> { 258 [Symbol.iterator](): NodeJS.Iterator<T, TReturn, TNext>; 259 } 260 261 /** An async iterable iterator returned by the Node.js API. */ 262 // Default TReturn/TNext in v16 is `any`, for compatibility with the previously-used AsyncIterableIterator. 263 interface AsyncIterator<T, TReturn = any, TNext = any> extends AsyncIteratorObject<T, TReturn, TNext> { 264 [Symbol.asyncIterator](): NodeJS.AsyncIterator<T, TReturn, TNext>; 265 } 266 }