namespace
__internal
namespace __internal
interface BunEvent
The Node.js-flavored members of the global
Event. The global interface picks them up only when lib.dom.d.ts is not loaded: lib.dom declarescomposedPath(): EventTarget[], which is incompatible with the tuple type below, so when lib.dom is loaded its declarations win.- cancelBubble: boolean
Alias for event.stopPropagation(). This is not used in Node.js and is provided purely for completeness.
- readonly defaultPrevented: boolean
trueifcancelableistrueandevent.preventDefault()has been called. - readonly isTrusted: boolean
The
AbortSignal"abort" event is emitted withisTrustedset totrue. The value isfalsein all other cases. Returns an array containing the current EventTarget as the only entry or empty if the event is not being dispatched. This is not used in Node.js and is provided purely for completeness.
Sets the
defaultPreventedproperty totrueifcancelableistrue.Stops the invocation of event listeners after the current one completes.
This is not used in Node.js and is provided purely for completeness.
interface BunEventTarget
The Node.js-flavored members of the global
EventTarget, used only when lib.dom.d.ts is not loaded, same as BunEvent.- type: string,): void;
Adds a new handler for the
typeevent. Any givenlisteneris added only once pertypeand percaptureoption value.If the
onceoption is true, thelisteneris removed after the next time atypeevent is dispatched.The
captureoption is not used by Node.js in any functional way other than tracking registered event listeners per theEventTargetspecification. Specifically, thecaptureoption is used as part of the key when registering alistener. Any individuallistenermay be added once withcapture = false, and once withcapture = true. - ): boolean;
Dispatches a synthetic event
eventto target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. - type: string,): void;
Removes the event listener in target's event listener list with the same type, callback, and options.
interface BunHeadersOverride
- name: 'set-cookie' | 'Set-Cookie'): string[];
Gets all values for the given header name.
Only
"Set-Cookie"is supported. Any other header name returns an empty array.@param nameThe header name
@returnsThe header's values
const headers = new Headers(); headers.append("Set-Cookie", "foo=bar"); headers.append("Set-Cookie", "baz=qux"); headers.getAll("Set-Cookie"); // ["foo=bar", "baz=qux"] Converts Headers to a plain JavaScript object.
About 10x faster than
Object.fromEntries(headers.entries()).Called when you run
JSON.stringify(headers).Does not preserve insertion order. Well-known header names are lowercased; other header names are left as-is.
interface BunRequestOverride
Returns a ReadableStream of the body decoded as UTF-8 text.
Multi-byte characters split across chunk boundaries are joined correctly. Throws a TypeError if the body has already been consumed or is locked.
interface BunResponseOverride
Returns a ReadableStream of the body decoded as UTF-8 text.
Multi-byte characters split across chunk boundaries are joined correctly. Throws a TypeError if the body has already been consumed or is locked.
- type DistributedMerge<T, Else = T> = T extends T ? Merge<T, Exclude<Else, T>> : never
- type DistributedOmit<T, K extends PropertyKey> = T extends T ? Omit<T, K> : never
Like Omit, but correctly distributes over unions. Most useful for removing properties from union options objects, like Bun.SQL.Options
type X = Bun.DistributedOmit<{type?: 'a', url?: string} | {type?: 'b', flag?: boolean}, "url"> // `{type?: 'a'} | {type?: 'b', flag?: boolean}` (Omit applied to each union item instead of entire type) type X = Omit<{type?: 'a', url?: string} | {type?: 'b', flag?: boolean}, "url">; // `{type?: "a" | "b" | undefined}` (Missing `flag` property and no longer a union) - type KeysInBoth<A, B> = Extract<keyof A, keyof B>
- type LibDomIsLoaded = typeof globalThis extends { onabort: any } ? true : false
- type LibEmptyOrBroadcastChannel = LibDomIsLoaded extends true ? {} : BroadcastChannel
- type LibEmptyOrBunEvent = LibDomIsLoaded extends true ? {} : BunEvent
- type LibEmptyOrBunEventTarget = LibDomIsLoaded extends true ? {} : BunEventTarget
- type LibEmptyOrBunWebSocket = LibDomIsLoaded extends true ? {} : Bun.WebSocket
- type LibEmptyOrEventSource = LibDomIsLoaded extends true ? {} : EventSource
- type LibEmptyOrNodeCryptoWebcryptoSubtleCrypto = LibDomIsLoaded extends true ? {} : webcrypto.SubtleCrypto
- type LibEmptyOrNodeMessagePort = LibDomIsLoaded extends true ? {} : MessagePort
- type LibEmptyOrNodeReadableStream<T> = LibDomIsLoaded extends true ? {} : ReadableStream
- type LibEmptyOrNodeStreamWebCompressionStream = LibDomIsLoaded extends true ? {} : CompressionStream
- type LibEmptyOrNodeStreamWebDecompressionStream = LibDomIsLoaded extends true ? {} : DecompressionStream
- type LibEmptyOrNodeStreamWebTextDecoderStream = LibDomIsLoaded extends true ? {} : TextDecoderStream
- type LibEmptyOrNodeStreamWebTextEncoderStream = LibDomIsLoaded extends true ? {} : TextEncoderStream
- type LibEmptyOrNodeUtilTextDecoder = LibDomIsLoaded extends true ? {} : TextDecoder
- type LibEmptyOrNodeUtilTextEncoder = LibDomIsLoaded extends true ? {} : TextEncoder
- type LibEmptyOrNodeWritableStream<T> = LibDomIsLoaded extends true ? {} : WritableStream
- type LibEmptyOrPerformanceEntry = LibDomIsLoaded extends true ? {} : PerformanceEntry
- type LibEmptyOrPerformanceMark = LibDomIsLoaded extends true ? {} : PerformanceMark
- type LibEmptyOrPerformanceMeasure = LibDomIsLoaded extends true ? {} : PerformanceMeasure
- type LibEmptyOrPerformanceObserver = LibDomIsLoaded extends true ? {} : PerformanceObserver
- type LibEmptyOrPerformanceObserverEntryList = LibDomIsLoaded extends true ? {} : PerformanceObserverEntryList
- type LibEmptyOrPerformanceResourceTiming = LibDomIsLoaded extends true ? {} : PerformanceResourceTiming
- type LibEmptyOrReadableByteStreamController = LibDomIsLoaded extends true ? {} : ReadableByteStreamController
- type LibEmptyOrReadableStreamBYOBReader = LibDomIsLoaded extends true ? {} : ReadableStreamBYOBReader
- type LibEmptyOrReadableStreamBYOBRequest = LibDomIsLoaded extends true ? {} : ReadableStreamBYOBRequest
- type LibOrFallbackHeaders = LibDomIsLoaded extends true ? {} : Headers
- type LibOrFallbackRequest = LibDomIsLoaded extends true ? {} : Request
- type LibOrFallbackRequestInit = LibDomIsLoaded extends true ? {} : Omit<RequestInit, 'body' | 'headers'> & { body: Bun.BodyInit | null; headers: Bun.HeadersInit }
- type LibOrFallbackResponse = LibDomIsLoaded extends true ? {} : Response
- type LibOrFallbackResponseInit = LibDomIsLoaded extends true ? {} : ResponseInit
- type LibPerformanceOrNodePerfHooksPerformance = LibDomIsLoaded extends true ? {} : Performance
- type LibWorkerOrBunWorker = LibDomIsLoaded extends true ? {} : Bun.Worker
- type Merge<A, B> = MergeInner<A, B> & MergeInner<B, A>
- type MergeInner<A, B> = Omit<A, KeysInBoth<A, B>> & Omit<B, KeysInBoth<A, B>> & { [K in KeysInBoth<A, B>]: A[Key] | B[Key] }
- type UseLibDomIfAvailable<GlobalThisKeyName extends PropertyKey, Otherwise> = LibDomIsLoaded extends true ? typeof globalThis extends { [K in GlobalThisKeyName]: infer T } ? T : Otherwise : Otherwise
Uses the lib.dom.d.ts definition of a global if it exists, otherwise falls back to
Otherwise.Some symbols can't be declared in a way that satisfies both @types/bun and lib.dom.d.ts, so when lib.dom.d.ts is loaded, its definition wins.
- type Without<A, B> = A & { [K in Exclude<keyof B, keyof A>]: never }