Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 64 additions & 12 deletions packages/bun-types/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ declare module "bun" {
type LibWorkerOrBunWorker = LibDomIsLoaded extends true ? {} : Bun.Worker;
type LibEmptyOrBunWebSocket = LibDomIsLoaded extends true ? {} : Bun.WebSocket;

type LibEmptyOrNodeStreamWebCompressionStream = LibDomIsLoaded extends true
? {}
: import("node:stream/web").CompressionStream;
type LibEmptyOrNodeStreamWebDecompressionStream = LibDomIsLoaded extends true
? {}
: import("node:stream/web").DecompressionStream;

type LibPerformanceOrNodePerfHooksPerformance = LibDomIsLoaded extends true ? {} : import("perf_hooks").Performance;
type LibEmptyOrPerformanceEntry = LibDomIsLoaded extends true ? {} : import("node:perf_hooks").PerformanceEntry;
type LibEmptyOrPerformanceMark = LibDomIsLoaded extends true ? {} : import("node:perf_hooks").PerformanceMark;
Expand Down Expand Up @@ -271,6 +278,30 @@ declare var Event: {
new (type: string, eventInitDict?: Bun.EventInit): Event;
};

/**
* Unimplemented in Bun
*/
interface CompressionStream extends Bun.__internal.LibEmptyOrNodeStreamWebCompressionStream {}
/**
* Unimplemented in Bun
*/
declare var CompressionStream: Bun.__internal.UseLibDomIfAvailable<
"CompressionStream",
typeof import("node:stream/web").CompressionStream
>;

/**
* Unimplemented in Bun
*/
interface DecompressionStream extends Bun.__internal.LibEmptyOrNodeStreamWebCompressionStream {}
/**
* Unimplemented in Bun
*/
declare var DecompressionStream: Bun.__internal.UseLibDomIfAvailable<
"DecompressionStream",
typeof import("node:stream/web").DecompressionStream
>;

interface EventTarget {
/**
* Adds a new handler for the `type` event. Any given `listener` is added only once per `type` and per `capture` option value.
Expand Down Expand Up @@ -860,7 +891,10 @@ 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. */
/**
* 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 {
readonly message: string;
readonly name: string;
Expand Down Expand Up @@ -890,11 +924,35 @@ interface DOMException extends Error {
readonly INVALID_NODE_TYPE_ERR: 24;
readonly DATA_CLONE_ERR: 25;
}

// declare var DOMException: {
// prototype: DOMException;
// new (message?: string, name?: string): DOMException;
// };
declare var DOMException: {
prototype: DOMException;
new (message?: string, name?: string): DOMException;
readonly INDEX_SIZE_ERR: 1;
readonly DOMSTRING_SIZE_ERR: 2;
readonly HIERARCHY_REQUEST_ERR: 3;
readonly WRONG_DOCUMENT_ERR: 4;
readonly INVALID_CHARACTER_ERR: 5;
readonly NO_DATA_ALLOWED_ERR: 6;
readonly NO_MODIFICATION_ALLOWED_ERR: 7;
readonly NOT_FOUND_ERR: 8;
readonly NOT_SUPPORTED_ERR: 9;
readonly INUSE_ATTRIBUTE_ERR: 10;
readonly INVALID_STATE_ERR: 11;
readonly SYNTAX_ERR: 12;
readonly INVALID_MODIFICATION_ERR: 13;
readonly NAMESPACE_ERR: 14;
readonly INVALID_ACCESS_ERR: 15;
readonly VALIDATION_ERR: 16;
readonly TYPE_MISMATCH_ERR: 17;
readonly SECURITY_ERR: 18;
readonly NETWORK_ERR: 19;
readonly ABORT_ERR: 20;
readonly URL_MISMATCH_ERR: 21;
readonly QUOTA_EXCEEDED_ERR: 22;
readonly TIMEOUT_ERR: 23;
readonly INVALID_NODE_TYPE_ERR: 24;
readonly DATA_CLONE_ERR: 25;
};

declare function alert(message?: string): void;
declare function confirm(message?: string): boolean;
Expand Down Expand Up @@ -1605,12 +1663,6 @@ declare var AbortSignal: Bun.__internal.UseLibDomIfAvailable<
}
>;

interface DOMException {}
declare var DOMException: Bun.__internal.UseLibDomIfAvailable<
"DOMException",
{ prototype: DOMException; new (): DOMException }
>;

interface FormData {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/append) */
append(name: string, value: string | Blob): void;
Expand Down
2 changes: 1 addition & 1 deletion test/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions test/integration/bun-types/fixture/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import * as nodeCrypto from "crypto";
import { expectType } from "./utilities";

nodeCrypto.webcrypto.CryptoKey;

crypto.getRandomValues(new Uint8Array(1));

// TODO(@alii): Failing with @types/node@22.15.0
Expand Down