883f22d96e938d650cd0a803ea8279a35af0fca8951e1688bf3199b895b491b66fc51db44299402c2746f02cabcfbf853200ae24c86ac080865db2f9a608d5 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. export {}; // Make this a module
  2. // #region Fetch and friends
  3. // Conditional type aliases, used at the end of this file.
  4. // Will either be empty if lib.dom (or lib.webworker) is included, or the undici version otherwise.
  5. type _Request = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Request;
  6. type _Response = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Response;
  7. type _FormData = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").FormData;
  8. type _Headers = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Headers;
  9. type _MessageEvent = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").MessageEvent;
  10. type _RequestInit = typeof globalThis extends { onmessage: any } ? {}
  11. : import("undici-types").RequestInit;
  12. type _ResponseInit = typeof globalThis extends { onmessage: any } ? {}
  13. : import("undici-types").ResponseInit;
  14. type _WebSocket = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").WebSocket;
  15. type _EventSource = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").EventSource;
  16. // #endregion Fetch and friends
  17. // Conditional type definitions for webstorage interface, which conflicts with lib.dom otherwise.
  18. type _Storage = typeof globalThis extends { onabort: any } ? {} : {
  19. readonly length: number;
  20. clear(): void;
  21. getItem(key: string): string | null;
  22. key(index: number): string | null;
  23. removeItem(key: string): void;
  24. setItem(key: string, value: string): void;
  25. [key: string]: any;
  26. };
  27. // #region DOMException
  28. type _DOMException = typeof globalThis extends { onmessage: any } ? {} : NodeDOMException;
  29. interface NodeDOMException extends Error {
  30. readonly code: number;
  31. readonly message: string;
  32. readonly name: string;
  33. readonly INDEX_SIZE_ERR: 1;
  34. readonly DOMSTRING_SIZE_ERR: 2;
  35. readonly HIERARCHY_REQUEST_ERR: 3;
  36. readonly WRONG_DOCUMENT_ERR: 4;
  37. readonly INVALID_CHARACTER_ERR: 5;
  38. readonly NO_DATA_ALLOWED_ERR: 6;
  39. readonly NO_MODIFICATION_ALLOWED_ERR: 7;
  40. readonly NOT_FOUND_ERR: 8;
  41. readonly NOT_SUPPORTED_ERR: 9;
  42. readonly INUSE_ATTRIBUTE_ERR: 10;
  43. readonly INVALID_STATE_ERR: 11;
  44. readonly SYNTAX_ERR: 12;
  45. readonly INVALID_MODIFICATION_ERR: 13;
  46. readonly NAMESPACE_ERR: 14;
  47. readonly INVALID_ACCESS_ERR: 15;
  48. readonly VALIDATION_ERR: 16;
  49. readonly TYPE_MISMATCH_ERR: 17;
  50. readonly SECURITY_ERR: 18;
  51. readonly NETWORK_ERR: 19;
  52. readonly ABORT_ERR: 20;
  53. readonly URL_MISMATCH_ERR: 21;
  54. readonly QUOTA_EXCEEDED_ERR: 22;
  55. readonly TIMEOUT_ERR: 23;
  56. readonly INVALID_NODE_TYPE_ERR: 24;
  57. readonly DATA_CLONE_ERR: 25;
  58. }
  59. interface NodeDOMExceptionConstructor {
  60. prototype: DOMException;
  61. new(message?: string, nameOrOptions?: string | { name?: string; cause?: unknown }): DOMException;
  62. readonly INDEX_SIZE_ERR: 1;
  63. readonly DOMSTRING_SIZE_ERR: 2;
  64. readonly HIERARCHY_REQUEST_ERR: 3;
  65. readonly WRONG_DOCUMENT_ERR: 4;
  66. readonly INVALID_CHARACTER_ERR: 5;
  67. readonly NO_DATA_ALLOWED_ERR: 6;
  68. readonly NO_MODIFICATION_ALLOWED_ERR: 7;
  69. readonly NOT_FOUND_ERR: 8;
  70. readonly NOT_SUPPORTED_ERR: 9;
  71. readonly INUSE_ATTRIBUTE_ERR: 10;
  72. readonly INVALID_STATE_ERR: 11;
  73. readonly SYNTAX_ERR: 12;
  74. readonly INVALID_MODIFICATION_ERR: 13;
  75. readonly NAMESPACE_ERR: 14;
  76. readonly INVALID_ACCESS_ERR: 15;
  77. readonly VALIDATION_ERR: 16;
  78. readonly TYPE_MISMATCH_ERR: 17;
  79. readonly SECURITY_ERR: 18;
  80. readonly NETWORK_ERR: 19;
  81. readonly ABORT_ERR: 20;
  82. readonly URL_MISMATCH_ERR: 21;
  83. readonly QUOTA_EXCEEDED_ERR: 22;
  84. readonly TIMEOUT_ERR: 23;
  85. readonly INVALID_NODE_TYPE_ERR: 24;
  86. readonly DATA_CLONE_ERR: 25;
  87. }
  88. // #endregion DOMException
  89. declare global {
  90. var global: typeof globalThis;
  91. var process: NodeJS.Process;
  92. var console: Console;
  93. interface ErrorConstructor {
  94. /**
  95. * Creates a `.stack` property on `targetObject`, which when accessed returns
  96. * a string representing the location in the code at which
  97. * `Error.captureStackTrace()` was called.
  98. *
  99. * ```js
  100. * const myObject = {};
  101. * Error.captureStackTrace(myObject);
  102. * myObject.stack; // Similar to `new Error().stack`
  103. * ```
  104. *
  105. * The first line of the trace will be prefixed with
  106. * `${myObject.name}: ${myObject.message}`.
  107. *
  108. * The optional `constructorOpt` argument accepts a function. If given, all frames
  109. * above `constructorOpt`, including `constructorOpt`, will be omitted from the
  110. * generated stack trace.
  111. *
  112. * The `constructorOpt` argument is useful for hiding implementation
  113. * details of error generation from the user. For instance:
  114. *
  115. * ```js
  116. * function a() {
  117. * b();
  118. * }
  119. *
  120. * function b() {
  121. * c();
  122. * }
  123. *
  124. * function c() {
  125. * // Create an error without stack trace to avoid calculating the stack trace twice.
  126. * const { stackTraceLimit } = Error;
  127. * Error.stackTraceLimit = 0;
  128. * const error = new Error();
  129. * Error.stackTraceLimit = stackTraceLimit;
  130. *
  131. * // Capture the stack trace above function b
  132. * Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  133. * throw error;
  134. * }
  135. *
  136. * a();
  137. * ```
  138. */
  139. captureStackTrace(targetObject: object, constructorOpt?: Function): void;
  140. /**
  141. * @see https://v8.dev/docs/stack-trace-api#customizing-stack-traces
  142. */
  143. prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
  144. /**
  145. * The `Error.stackTraceLimit` property specifies the number of stack frames
  146. * collected by a stack trace (whether generated by `new Error().stack` or
  147. * `Error.captureStackTrace(obj)`).
  148. *
  149. * The default value is `10` but may be set to any valid JavaScript number. Changes
  150. * will affect any stack trace captured _after_ the value has been changed.
  151. *
  152. * If set to a non-number value, or set to a negative number, stack traces will
  153. * not capture any frames.
  154. */
  155. stackTraceLimit: number;
  156. }
  157. /**
  158. * Enable this API with the `--expose-gc` CLI flag.
  159. */
  160. var gc: NodeJS.GCFunction | undefined;
  161. namespace NodeJS {
  162. interface CallSite {
  163. getColumnNumber(): number | null;
  164. getEnclosingColumnNumber(): number | null;
  165. getEnclosingLineNumber(): number | null;
  166. getEvalOrigin(): string | undefined;
  167. getFileName(): string | null;
  168. getFunction(): Function | undefined;
  169. getFunctionName(): string | null;
  170. getLineNumber(): number | null;
  171. getMethodName(): string | null;
  172. getPosition(): number;
  173. getPromiseIndex(): number | null;
  174. getScriptHash(): string;
  175. getScriptNameOrSourceURL(): string | null;
  176. getThis(): unknown;
  177. getTypeName(): string | null;
  178. isAsync(): boolean;
  179. isConstructor(): boolean;
  180. isEval(): boolean;
  181. isNative(): boolean;
  182. isPromiseAll(): boolean;
  183. isToplevel(): boolean;
  184. }
  185. interface ErrnoException extends Error {
  186. errno?: number | undefined;
  187. code?: string | undefined;
  188. path?: string | undefined;
  189. syscall?: string | undefined;
  190. }
  191. interface ReadableStream extends EventEmitter {
  192. readable: boolean;
  193. read(size?: number): string | Buffer;
  194. setEncoding(encoding: BufferEncoding): this;
  195. pause(): this;
  196. resume(): this;
  197. isPaused(): boolean;
  198. pipe<T extends WritableStream>(destination: T, options?: { end?: boolean | undefined }): T;
  199. unpipe(destination?: WritableStream): this;
  200. unshift(chunk: string | Uint8Array, encoding?: BufferEncoding): void;
  201. wrap(oldStream: ReadableStream): this;
  202. [Symbol.asyncIterator](): NodeJS.AsyncIterator<string | Buffer>;
  203. }
  204. interface WritableStream extends EventEmitter {
  205. writable: boolean;
  206. write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean;
  207. write(str: string, encoding?: BufferEncoding, cb?: (err?: Error | null) => void): boolean;
  208. end(cb?: () => void): this;
  209. end(data: string | Uint8Array, cb?: () => void): this;
  210. end(str: string, encoding?: BufferEncoding, cb?: () => void): this;
  211. }
  212. interface ReadWriteStream extends ReadableStream, WritableStream {}
  213. interface RefCounted {
  214. ref(): this;
  215. unref(): this;
  216. }
  217. interface Dict<T> {
  218. [key: string]: T | undefined;
  219. }
  220. interface ReadOnlyDict<T> {
  221. readonly [key: string]: T | undefined;
  222. }
  223. interface GCFunction {
  224. (minor?: boolean): void;
  225. (options: NodeJS.GCOptions & { execution: "async" }): Promise<void>;
  226. (options: NodeJS.GCOptions): void;
  227. }
  228. interface GCOptions {
  229. execution?: "sync" | "async" | undefined;
  230. flavor?: "regular" | "last-resort" | undefined;
  231. type?: "major-snapshot" | "major" | "minor" | undefined;
  232. filename?: string | undefined;
  233. }
  234. /** An iterable iterator returned by the Node.js API. */
  235. // Default TReturn/TNext in v22 is `any`, for compatibility with the previously-used IterableIterator.
  236. // TODO: In next major @types/node version, change default TReturn to undefined.
  237. interface Iterator<T, TReturn = any, TNext = any> extends IteratorObject<T, TReturn, TNext> {
  238. [Symbol.iterator](): NodeJS.Iterator<T, TReturn, TNext>;
  239. }
  240. /** An async iterable iterator returned by the Node.js API. */
  241. // Default TReturn/TNext in v22 is `any`, for compatibility with the previously-used AsyncIterableIterator.
  242. // TODO: In next major @types/node version, change default TReturn to undefined.
  243. interface AsyncIterator<T, TReturn = any, TNext = any> extends AsyncIteratorObject<T, TReturn, TNext> {
  244. [Symbol.asyncIterator](): NodeJS.AsyncIterator<T, TReturn, TNext>;
  245. }
  246. }
  247. // Global DOM types
  248. function structuredClone<T>(
  249. value: T,
  250. transfer?: { transfer: ReadonlyArray<import("worker_threads").TransferListItem> },
  251. ): T;
  252. interface DOMException extends _DOMException {}
  253. var DOMException: typeof globalThis extends { onmessage: any; DOMException: infer T } ? T
  254. : NodeDOMExceptionConstructor;
  255. // #region AbortController
  256. interface AbortController {
  257. readonly signal: AbortSignal;
  258. abort(reason?: any): void;
  259. }
  260. var AbortController: typeof globalThis extends { onmessage: any; AbortController: infer T } ? T
  261. : {
  262. prototype: AbortController;
  263. new(): AbortController;
  264. };
  265. interface AbortSignal extends EventTarget {
  266. readonly aborted: boolean;
  267. onabort: ((this: AbortSignal, ev: Event) => any) | null;
  268. readonly reason: any;
  269. throwIfAborted(): void;
  270. }
  271. var AbortSignal: typeof globalThis extends { onmessage: any; AbortSignal: infer T } ? T
  272. : {
  273. prototype: AbortSignal;
  274. new(): AbortSignal;
  275. abort(reason?: any): AbortSignal;
  276. any(signals: AbortSignal[]): AbortSignal;
  277. timeout(milliseconds: number): AbortSignal;
  278. };
  279. // #endregion AbortController
  280. // #region Storage
  281. interface Storage extends _Storage {}
  282. // Conditional on `onabort` rather than `onmessage`, in order to exclude lib.webworker
  283. var Storage: typeof globalThis extends { onabort: any; Storage: infer T } ? T
  284. : {
  285. prototype: Storage;
  286. new(): Storage;
  287. };
  288. var localStorage: Storage;
  289. var sessionStorage: Storage;
  290. // #endregion Storage
  291. // #region fetch
  292. interface RequestInit extends _RequestInit {}
  293. function fetch(
  294. input: string | URL | globalThis.Request,
  295. init?: RequestInit,
  296. ): Promise<Response>;
  297. interface Request extends _Request {}
  298. var Request: typeof globalThis extends {
  299. onmessage: any;
  300. Request: infer T;
  301. } ? T
  302. : typeof import("undici-types").Request;
  303. interface ResponseInit extends _ResponseInit {}
  304. interface Response extends _Response {}
  305. var Response: typeof globalThis extends {
  306. onmessage: any;
  307. Response: infer T;
  308. } ? T
  309. : typeof import("undici-types").Response;
  310. interface FormData extends _FormData {}
  311. var FormData: typeof globalThis extends {
  312. onmessage: any;
  313. FormData: infer T;
  314. } ? T
  315. : typeof import("undici-types").FormData;
  316. interface Headers extends _Headers {}
  317. var Headers: typeof globalThis extends {
  318. onmessage: any;
  319. Headers: infer T;
  320. } ? T
  321. : typeof import("undici-types").Headers;
  322. interface MessageEvent extends _MessageEvent {}
  323. var MessageEvent: typeof globalThis extends {
  324. onmessage: any;
  325. MessageEvent: infer T;
  326. } ? T
  327. : typeof import("undici-types").MessageEvent;
  328. interface WebSocket extends _WebSocket {}
  329. var WebSocket: typeof globalThis extends { onmessage: any; WebSocket: infer T } ? T
  330. : typeof import("undici-types").WebSocket;
  331. interface EventSource extends _EventSource {}
  332. var EventSource: typeof globalThis extends { onmessage: any; EventSource: infer T } ? T
  333. : typeof import("undici-types").EventSource;
  334. // #endregion fetch
  335. }