From 08e33fbd42774ccf8eeda343270175cd90ea80bb Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Mon, 6 Feb 2023 21:36:36 -0800 Subject: [PATCH] Fix gaps in types (#2003) * Add type for clearImmediate * Expose Crypto class * Add types for CustomEvent * Add types for module and exports * Add types for global * Add types for DOMException * Add types for WebAssembly * Update formatting * Fix clearTimeout * Fix formatting * Update formatting * Remove log --------- Co-authored-by: Colin McDonnell --- package.json | 2 +- packages/bun-types/.prettierrc | 6 + packages/bun-types/bun.d.ts | 12 +- packages/bun-types/bun.lockb | Bin 43287 -> 39908 bytes packages/bun-types/dns.d.ts | 25 +- packages/bun-types/globals.d.ts | 421 +++++++++++++++++++-- packages/bun-types/scripts/bundle.ts | 2 +- packages/bun-types/tests/env.test-d.ts | 4 +- packages/bun-types/tests/globals.test-d.ts | 23 ++ packages/bun-types/timers.d.ts | 12 +- packages/bun-types/util.d.ts | 189 +++++++-- 11 files changed, 599 insertions(+), 97 deletions(-) create mode 100644 packages/bun-types/.prettierrc diff --git a/package.json b/package.json index 6c55578bf0..42a8c7a975 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "build-fallback": "esbuild --target=esnext --bundle src/fallback.ts --format=iife --platform=browser --minify > src/fallback.out.js", "postinstall": "bash .scripts/postinstall.sh", "typecheck": "tsc", - "fmt": "prettier --write './**/*.{ts,tsx,js,jsx}'", + "fmt": "prettier --write './**/*.{ts,tsx,js,jsx}' --config .prettierrc", "lint": "eslint './**/*.d.ts' --cache", "lint:fix": "eslint './**/*.d.ts' --cache --fix" }, diff --git a/packages/bun-types/.prettierrc b/packages/bun-types/.prettierrc new file mode 100644 index 0000000000..2a9dc5dc4c --- /dev/null +++ b/packages/bun-types/.prettierrc @@ -0,0 +1,6 @@ +{ + "arrowParens": "avoid", + "printWidth": 80, + "trailingComma": "all", + "useTabs": false +} diff --git a/packages/bun-types/bun.d.ts b/packages/bun-types/bun.d.ts index ba626c00d4..a04ec91a04 100644 --- a/packages/bun-types/bun.d.ts +++ b/packages/bun-types/bun.d.ts @@ -2154,16 +2154,16 @@ declare module "bun" { /** * Resolve a `Promise` after milliseconds. This is like * {@link setTimeout} except it returns a `Promise`. - * + * * @param ms milliseconds to delay resolving the promise. This is a minimum * number. It may take longer. If a {@link Date} is passed, it will sleep until the * {@link Date} is reached. - * - * @example + * + * @example * ## Sleep for 1 second * ```ts * import { sleep } from "bun"; - * + * * await sleep(1000); * ``` * ## Sleep for 10 milliseconds @@ -2171,7 +2171,7 @@ declare module "bun" { * await Bun.sleep(10); * ``` * ## Sleep until `Date` - * + * * ```ts * const target = new Date(); * target.setSeconds(target.getSeconds() + 1); @@ -2657,7 +2657,7 @@ declare module "bun" { */ builder: PluginBuilder, ): void | Promise; - }): ReturnType<(typeof options)["setup"]>; + }): ReturnType; /** * Deactivate all plugins diff --git a/packages/bun-types/bun.lockb b/packages/bun-types/bun.lockb index a0b9b6b1d7dcd3391279fef07e31a10b20a3be85..6b5a8c193184e266ef877528620f77c2979b7c33 100755 GIT binary patch delta 11697 zcmeHNd301|mVd935K^(oQVCSBBnd)-NBtAeO> zy0yit-Fnbg#(~3hJEy^=2W%G@M+c*xHcpS@ppDI_N9KsOOFM0AJI?R->b+N$jM&-- zj{o=_F8AI0EqDK3<$K>xU$(vVPqy2#uX_K)DA$R9Sa)jCpXRIYtbhK|&z;k6+C6FK z510S(r%&!z+B%l)SM;`dUu~*?@9H2C{69uf0^MB=I?;{)V?jRwOn#@Yt|6;^W0Og5 zR29Vzeu_;|5`g~#`U+rQXJ=bymalhIL~#DQ;In@}=y>3`$l!YQ>+4!J`my)}V2nb? z`ns;H#+JIKAA?Q;y$6^I{5nce9KiMwL4ogKq4A(=u<&T$tD+Uf4SW>5a z4)j6rF9YuKwQlxxDoUrXtF2|TPq`mf%}GVaPw+rX_5vG<=pOhjn7Uvrz=eto3mcm^ zHDvX)E6s+7K8qE*EyMp1#!`;ypo5?}z0=p=+XQbufwkEmgS9B`2x#`3c9{BQz)R31 zu(ht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Sj}worgRjzPDEKJi4v3j>8_ffByq^U@NK8V zb{&6>mB39bsO{dYmIRAer+HSYkiB~V7sx{`@e8}6RO%fjpl)JxB|J0{`6aIu}&P!-%zyqz>!bh{2blFqwMVwT574&YSOgy zV4YqwMN9A0>2>16fmw^X{`K?5g71~$@jRAJ0i>(f>ckfW_H*TkQ>$5e%TIxbW;uC^(PLVsOKKe8-A1K93>bU_F z(x6QepAbBG`h~90+TnpHVD+^)tN&Bu>h7bU?uA+IfJ{$9L7HVPWc@kY7 zNOv#O>cqzhL17((UUmuNnSjNJZO;j&mzQZZ^Frtow0Aj#JR7gObR<|NrTF?`{Huk9 z$0IJA6a$p$y3?6%ZPe=c!x_E}oSM^qa`Kgj&uZiq?3@IAkzz+18?|G_=LusMXpa2X zx6T;WD6Hz7#0Ly-oKM(SzyC~EPfqn}ONsrf>6^xJez;ZE^4(XGUcTnH+q8M3-#3G3 zRMWt~9|u{!x!9f-e0h)a_OV}B>n++5*%BUH~bxUij zDhs2l3rw{}Q$uZGRgp2es-mO^* void, + callback: (err: ErrnoException | null, addresses: AnyRecord[]) => void, ): void; export function resolve( hostname: string, @@ -344,18 +341,12 @@ declare module "dns" { export function resolve( hostname: string, rrtype: "MX", - callback: ( - err: ErrnoException | null, - addresses: MxRecord[], - ) => void, + callback: (err: ErrnoException | null, addresses: MxRecord[]) => void, ): void; export function resolve( hostname: string, rrtype: "NAPTR", - callback: ( - err: ErrnoException | null, - addresses: NaptrRecord[], - ) => void, + callback: (err: ErrnoException | null, addresses: NaptrRecord[]) => void, ): void; export function resolve( hostname: string, @@ -375,18 +366,12 @@ declare module "dns" { export function resolve( hostname: string, rrtype: "SRV", - callback: ( - err: ErrnoException | null, - addresses: SrvRecord[], - ) => void, + callback: (err: ErrnoException | null, addresses: SrvRecord[]) => void, ): void; export function resolve( hostname: string, rrtype: "TXT", - callback: ( - err: ErrnoException | null, - addresses: string[][], - ) => void, + callback: (err: ErrnoException | null, addresses: string[][]) => void, ): void; export function resolve( hostname: string, diff --git a/packages/bun-types/globals.d.ts b/packages/bun-types/globals.d.ts index cef3f57ec1..5f2d25661a 100644 --- a/packages/bun-types/globals.d.ts +++ b/packages/bun-types/globals.d.ts @@ -14,7 +14,17 @@ type Platform = | "win32" | "cygwin" | "netbsd"; -type Architecture = "arm" | "arm64" | "ia32" | "mips" | "mipsel" | "ppc" | "ppc64" | "s390" | "s390x" | "x64"; +type Architecture = + | "arm" + | "arm64" + | "ia32" + | "mips" + | "mipsel" + | "ppc" + | "ppc64" + | "s390" + | "s390x" + | "x64"; type Signals = | "SIGABRT" | "SIGALRM" @@ -436,7 +446,10 @@ interface Headers { entries(): IterableIterator<[string, string]>; keys(): IterableIterator; values(): IterableIterator; - forEach(callbackfn: (value: string, key: string, parent: Headers) => void, thisArg?: any): void; + forEach( + callbackfn: (value: string, key: string, parent: Headers) => void, + thisArg?: any, + ): void; /** * Convert {@link Headers} to a plain JavaScript object. @@ -480,7 +493,13 @@ declare var Headers: { }; type HeadersInit = Array<[string, string]> | Record | Headers; -type ResponseType = "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect"; +type ResponseType = + | "basic" + | "cors" + | "default" + | "error" + | "opaque" + | "opaqueredirect"; declare class Blob implements BlobInterface { /** @@ -556,7 +575,10 @@ interface ResponseInit { * ``` */ declare class Response implements BlobInterface { - constructor(body?: ReadableStream | BlobPart | BlobPart[] | null, options?: ResponseInit); + constructor( + body?: ReadableStream | BlobPart | BlobPart[] | null, + options?: ResponseInit, + ); /** * Create a new {@link Response} with a JSON body @@ -689,7 +711,13 @@ declare class Response implements BlobInterface { clone(): Response; } -type RequestCache = "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload"; +type RequestCache = + | "default" + | "force-cache" + | "no-cache" + | "no-store" + | "only-if-cached" + | "reload"; type RequestCredentials = "include" | "omit" | "same-origin"; type RequestDestination = | "" @@ -729,7 +757,9 @@ type RequestInfo = Request | string; type BodyInit = ReadableStream | XMLHttpRequestBodyInit; type XMLHttpRequestBodyInit = Blob | BufferSource | string; type ReadableStreamController = ReadableStreamDefaultController; -type ReadableStreamDefaultReadResult = ReadableStreamDefaultReadValueResult | ReadableStreamDefaultReadDoneResult; +type ReadableStreamDefaultReadResult = + | ReadableStreamDefaultReadValueResult + | ReadableStreamDefaultReadDoneResult; type ReadableStreamReader = ReadableStreamDefaultReader; interface RequestInit { @@ -963,7 +993,7 @@ declare class Request implements BlobInterface { clone(): Request; } -interface Crypto { +declare interface Crypto { readonly subtle: SubtleCrypto; getRandomValues(array: T): T; @@ -979,6 +1009,10 @@ interface Crypto { */ randomUUID(): string; } +declare var Crypto: { + prototype: Crypto; + new (): Crypto; +}; declare var crypto: Crypto; @@ -1061,7 +1095,10 @@ declare class TextDecoder { */ readonly ignoreBOM: boolean; - constructor(encoding?: Encoding, options?: { fatal?: boolean; ignoreBOM?: boolean }); + constructor( + encoding?: Encoding, + options?: { fatal?: boolean; ignoreBOM?: boolean }, + ); /** * Decodes the `input` and returns a string. If `options.stream` is `true`, any @@ -1207,6 +1244,11 @@ declare function clearInterval(id?: number): void; * @param id timer id */ declare function clearTimeout(id?: number): void; +/** + * Cancel an immediate function call by its immediate ID. + * @param id immediate id + */ +declare function clearImmediate(id?: number): void; // declare function createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise; // declare function createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise; /** @@ -1220,8 +1262,10 @@ declare function clearTimeout(id?: number): void; * */ -declare function fetch(url: string | URL, init?: FetchRequestInit): Promise; - +declare function fetch( + url: string | URL, + init?: FetchRequestInit, +): Promise; /** * Send a HTTP(s) request @@ -1246,19 +1290,30 @@ declare function reportError(error: any): void; * Run a function immediately after main event loop is vacant * @param handler function to call */ -declare function setImmediate(handler: TimerHandler, ...arguments: any[]): number; +declare function setImmediate( + handler: TimerHandler, + ...arguments: any[] +): number; /** * Run a function every `interval` milliseconds * @param handler function to call * @param interval milliseconds to wait between calls */ -declare function setInterval(handler: TimerHandler, interval?: number, ...arguments: any[]): number; +declare function setInterval( + handler: TimerHandler, + interval?: number, + ...arguments: any[] +): number; /** * Run a function after `timeout` (milliseconds) * @param handler function to call * @param timeout milliseconds to wait between calls */ -declare function setTimeout(handler: TimerHandler, timeout?: number, ...arguments: any[]): number; +declare function setTimeout( + handler: TimerHandler, + timeout?: number, + ...arguments: any[] +): number; declare function addEventListener( type: K, listener: (this: object, ev: EventMap[K]) => any, @@ -1572,6 +1627,27 @@ declare var MessageEvent: { new (type: string, eventInitDict?: MessageEventInit): MessageEvent; }; +interface CustomEventInit extends EventInit { + detail?: T; +} + +interface CustomEvent extends Event { + /** Returns any custom data event was created with. Typically used for synthetic events. */ + readonly detail: T; + /** @deprecated */ + initCustomEvent( + type: string, + bubbles?: boolean, + cancelable?: boolean, + detail?: T, + ): void; +} + +declare var CustomEvent: { + prototype: CustomEvent; + new (type: string, eventInitDict?: CustomEventInit): CustomEvent; +}; + /** * An implementation of the [WebSocket API](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) */ @@ -1706,14 +1782,19 @@ interface URLSearchParams { keys(): IterableIterator; /** Returns an iterator allowing to go through all values of the key/value pairs of this search parameter. */ values(): IterableIterator; - forEach(callbackfn: (value: string, key: string, parent: URLSearchParams) => void, thisArg?: any): void; + forEach( + callbackfn: (value: string, key: string, parent: URLSearchParams) => void, + thisArg?: any, + ): void; /** Returns a string containing a query string suitable for use in a URL. Does not include the question mark. */ toString(): string; } declare var URLSearchParams: { prototype: URLSearchParams; - new (init?: string[][] | Record | string | URLSearchParams): URLSearchParams; + new ( + init?: string[][] | Record | string | URLSearchParams, + ): URLSearchParams; toString(): string; }; @@ -1914,10 +1995,19 @@ interface ReadableStream { readonly locked: boolean; cancel(reason?: any): Promise; getReader(): ReadableStreamDefaultReader; - pipeThrough(transform: ReadableWritablePair, options?: StreamPipeOptions): ReadableStream; - pipeTo(destination: WritableStream, options?: StreamPipeOptions): Promise; + pipeThrough( + transform: ReadableWritablePair, + options?: StreamPipeOptions, + ): ReadableStream; + pipeTo( + destination: WritableStream, + options?: StreamPipeOptions, + ): Promise; tee(): [ReadableStream, ReadableStream]; - forEach(callbackfn: (value: any, key: number, parent: ReadableStream) => void, thisArg?: any): void; + forEach( + callbackfn: (value: any, key: number, parent: ReadableStream) => void, + thisArg?: any, + ): void; [Symbol.asyncIterator](): AsyncIterableIterator; values(options?: { preventCancel: boolean }): AsyncIterableIterator; } @@ -1975,7 +2065,8 @@ declare var ReadableStreamDefaultController: { new (): ReadableStreamDefaultController; }; -interface ReadableStreamDefaultReader extends ReadableStreamGenericReader { +interface ReadableStreamDefaultReader + extends ReadableStreamGenericReader { read(): Promise>; releaseLock(): void; } @@ -2020,7 +2111,10 @@ interface WritableStream { declare var WritableStream: { prototype: WritableStream; - new (underlyingSink?: UnderlyingSink, strategy?: QueuingStrategy): WritableStream; + new ( + underlyingSink?: UnderlyingSink, + strategy?: QueuingStrategy, + ): WritableStream; }; /** This Streams API interface represents a controller allowing control of a WritableStream's state. When constructing a WritableStream, the underlying sink is given a corresponding WritableStreamDefaultController instance to manipulate. */ @@ -2060,7 +2154,10 @@ interface TransformerStartCallback { } interface TransformerTransformCallback { - (chunk: I, controller: TransformStreamDefaultController): void | PromiseLike; + ( + chunk: I, + controller: TransformStreamDefaultController, + ): void | PromiseLike; } interface UnderlyingSinkAbortCallback { @@ -2076,7 +2173,10 @@ interface UnderlyingSinkStartCallback { } interface UnderlyingSinkWriteCallback { - (chunk: W, controller: WritableStreamDefaultController): void | PromiseLike; + ( + chunk: W, + controller: WritableStreamDefaultController, + ): void | PromiseLike; } interface UnderlyingSourceCancelCallback { @@ -2101,7 +2201,9 @@ interface UnderlyingSource { // eslint-disable-next-line @typescript-eslint/no-unused-vars interface DirectUnderlyingSource { cancel?: UnderlyingSourceCancelCallback; - pull: (controller: ReadableStreamDirectController) => void | PromiseLike; + pull: ( + controller: ReadableStreamDirectController, + ) => void | PromiseLike; type: "direct"; } @@ -2206,6 +2308,43 @@ interface ErrnoException extends Error { syscall?: string | undefined; } +/** An abnormal event (called an exception) which occurs as a result of calling a method or accessing a property of a web API. */ +interface DOMException extends Error { + /** @deprecated */ + readonly code: number; + readonly message: string; + readonly name: string; + readonly ABORT_ERR: number; + readonly DATA_CLONE_ERR: number; + readonly DOMSTRING_SIZE_ERR: number; + readonly HIERARCHY_REQUEST_ERR: number; + readonly INDEX_SIZE_ERR: number; + readonly INUSE_ATTRIBUTE_ERR: number; + readonly INVALID_ACCESS_ERR: number; + readonly INVALID_CHARACTER_ERR: number; + readonly INVALID_MODIFICATION_ERR: number; + readonly INVALID_NODE_TYPE_ERR: number; + readonly INVALID_STATE_ERR: number; + readonly NAMESPACE_ERR: number; + readonly NETWORK_ERR: number; + readonly NOT_FOUND_ERR: number; + readonly NOT_SUPPORTED_ERR: number; + readonly NO_DATA_ALLOWED_ERR: number; + readonly NO_MODIFICATION_ALLOWED_ERR: number; + readonly QUOTA_EXCEEDED_ERR: number; + readonly SECURITY_ERR: number; + readonly SYNTAX_ERR: number; + readonly TIMEOUT_ERR: number; + readonly TYPE_MISMATCH_ERR: number; + readonly URL_MISMATCH_ERR: number; + readonly VALIDATION_ERR: number; + readonly WRONG_DOCUMENT_ERR: number; +} +declare var DOMException: { + prototype: DOMException; + new (message?: string, name?: string): DOMException; +}; + declare function alert(message?: string): void; declare function confirm(message?: string): boolean; declare function prompt(message?: string, _default?: string): string | null; @@ -2218,7 +2357,15 @@ declare function prompt(message?: string, _default?: string): string | null; type KeyFormat = "jwk" | "pkcs8" | "raw" | "spki"; type KeyType = "private" | "public" | "secret"; -type KeyUsage = "decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey"; +type KeyUsage = + | "decrypt" + | "deriveBits" + | "deriveKey" + | "encrypt" + | "sign" + | "unwrapKey" + | "verify" + | "wrapKey"; type HashAlgorithmIdentifier = AlgorithmIdentifier; type NamedCurve = string; @@ -2371,30 +2518,59 @@ type AlgorithmIdentifier = Algorithm | string; */ interface SubtleCrypto { decrypt( - algorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams, + algorithm: + | AlgorithmIdentifier + | RsaOaepParams + | AesCtrParams + | AesCbcParams + | AesGcmParams, key: CryptoKey, data: BufferSource, ): Promise; deriveBits( - algorithm: AlgorithmIdentifier | EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params, + algorithm: + | AlgorithmIdentifier + | EcdhKeyDeriveParams + | HkdfParams + | Pbkdf2Params, baseKey: CryptoKey, length: number, ): Promise; deriveKey( - algorithm: AlgorithmIdentifier | EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params, + algorithm: + | AlgorithmIdentifier + | EcdhKeyDeriveParams + | HkdfParams + | Pbkdf2Params, baseKey: CryptoKey, - derivedKeyType: AlgorithmIdentifier | AesDerivedKeyParams | HmacImportParams | HkdfParams | Pbkdf2Params, + derivedKeyType: + | AlgorithmIdentifier + | AesDerivedKeyParams + | HmacImportParams + | HkdfParams + | Pbkdf2Params, extractable: boolean, keyUsages: KeyUsage[], ): Promise; - digest(algorithm: AlgorithmIdentifier, data: BufferSource): Promise; + digest( + algorithm: AlgorithmIdentifier, + data: BufferSource, + ): Promise; encrypt( - algorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams, + algorithm: + | AlgorithmIdentifier + | RsaOaepParams + | AesCtrParams + | AesCbcParams + | AesGcmParams, key: CryptoKey, data: BufferSource, ): Promise; exportKey(format: "jwk", key: CryptoKey): Promise; - exportKey(format: Exclude, key: CryptoKey): Promise; + exportKey( + format: Exclude, + key: CryptoKey, + ): Promise; generateKey( algorithm: RsaHashedKeyGenParams | EcKeyGenParams, extractable: boolean, @@ -2413,14 +2589,24 @@ interface SubtleCrypto { importKey( format: "jwk", keyData: JsonWebKey, - algorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm, + algorithm: + | AlgorithmIdentifier + | RsaHashedImportParams + | EcKeyImportParams + | HmacImportParams + | AesKeyAlgorithm, extractable: boolean, keyUsages: ReadonlyArray, ): Promise; importKey( format: Exclude, keyData: BufferSource, - algorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm, + algorithm: + | AlgorithmIdentifier + | RsaHashedImportParams + | EcKeyImportParams + | HmacImportParams + | AesKeyAlgorithm, extractable: boolean, keyUsages: KeyUsage[], ): Promise; @@ -2433,7 +2619,12 @@ interface SubtleCrypto { format: KeyFormat, wrappedKey: BufferSource, unwrappingKey: CryptoKey, - unwrapAlgorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams, + unwrapAlgorithm: + | AlgorithmIdentifier + | RsaOaepParams + | AesCtrParams + | AesCbcParams + | AesGcmParams, unwrappedKeyAlgorithm: | AlgorithmIdentifier | RsaHashedImportParams @@ -2453,7 +2644,12 @@ interface SubtleCrypto { format: KeyFormat, key: CryptoKey, wrappingKey: CryptoKey, - wrapAlgorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams, + wrapAlgorithm: + | AlgorithmIdentifier + | RsaOaepParams + | AesCtrParams + | AesCbcParams + | AesGcmParams, ): Promise; } @@ -2537,7 +2733,9 @@ interface ErrorConstructor { * * @see https://v8.dev/docs/stack-trace-api#customizing-stack-traces */ - prepareStackTrace?: ((err: Error, stackTraces: CallSite[]) => any) | undefined; + prepareStackTrace?: + | ((err: Error, stackTraces: CallSite[]) => any) + | undefined; stackTraceLimit: number; } @@ -2642,3 +2840,154 @@ interface SharedArrayBuffer { */ grow(size: number): SharedArrayBuffer; } + +declare namespace WebAssembly { + interface CompileError extends Error {} + + var CompileError: { + prototype: CompileError; + new (message?: string): CompileError; + (message?: string): CompileError; + }; + + interface Global { + value: any; + valueOf(): any; + } + + var Global: { + prototype: Global; + new (descriptor: GlobalDescriptor, v?: any): Global; + }; + + interface Instance { + readonly exports: Exports; + } + + var Instance: { + prototype: Instance; + new (module: Module, importObject?: Imports): Instance; + }; + + interface LinkError extends Error {} + + var LinkError: { + prototype: LinkError; + new (message?: string): LinkError; + (message?: string): LinkError; + }; + + interface Memory { + readonly buffer: ArrayBuffer; + grow(delta: number): number; + } + + var Memory: { + prototype: Memory; + new (descriptor: MemoryDescriptor): Memory; + }; + + interface Module {} + + var Module: { + prototype: Module; + new (bytes: BufferSource): Module; + customSections(moduleObject: Module, sectionName: string): ArrayBuffer[]; + exports(moduleObject: Module): ModuleExportDescriptor[]; + imports(moduleObject: Module): ModuleImportDescriptor[]; + }; + + interface RuntimeError extends Error {} + + var RuntimeError: { + prototype: RuntimeError; + new (message?: string): RuntimeError; + (message?: string): RuntimeError; + }; + + interface Table { + readonly length: number; + get(index: number): any; + grow(delta: number, value?: any): number; + set(index: number, value?: any): void; + } + + var Table: { + prototype: Table; + new (descriptor: TableDescriptor, value?: any): Table; + }; + + interface GlobalDescriptor { + mutable?: boolean; + value: ValueType; + } + + interface MemoryDescriptor { + initial: number; + maximum?: number; + shared?: boolean; + } + + interface ModuleExportDescriptor { + kind: ImportExportKind; + name: string; + } + + interface ModuleImportDescriptor { + kind: ImportExportKind; + module: string; + name: string; + } + + interface TableDescriptor { + element: TableKind; + initial: number; + maximum?: number; + } + + interface WebAssemblyInstantiatedSource { + instance: Instance; + module: Module; + } + + type ImportExportKind = "function" | "global" | "memory" | "table"; + type TableKind = "anyfunc" | "externref"; + type ValueType = + | "anyfunc" + | "externref" + | "f32" + | "f64" + | "i32" + | "i64" + | "v128"; + type ExportValue = Function | Global | Memory | Table; + type Exports = Record; + type ImportValue = ExportValue | number; + type Imports = Record; + type ModuleImports = Record; + function compile(bytes: BufferSource): Promise; + // function compileStreaming(source: Response | PromiseLike): Promise; + function instantiate( + bytes: BufferSource, + importObject?: Imports, + ): Promise; + function instantiate( + moduleObject: Module, + importObject?: Imports, + ): Promise; + // function instantiateStreaming( + // source: Response | PromiseLike, + // importObject?: Imports, + // ): Promise; + function validate(bytes: BufferSource): boolean; +} + +interface NodeModule { + exports: any; +} + +declare var module: NodeModule; + +// Same as module.exports +declare var exports: any; +declare var global: typeof globalThis; diff --git a/packages/bun-types/scripts/bundle.ts b/packages/bun-types/scripts/bundle.ts index 7661a8747b..6a7a5af22b 100644 --- a/packages/bun-types/scripts/bundle.ts +++ b/packages/bun-types/scripts/bundle.ts @@ -23,7 +23,7 @@ try { const header = await file(join(import.meta.dir, "..", "header.txt")).text(); const filesToCat = (await getDotTsFiles("./")).filter( - (f) => !["./index.d.ts"].some((tf) => f === tf), + f => !["./index.d.ts"].some(tf => f === tf), ); const fileContents: string[] = []; diff --git a/packages/bun-types/tests/env.test-d.ts b/packages/bun-types/tests/env.test-d.ts index 073caabfe6..c2611e1a78 100644 --- a/packages/bun-types/tests/env.test-d.ts +++ b/packages/bun-types/tests/env.test-d.ts @@ -12,9 +12,11 @@ expectType<"WHATEVER">(process.env.WHATEVER); export {}; new Bun.Transpiler({ - macros: { + macro: { "react-relay": { graphql: "bun-macro-relay/bun-macro-relay.tsx", }, }, }); + +Event; diff --git a/packages/bun-types/tests/globals.test-d.ts b/packages/bun-types/tests/globals.test-d.ts index 5faf9d8340..c67aa42567 100644 --- a/packages/bun-types/tests/globals.test-d.ts +++ b/packages/bun-types/tests/globals.test-d.ts @@ -64,3 +64,26 @@ expectType>(fsPromises.mkdir("./index.d.ts")); Bun.env; Bun.version; + +setImmediate; +clearImmediate; +setInterval; +clearInterval; +setTimeout; +clearTimeout; + +const arg = new AbortSignal(); +arg; + +const e = new CustomEvent("asdf"); +console.log(e); + +exports; +module.exports; + +global.AbortController; +global.Bun; + +const er = new DOMException(); +er.name; +er.HIERARCHY_REQUEST_ERR; diff --git a/packages/bun-types/timers.d.ts b/packages/bun-types/timers.d.ts index c09c5b30cb..ab1e299531 100644 --- a/packages/bun-types/timers.d.ts +++ b/packages/bun-types/timers.d.ts @@ -19,8 +19,16 @@ declare module "timers" { const _exported: { clearTimeout: (timer: Timer | number) => void; clearInterval: (timer: Timer | number) => void; - setInterval: (cb: CallableFunction, msDelay: number, ...args: any[]) => Timer; - setTimeout: (cb: CallableFunction, msDelay: number, ...args: any[]) => Timer; + setInterval: ( + cb: CallableFunction, + msDelay: number, + ...args: any[] + ) => Timer; + setTimeout: ( + cb: CallableFunction, + msDelay: number, + ...args: any[] + ) => Timer; setImmediate: (cb: CallableFunction, ...args: any[]) => Timer; }; export = _exported; diff --git a/packages/bun-types/util.d.ts b/packages/bun-types/util.d.ts index 36e5f8814b..134fd59fa7 100644 --- a/packages/bun-types/util.d.ts +++ b/packages/bun-types/util.d.ts @@ -64,7 +64,10 @@ declare module "util" { | "date" | "regexp" | "module"; - export type CustomInspectFunction = (depth: number, options: InspectOptionsStylized) => string; + export type CustomInspectFunction = ( + depth: number, + options: InspectOptionsStylized, + ) => string; export interface InspectOptionsStylized extends InspectOptions { stylize(text: string, styleType: Style): string; } @@ -341,7 +344,12 @@ declare module "util" { * @param object Any JavaScript primitive or `Object`. * @return The representation of `object`. */ - export function inspect(object: any, showHidden?: boolean, depth?: number | null, color?: boolean): string; + export function inspect( + object: any, + showHidden?: boolean, + depth?: number | null, + color?: boolean, + ): string; export function inspect(object: any, options?: InspectOptions): string; export namespace inspect { let colors: Dict<[number, number]>; @@ -494,7 +502,10 @@ declare module "util" { * ``` * @deprecated Legacy: Use ES2015 class syntax and `extends` keyword instead. */ - export function inherits(constructor: unknown, superConstructor: unknown): void; + export function inherits( + constructor: unknown, + superConstructor: unknown, + ): void; export type DebugLoggerFunction = (msg: string, ...param: unknown[]) => void; export interface DebugLogger extends DebugLoggerFunction { enabled: boolean; @@ -555,7 +566,10 @@ declare module "util" { * @param callback A callback invoked the first time the logging function is called with a function argument that is a more optimized logging function. * @return The logging function */ - export function debuglog(section: string, callback?: (fn: DebugLoggerFunction) => void): DebugLogger; + export function debuglog( + section: string, + callback?: (fn: DebugLoggerFunction) => void, + ): DebugLogger; export const debug: typeof debuglog; /** * Returns `true` if the given `object` is a `Boolean`. Otherwise, returns `false`. @@ -640,7 +654,9 @@ declare module "util" { * ``` * @deprecated Since v4.0.0 - Use `value === undefined || value === null` instead. */ - export function isNullOrUndefined(object: unknown): object is null | undefined; + export function isNullOrUndefined( + object: unknown, + ): object is null | undefined; /** * Returns `true` if the given `object` is a `Number`. Otherwise, returns `false`. * @@ -804,7 +820,11 @@ declare module "util" { * @param code A deprecation code. See the `list of deprecated APIs` for a list of codes. * @return The deprecated function wrapped to emit a warning. */ - export function deprecate(fn: T, msg: string, code?: string): T; + export function deprecate( + fn: T, + msg: string, + code?: string, + ): T; /** * Returns `true` if there is deep strict equality between `val1` and `val2`. * Otherwise, returns `false`. @@ -871,7 +891,9 @@ declare module "util" { * @param original An `async` function * @return a callback style function */ - export function callbackify(fn: () => Promise): (callback: (err: ErrnoException) => void) => void; + export function callbackify( + fn: () => Promise, + ): (callback: (err: ErrnoException) => void) => void; export function callbackify( fn: () => Promise, ): (callback: (err: ErrnoException, result: TResult) => void) => void; @@ -880,28 +902,64 @@ declare module "util" { ): (arg1: T1, callback: (err: ErrnoException) => void) => void; export function callbackify( fn: (arg1: T1) => Promise, - ): (arg1: T1, callback: (err: ErrnoException, result: TResult) => void) => void; + ): ( + arg1: T1, + callback: (err: ErrnoException, result: TResult) => void, + ) => void; export function callbackify( fn: (arg1: T1, arg2: T2) => Promise, ): (arg1: T1, arg2: T2, callback: (err: ErrnoException) => void) => void; export function callbackify( fn: (arg1: T1, arg2: T2) => Promise, - ): (arg1: T1, arg2: T2, callback: (err: ErrnoException | null, result: TResult) => void) => void; + ): ( + arg1: T1, + arg2: T2, + callback: (err: ErrnoException | null, result: TResult) => void, + ) => void; export function callbackify( fn: (arg1: T1, arg2: T2, arg3: T3) => Promise, - ): (arg1: T1, arg2: T2, arg3: T3, callback: (err: ErrnoException) => void) => void; + ): ( + arg1: T1, + arg2: T2, + arg3: T3, + callback: (err: ErrnoException) => void, + ) => void; export function callbackify( fn: (arg1: T1, arg2: T2, arg3: T3) => Promise, - ): (arg1: T1, arg2: T2, arg3: T3, callback: (err: ErrnoException | null, result: TResult) => void) => void; + ): ( + arg1: T1, + arg2: T2, + arg3: T3, + callback: (err: ErrnoException | null, result: TResult) => void, + ) => void; export function callbackify( fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise, - ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: ErrnoException) => void) => void; + ): ( + arg1: T1, + arg2: T2, + arg3: T3, + arg4: T4, + callback: (err: ErrnoException) => void, + ) => void; export function callbackify( fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise, - ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: ErrnoException | null, result: TResult) => void) => void; + ): ( + arg1: T1, + arg2: T2, + arg3: T3, + arg4: T4, + callback: (err: ErrnoException | null, result: TResult) => void, + ) => void; export function callbackify( fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise, - ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: ErrnoException) => void) => void; + ): ( + arg1: T1, + arg2: T2, + arg3: T3, + arg4: T4, + arg5: T5, + callback: (err: ErrnoException) => void, + ) => void; export function callbackify( fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise, ): ( @@ -913,10 +971,32 @@ declare module "util" { callback: (err: ErrnoException | null, result: TResult) => void, ) => void; export function callbackify( - fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise, - ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: ErrnoException) => void) => void; + fn: ( + arg1: T1, + arg2: T2, + arg3: T3, + arg4: T4, + arg5: T5, + arg6: T6, + ) => Promise, + ): ( + arg1: T1, + arg2: T2, + arg3: T3, + arg4: T4, + arg5: T5, + arg6: T6, + callback: (err: ErrnoException) => void, + ) => void; export function callbackify( - fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise, + fn: ( + arg1: T1, + arg2: T2, + arg3: T3, + arg4: T4, + arg5: T5, + arg6: T6, + ) => Promise, ): ( arg1: T1, arg2: T2, @@ -926,10 +1006,12 @@ declare module "util" { arg6: T6, callback: (err: ErrnoException | null, result: TResult) => void, ) => void; - export interface CustomPromisifyLegacy extends Function { + export interface CustomPromisifyLegacy + extends Function { __promisify__: TCustom; } - export interface CustomPromisifySymbol extends Function { + export interface CustomPromisifySymbol + extends Function { [promisify.custom]: TCustom; } export type CustomPromisify = @@ -1001,38 +1083,79 @@ declare module "util" { * bindBar().then((a) => console.log(a)); // '42' * ``` */ - export function promisify(fn: CustomPromisify): TCustom; + export function promisify( + fn: CustomPromisify, + ): TCustom; export function promisify( fn: (callback: (err: any, result: TResult) => void) => void, ): () => Promise; - export function promisify(fn: (callback: (err?: any) => void) => void): () => Promise; + export function promisify( + fn: (callback: (err?: any) => void) => void, + ): () => Promise; export function promisify( fn: (arg1: T1, callback: (err: any, result: TResult) => void) => void, ): (arg1: T1) => Promise; - export function promisify(fn: (arg1: T1, callback: (err?: any) => void) => void): (arg1: T1) => Promise; + export function promisify( + fn: (arg1: T1, callback: (err?: any) => void) => void, + ): (arg1: T1) => Promise; export function promisify( - fn: (arg1: T1, arg2: T2, callback: (err: any, result: TResult) => void) => void, + fn: ( + arg1: T1, + arg2: T2, + callback: (err: any, result: TResult) => void, + ) => void, ): (arg1: T1, arg2: T2) => Promise; export function promisify( fn: (arg1: T1, arg2: T2, callback: (err?: any) => void) => void, ): (arg1: T1, arg2: T2) => Promise; export function promisify( - fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err: any, result: TResult) => void) => void, + fn: ( + arg1: T1, + arg2: T2, + arg3: T3, + callback: (err: any, result: TResult) => void, + ) => void, ): (arg1: T1, arg2: T2, arg3: T3) => Promise; export function promisify( fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err?: any) => void) => void, ): (arg1: T1, arg2: T2, arg3: T3) => Promise; export function promisify( - fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: any, result: TResult) => void) => void, + fn: ( + arg1: T1, + arg2: T2, + arg3: T3, + arg4: T4, + callback: (err: any, result: TResult) => void, + ) => void, ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise; export function promisify( - fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err?: any) => void) => void, + fn: ( + arg1: T1, + arg2: T2, + arg3: T3, + arg4: T4, + callback: (err?: any) => void, + ) => void, ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise; export function promisify( - fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: any, result: TResult) => void) => void, + fn: ( + arg1: T1, + arg2: T2, + arg3: T3, + arg4: T4, + arg5: T5, + callback: (err: any, result: TResult) => void, + ) => void, ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise; export function promisify( - fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err?: any) => void) => void, + fn: ( + arg1: T1, + arg2: T2, + arg3: T3, + arg4: T4, + arg5: T5, + callback: (err?: any) => void, + ) => void, ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise; export function promisify(fn: Function): Function; export namespace promisify { @@ -1182,7 +1305,9 @@ declare module "util/types" { * ``` * @since v10.11.0 */ - function isBoxedPrimitive(object: unknown): object is String | Number | BigInt | Boolean | Symbol; + function isBoxedPrimitive( + object: unknown, + ): object is String | Number | BigInt | Boolean | Symbol; /** * Returns `true` if the value is a built-in [`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) instance. * @@ -1428,7 +1553,11 @@ declare module "util/types" { */ function isSet( object: T | {}, - ): object is T extends ReadonlySet ? (unknown extends T ? never : ReadonlySet) : Set; + ): object is T extends ReadonlySet + ? unknown extends T + ? never + : ReadonlySet + : Set; /** * Returns `true` if the value is an iterator returned for a built-in [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) instance. *