7faed98ac10bdeaebe8b5bfa1b02101eaab59b74791419051d57d4bd6161f1d4aa12e20122c35ac3f4125f3756b4a4ff16c5d0e1ede65ae31721e534908cd9 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. declare var global: typeof globalThis;
  2. declare var process: NodeJS.Process;
  3. declare var console: Console;
  4. interface ErrorConstructor {
  5. /**
  6. * Creates a `.stack` property on `targetObject`, which when accessed returns
  7. * a string representing the location in the code at which
  8. * `Error.captureStackTrace()` was called.
  9. *
  10. * ```js
  11. * const myObject = {};
  12. * Error.captureStackTrace(myObject);
  13. * myObject.stack; // Similar to `new Error().stack`
  14. * ```
  15. *
  16. * The first line of the trace will be prefixed with
  17. * `${myObject.name}: ${myObject.message}`.
  18. *
  19. * The optional `constructorOpt` argument accepts a function. If given, all frames
  20. * above `constructorOpt`, including `constructorOpt`, will be omitted from the
  21. * generated stack trace.
  22. *
  23. * The `constructorOpt` argument is useful for hiding implementation
  24. * details of error generation from the user. For instance:
  25. *
  26. * ```js
  27. * function a() {
  28. * b();
  29. * }
  30. *
  31. * function b() {
  32. * c();
  33. * }
  34. *
  35. * function c() {
  36. * // Create an error without stack trace to avoid calculating the stack trace twice.
  37. * const { stackTraceLimit } = Error;
  38. * Error.stackTraceLimit = 0;
  39. * const error = new Error();
  40. * Error.stackTraceLimit = stackTraceLimit;
  41. *
  42. * // Capture the stack trace above function b
  43. * Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  44. * throw error;
  45. * }
  46. *
  47. * a();
  48. * ```
  49. */
  50. captureStackTrace(targetObject: object, constructorOpt?: Function): void;
  51. /**
  52. * @see https://v8.dev/docs/stack-trace-api#customizing-stack-traces
  53. */
  54. prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
  55. /**
  56. * The `Error.stackTraceLimit` property specifies the number of stack frames
  57. * collected by a stack trace (whether generated by `new Error().stack` or
  58. * `Error.captureStackTrace(obj)`).
  59. *
  60. * The default value is `10` but may be set to any valid JavaScript number. Changes
  61. * will affect any stack trace captured _after_ the value has been changed.
  62. *
  63. * If set to a non-number value, or set to a negative number, stack traces will
  64. * not capture any frames.
  65. */
  66. stackTraceLimit: number;
  67. }
  68. /**
  69. * Enable this API with the `--expose-gc` CLI flag.
  70. */
  71. declare var gc: NodeJS.GCFunction | undefined;
  72. declare namespace NodeJS {
  73. interface CallSite {
  74. getColumnNumber(): number | null;
  75. getEnclosingColumnNumber(): number | null;
  76. getEnclosingLineNumber(): number | null;
  77. getEvalOrigin(): string | undefined;
  78. getFileName(): string | null;
  79. getFunction(): Function | undefined;
  80. getFunctionName(): string | null;
  81. getLineNumber(): number | null;
  82. getMethodName(): string | null;
  83. getPosition(): number;
  84. getPromiseIndex(): number | null;
  85. getScriptHash(): string;
  86. getScriptNameOrSourceURL(): string | null;
  87. getThis(): unknown;
  88. getTypeName(): string | null;
  89. isAsync(): boolean;
  90. isConstructor(): boolean;
  91. isEval(): boolean;
  92. isNative(): boolean;
  93. isPromiseAll(): boolean;
  94. isToplevel(): boolean;
  95. }
  96. interface ErrnoException extends Error {
  97. errno?: number | undefined;
  98. code?: string | undefined;
  99. path?: string | undefined;
  100. syscall?: string | undefined;
  101. }
  102. interface ReadableStream extends EventEmitter {
  103. readable: boolean;
  104. read(size?: number): string | Buffer;
  105. setEncoding(encoding: BufferEncoding): this;
  106. pause(): this;
  107. resume(): this;
  108. isPaused(): boolean;
  109. pipe<T extends WritableStream>(destination: T, options?: { end?: boolean | undefined }): T;
  110. unpipe(destination?: WritableStream): this;
  111. unshift(chunk: string | Uint8Array, encoding?: BufferEncoding): void;
  112. wrap(oldStream: ReadableStream): this;
  113. [Symbol.asyncIterator](): AsyncIterableIterator<string | Buffer>;
  114. }
  115. interface WritableStream extends EventEmitter {
  116. writable: boolean;
  117. write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean;
  118. write(str: string, encoding?: BufferEncoding, cb?: (err?: Error | null) => void): boolean;
  119. end(cb?: () => void): this;
  120. end(data: string | Uint8Array, cb?: () => void): this;
  121. end(str: string, encoding?: BufferEncoding, cb?: () => void): this;
  122. }
  123. interface ReadWriteStream extends ReadableStream, WritableStream {}
  124. interface RefCounted {
  125. ref(): this;
  126. unref(): this;
  127. }
  128. interface Dict<T> {
  129. [key: string]: T | undefined;
  130. }
  131. interface ReadOnlyDict<T> {
  132. readonly [key: string]: T | undefined;
  133. }
  134. interface GCFunction {
  135. (minor?: boolean): void;
  136. (options: NodeJS.GCOptions & { execution: "async" }): Promise<void>;
  137. (options: NodeJS.GCOptions): void;
  138. }
  139. interface GCOptions {
  140. execution?: "sync" | "async" | undefined;
  141. flavor?: "regular" | "last-resort" | undefined;
  142. type?: "major-snapshot" | "major" | "minor" | undefined;
  143. filename?: string | undefined;
  144. }
  145. /** An iterable iterator returned by the Node.js API. */
  146. interface Iterator<T, TReturn = undefined, TNext = any> extends IteratorObject<T, TReturn, TNext> {
  147. [Symbol.iterator](): NodeJS.Iterator<T, TReturn, TNext>;
  148. }
  149. /** An async iterable iterator returned by the Node.js API. */
  150. interface AsyncIterator<T, TReturn = undefined, TNext = any> extends AsyncIteratorObject<T, TReturn, TNext> {
  151. [Symbol.asyncIterator](): NodeJS.AsyncIterator<T, TReturn, TNext>;
  152. }
  153. }