Skip to content
Merged
3 changes: 2 additions & 1 deletion bun.lock

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
},
"resolutions": {
"bun-types": "workspace:packages/bun-types",
"@types/bun": "workspace:packages/@types/bun"
"@types/bun": "workspace:packages/@types/bun",
"@types/node": "25.0.0"
},
"scripts": {
"build": "bun --silent run build:debug",
Expand Down
17 changes: 13 additions & 4 deletions packages/bun-types/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
declare module "bun" {
namespace __internal {
type NodeCryptoWebcryptoSubtleCrypto = import("crypto").webcrypto.SubtleCrypto;
type NodeCryptoWebcryptoCryptoKey = import("crypto").webcrypto.CryptoKey;
type NodeCryptoWebcryptoCryptoKeyPair = import("crypto").webcrypto.CryptoKeyPair;

type LibEmptyOrNodeCryptoWebcryptoSubtleCrypto = LibDomIsLoaded extends true
? {}
: import("crypto").webcrypto.SubtleCrypto;

type LibWorkerOrBunWorker = LibDomIsLoaded extends true ? {} : Bun.Worker;
type LibEmptyOrBunWebSocket = LibDomIsLoaded extends true ? {} : Bun.WebSocket;

Expand All @@ -14,7 +17,9 @@ declare module "bun" {
? {}
: import("node:stream/web").DecompressionStream;

type LibPerformanceOrNodePerfHooksPerformance = LibDomIsLoaded extends true ? {} : import("perf_hooks").Performance;
type LibPerformanceOrNodePerfHooksPerformance = LibDomIsLoaded extends true
? {}
: import("node:perf_hooks").Performance;
type LibEmptyOrPerformanceEntry = LibDomIsLoaded extends true ? {} : import("node:perf_hooks").PerformanceEntry;
type LibEmptyOrPerformanceMark = LibDomIsLoaded extends true ? {} : import("node:perf_hooks").PerformanceMark;
type LibEmptyOrPerformanceMeasure = LibDomIsLoaded extends true ? {} : import("node:perf_hooks").PerformanceMeasure;
Expand Down Expand Up @@ -224,7 +229,7 @@ interface TextEncoder extends Bun.__internal.LibEmptyOrNodeUtilTextEncoder {
* @param src The text to encode.
* @param dest The array to hold the encode result.
*/
encodeInto(src?: string, dest?: Bun.BufferSource): import("util").EncodeIntoResult;
encodeInto(src?: string, dest?: Bun.BufferSource): import("node:util").TextEncoderEncodeIntoResult;
}
declare var TextEncoder: Bun.__internal.UseLibDomIfAvailable<
"TextEncoder",
Expand Down Expand Up @@ -952,7 +957,7 @@ declare function alert(message?: string): void;
declare function confirm(message?: string): boolean;
declare function prompt(message?: string, _default?: string): string | null;

interface SubtleCrypto extends Bun.__internal.NodeCryptoWebcryptoSubtleCrypto {}
interface SubtleCrypto extends Bun.__internal.LibEmptyOrNodeCryptoWebcryptoSubtleCrypto {}
declare var SubtleCrypto: {
prototype: SubtleCrypto;
new (): SubtleCrypto;
Expand Down Expand Up @@ -1688,6 +1693,10 @@ declare var EventSource: Bun.__internal.UseLibDomIfAvailable<

interface Performance extends Bun.__internal.LibPerformanceOrNodePerfHooksPerformance {}
declare var performance: Bun.__internal.UseLibDomIfAvailable<"performance", Performance>;
declare var Performance: Bun.__internal.UseLibDomIfAvailable<
"Performance",
{ new (): Performance; prototype: Performance }
>;

interface PerformanceEntry extends Bun.__internal.LibEmptyOrPerformanceEntry {}
declare var PerformanceEntry: Bun.__internal.UseLibDomIfAvailable<
Expand Down
19 changes: 17 additions & 2 deletions packages/bun-types/overrides.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,11 @@ declare global {
}
}

declare module "fs/promises" {
declare module "node:fs/promises" {
function exists(path: Bun.PathLike): Promise<boolean>;
}

declare module "tls" {
declare module "node:tls" {
interface BunConnectionOptions extends Omit<ConnectionOptions, "key" | "ca" | "tls" | "cert"> {
/**
* Optionally override the trusted CA certificates. Default is to trust
Expand Down Expand Up @@ -359,3 +359,18 @@ declare module "tls" {

function connect(options: BunConnectionOptions, secureConnectListener?: () => void): TLSSocket;
}

declare module "console" {
interface Console {
/**
* Asynchronously read lines from standard input (fd 0)
*
* ```ts
* for await (const line of console) {
* console.log(line);
* }
* ```
*/
[Symbol.asyncIterator](): AsyncIterableIterator<string>;
}
}
18 changes: 10 additions & 8 deletions packages/bun-types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ declare module "bun:test" {
}

namespace __internal {
type IfNeverThenElse<T, Else> = [T] extends [never] ? Else : T;

type IsTuple<T> = T extends readonly unknown[]
? number extends T["length"]
? false // It's an array with unknown length, not a tuple
Expand Down Expand Up @@ -1097,8 +1099,8 @@ declare module "bun:test" {
*
* @param expected the expected value
*/
toContainKey(expected: keyof T): void;
toContainKey<X = T>(expected: NoInfer<keyof X>): void;
toContainKey(expected: __internal.IfNeverThenElse<keyof T, PropertyKey>): void;
toContainKey<X = T>(expected: __internal.IfNeverThenElse<NoInfer<keyof X>, PropertyKey>): void;

/**
* Asserts that an `object` contains all the provided keys.
Expand All @@ -1114,8 +1116,8 @@ declare module "bun:test" {
*
* @param expected the expected value
*/
toContainAllKeys(expected: Array<keyof T>): void;
toContainAllKeys<X = T>(expected: NoInfer<Array<keyof X>>): void;
toContainAllKeys(expected: Array<__internal.IfNeverThenElse<keyof T, PropertyKey>>): void;
toContainAllKeys<X = T>(expected: Array<__internal.IfNeverThenElse<NoInfer<keyof X>, PropertyKey>>): void;

/**
* Asserts that an `object` contains at least one of the provided keys.
Expand All @@ -1131,8 +1133,8 @@ declare module "bun:test" {
*
* @param expected the expected value
*/
toContainAnyKeys(expected: Array<keyof T>): void;
toContainAnyKeys<X = T>(expected: NoInfer<Array<keyof X>>): void;
toContainAnyKeys(expected: Array<__internal.IfNeverThenElse<keyof T, PropertyKey>>): void;
toContainAnyKeys<X = T>(expected: Array<__internal.IfNeverThenElse<NoInfer<keyof X>, PropertyKey>>): void;

/**
* Asserts that an `object` contain the provided value.
Expand Down Expand Up @@ -1224,8 +1226,8 @@ declare module "bun:test" {
*
* @param expected the expected value
*/
toContainKeys(expected: Array<keyof T>): void;
toContainKeys<X = T>(expected: NoInfer<Array<keyof X>>): void;
toContainKeys(expected: Array<__internal.IfNeverThenElse<keyof T, PropertyKey>>): void;
toContainKeys<X = T>(expected: Array<__internal.IfNeverThenElse<NoInfer<keyof X>, PropertyKey>>): void;

/**
* Asserts that a value contains and equals what is expected.
Expand Down
19 changes: 8 additions & 11 deletions test/bun.lock

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

7 changes: 5 additions & 2 deletions test/integration/bun-types/bun-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ afterAll(async () => {
if (TEMP_DIR) {
if (Bun.env.TYPES_INTEGRATION_TEST_KEEP_TEMP_DIR === "true") {
console.log(`Keeping temp dir ${TEMP_DIR}/fixture for debugging`);
await cp(TSCONFIG_SOURCE_PATH, join(TEMP_DIR, "fixture", "tsconfig.json"));
// Write tsconfig with skipLibCheck disabled for proper type checking
const tsconfig = structuredClone(sourceTsconfig);
tsconfig.compilerOptions.skipLibCheck = false;
await Bun.write(join(TEMP_DIR, "fixture", "tsconfig.json"), JSON.stringify(tsconfig, null, 2));
Comment thread
alii marked this conversation as resolved.
} else {
await rm(TEMP_DIR, { recursive: true, force: true });
}
Expand Down Expand Up @@ -435,7 +438,7 @@ describe("@types/bun integration test", () => {
code: 2322,
line: "24154.ts:11:3",
message:
"Type 'Blob' is not assignable to type 'import(\"buffer\").Blob'.\nThe types returned by 'stream()' are incompatible between these types.\nType 'ReadableStream<Uint8Array<ArrayBuffer>>' is missing the following properties from type 'ReadableStream<any>': blob, text, bytes, json",
"Type 'Blob' is not assignable to type 'import(\"node:buffer\").Blob'.\nThe types returned by 'stream()' are incompatible between these types.\nType 'ReadableStream<Uint8Array<ArrayBuffer>>' is missing the following properties from type 'ReadableStream<NonSharedUint8Array>': blob, text, bytes, json",
},
{
code: 2769,
Expand Down
1 change: 1 addition & 0 deletions test/integration/bun-types/fixture/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ async () => {
for await (const line of c2) {
console.log("Received:", line);
}

// tslint:disable-next-line:await-promise
for await (const line of console) {
console.log("Received:", line);
Expand Down
Loading