bun-types 1.2.6-canary.20250325T140646 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bun.ns.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import * as BunModule from "bun";
2
+
3
+ declare global {
4
+ export import Bun = BunModule;
5
+ }
6
+
7
+ export {};
package/deprecated.d.ts CHANGED
@@ -1,71 +1,66 @@
1
1
  declare module "bun" {
2
- /**
3
- * @deprecated Renamed to `ErrorLike`
4
- */
5
- type Errorlike = ErrorLike;
6
- interface TLSOptions {
7
- /**
8
- * File path to a TLS key
9
- *
10
- * To enable TLS, this option is required.
11
- *
12
- * @deprecated since v0.6.3 - Use `key: Bun.file(path)` instead.
13
- */
14
- keyFile?: string;
15
- /**
16
- * File path to a TLS certificate
17
- *
18
- * To enable TLS, this option is required.
19
- *
20
- * @deprecated since v0.6.3 - Use `cert: Bun.file(path)` instead.
21
- */
22
- certFile?: string;
23
- /**
24
- * File path to a .pem file for a custom root CA
25
- *
26
- * @deprecated since v0.6.3 - Use `ca: Bun.file(path)` instead.
27
- */
28
- caFile?: string;
29
- }
30
- }
2
+ interface BunMessageEvent<T> {
3
+ /**
4
+ * @deprecated
5
+ */
6
+ initMessageEvent(
7
+ type: string,
8
+ bubbles?: boolean,
9
+ cancelable?: boolean,
10
+ data?: any,
11
+ origin?: string,
12
+ lastEventId?: string,
13
+ source?: null,
14
+ ): void;
15
+ }
31
16
 
32
- declare namespace NodeJS {
33
- interface Process {
34
- /**
35
- * @deprecated This is deprecated; use the "node:assert" module instead.
36
- */
37
- assert(value: unknown, message?: string | Error): asserts value;
38
- }
17
+ /**
18
+ * @deprecated Renamed to `ErrorLike`
19
+ */
20
+ type Errorlike = ErrorLike;
21
+ interface TLSOptions {
22
+ /**
23
+ * File path to a TLS key
24
+ *
25
+ * To enable TLS, this option is required.
26
+ *
27
+ * @deprecated since v0.6.3 - Use `key: Bun.file(path)` instead.
28
+ */
29
+ keyFile?: string;
30
+ /**
31
+ * File path to a TLS certificate
32
+ *
33
+ * To enable TLS, this option is required.
34
+ *
35
+ * @deprecated since v0.6.3 - Use `cert: Bun.file(path)` instead.
36
+ */
37
+ certFile?: string;
38
+ /**
39
+ * File path to a .pem file for a custom root CA
40
+ *
41
+ * @deprecated since v0.6.3 - Use `ca: Bun.file(path)` instead.
42
+ */
43
+ caFile?: string;
44
+ }
39
45
  }
40
46
 
41
- declare namespace Bun {
42
- interface MessageEvent {
43
- /** @deprecated */
44
- initMessageEvent(
45
- type: string,
46
- bubbles?: boolean,
47
- cancelable?: boolean,
48
- data?: any,
49
- origin?: string,
50
- lastEventId?: string,
51
- source?: null,
52
- ): void;
53
- }
47
+ declare namespace NodeJS {
48
+ interface Process {
49
+ /**
50
+ * @deprecated This is deprecated; use the "node:assert" module instead.
51
+ */
52
+ assert(value: unknown, message?: string | Error): asserts value;
53
+ }
54
54
  }
55
55
 
56
56
  interface CustomEvent<T = any> {
57
- /** @deprecated */
58
- initCustomEvent(
59
- type: string,
60
- bubbles?: boolean,
61
- cancelable?: boolean,
62
- detail?: T,
63
- ): void;
57
+ /** @deprecated */
58
+ initCustomEvent(type: string, bubbles?: boolean, cancelable?: boolean, detail?: T): void;
64
59
  }
65
60
 
66
61
  interface DOMException {
67
- /** @deprecated */
68
- readonly code: number;
62
+ /** @deprecated */
63
+ readonly code: number;
69
64
  }
70
65
 
71
66
  /**
package/devserver.d.ts CHANGED
@@ -1,195 +1,189 @@
1
- export {};
1
+ declare module "bun" {
2
+ type HMREventNames =
3
+ | "beforeUpdate"
4
+ | "afterUpdate"
5
+ | "beforeFullReload"
6
+ | "beforePrune"
7
+ | "invalidate"
8
+ | "error"
9
+ | "ws:disconnect"
10
+ | "ws:connect";
2
11
 
3
- declare global {
4
- namespace Bun {
5
- type HMREventNames =
6
- | "bun:ready"
7
- | "bun:beforeUpdate"
8
- | "bun:afterUpdate"
9
- | "bun:beforeFullReload"
10
- | "bun:beforePrune"
11
- | "bun:invalidate"
12
- | "bun:error"
13
- | "bun:ws:disconnect"
14
- | "bun:ws:connect";
15
-
16
- /**
17
- * The event names for the dev server
18
- */
19
- type HMREvent = `bun:${HMREventNames}` | (string & {});
20
- }
12
+ /**
13
+ * The event names for the dev server
14
+ */
15
+ type HMREvent = `bun:${HMREventNames}` | (string & {});
16
+ }
21
17
 
22
- interface ImportMeta {
23
- /**
24
- * Hot module replacement APIs. This value is `undefined` in production and
25
- * can be used in an `if` statement to check if HMR APIs are available
26
- *
27
- * ```ts
28
- * if (import.meta.hot) {
29
- * // HMR APIs are available
30
- * }
31
- * ```
32
- *
33
- * However, this check is usually not needed as Bun will dead-code-eliminate
34
- * calls to all of the HMR APIs in production builds.
35
- *
36
- * https://bun.sh/docs/bundler/hmr
37
- */
38
- hot: {
39
- /**
40
- * `import.meta.hot.data` maintains state between module instances during
41
- * hot replacement, enabling data transfer from previous to new versions.
42
- * When `import.meta.hot.data` is written to, Bun will mark this module as
43
- * capable of self-accepting (equivalent of calling `accept()`).
44
- *
45
- * @example
46
- * ```ts
47
- * const root = import.meta.hot.data.root ??= createRoot(elem);
48
- * root.render(<App />); // re-use an existing root
49
- * ```
50
- *
51
- * In production, `data` is inlined to be `{}`. This is handy because Bun
52
- * knows it can minify `{}.prop ??= value` into `value` in production.
53
- */
54
- data: any;
18
+ interface ImportMeta {
19
+ /**
20
+ * Hot module replacement APIs. This value is `undefined` in production and
21
+ * can be used in an `if` statement to check if HMR APIs are available
22
+ *
23
+ * ```ts
24
+ * if (import.meta.hot) {
25
+ * // HMR APIs are available
26
+ * }
27
+ * ```
28
+ *
29
+ * However, this check is usually not needed as Bun will dead-code-eliminate
30
+ * calls to all of the HMR APIs in production builds.
31
+ *
32
+ * https://bun.sh/docs/bundler/hmr
33
+ */
34
+ hot: {
35
+ /**
36
+ * `import.meta.hot.data` maintains state between module instances during
37
+ * hot replacement, enabling data transfer from previous to new versions.
38
+ * When `import.meta.hot.data` is written to, Bun will mark this module as
39
+ * capable of self-accepting (equivalent of calling `accept()`).
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const root = import.meta.hot.data.root ??= createRoot(elem);
44
+ * root.render(<App />); // re-use an existing root
45
+ * ```
46
+ *
47
+ * In production, `data` is inlined to be `{}`. This is handy because Bun
48
+ * knows it can minify `{}.prop ??= value` into `value` in production.
49
+ *
50
+ *
51
+ */
52
+ data: any;
55
53
 
56
- /**
57
- * Indicate that this module can be replaced simply by re-evaluating the
58
- * file. After a hot update, importers of this module will be
59
- * automatically patched.
60
- *
61
- * When `import.meta.hot.accept` is not used, the page will reload when
62
- * the file updates, and a console message shows which files were checked.
63
- *
64
- * @example
65
- * ```ts
66
- * import { getCount } from "./foo";
67
- *
68
- * console.log("count is ", getCount());
69
- *
70
- * import.meta.hot.accept();
71
- * ```
72
- */
73
- accept(): void;
54
+ /**
55
+ * Indicate that this module can be replaced simply by re-evaluating the
56
+ * file. After a hot update, importers of this module will be
57
+ * automatically patched.
58
+ *
59
+ * When `import.meta.hot.accept` is not used, the page will reload when
60
+ * the file updates, and a console message shows which files were checked.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * import { getCount } from "./foo";
65
+ *
66
+ * console.log("count is ", getCount());
67
+ *
68
+ * import.meta.hot.accept();
69
+ * ```
70
+ */
71
+ accept(): void;
74
72
 
75
- /**
76
- * Indicate that this module can be replaced by evaluating the new module,
77
- * and then calling the callback with the new module. In this mode, the
78
- * importers do not get patched. This is to match Vite, which is unable
79
- * to patch their import statements. Prefer using `import.meta.hot.accept()`
80
- * without an argument as it usually makes your code easier to understand.
81
- *
82
- * When `import.meta.hot.accept` is not used, the page will reload when
83
- * the file updates, and a console message shows which files were checked.
84
- *
85
- * @example
86
- * ```ts
87
- * export const count = 0;
88
- *
89
- * import.meta.hot.accept((newModule) => {
90
- * if (newModule) {
91
- * // newModule is undefined when SyntaxError happened
92
- * console.log('updated: count is now ', newModule.count)
93
- * }
94
- * });
95
- * ```
96
- *
97
- * In production, calls to this are dead-code-eliminated.
98
- */
99
- accept(cb: (newModule: any | undefined) => void): void;
73
+ /**
74
+ * Indicate that this module can be replaced by evaluating the new module,
75
+ * and then calling the callback with the new module. In this mode, the
76
+ * importers do not get patched. This is to match Vite, which is unable
77
+ * to patch their import statements. Prefer using `import.meta.hot.accept()`
78
+ * without an argument as it usually makes your code easier to understand.
79
+ *
80
+ * When `import.meta.hot.accept` is not used, the page will reload when
81
+ * the file updates, and a console message shows which files were checked.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * export const count = 0;
86
+ *
87
+ * import.meta.hot.accept((newModule) => {
88
+ * if (newModule) {
89
+ * // newModule is undefined when SyntaxError happened
90
+ * console.log('updated: count is now ', newModule.count)
91
+ * }
92
+ * });
93
+ * ```
94
+ *
95
+ * In production, calls to this are dead-code-eliminated.
96
+ */
97
+ accept(cb: (newModule: any | undefined) => void): void;
100
98
 
101
- /**
102
- * Indicate that a dependency's module can be accepted. When the dependency
103
- * is updated, the callback will be called with the new module.
104
- *
105
- * When `import.meta.hot.accept` is not used, the page will reload when
106
- * the file updates, and a console message shows which files were checked.
107
- *
108
- * @example
109
- * ```ts
110
- * import.meta.hot.accept('./foo', (newModule) => {
111
- * if (newModule) {
112
- * // newModule is undefined when SyntaxError happened
113
- * console.log('updated: count is now ', newModule.count)
114
- * }
115
- * });
116
- * ```
117
- */
118
- accept(specifier: string, callback: (newModule: any) => void): void;
99
+ /**
100
+ * Indicate that a dependency's module can be accepted. When the dependency
101
+ * is updated, the callback will be called with the new module.
102
+ *
103
+ * When `import.meta.hot.accept` is not used, the page will reload when
104
+ * the file updates, and a console message shows which files were checked.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * import.meta.hot.accept('./foo', (newModule) => {
109
+ * if (newModule) {
110
+ * // newModule is undefined when SyntaxError happened
111
+ * console.log('updated: count is now ', newModule.count)
112
+ * }
113
+ * });
114
+ * ```
115
+ */
116
+ accept(specifier: string, callback: (newModule: any) => void): void;
119
117
 
120
- /**
121
- * Indicate that a dependency's module can be accepted. This variant
122
- * accepts an array of dependencies, where the callback will receive
123
- * the one updated module, and `undefined` for the rest.
124
- *
125
- * When `import.meta.hot.accept` is not used, the page will reload when
126
- * the file updates, and a console message shows which files were checked.
127
- */
128
- accept(
129
- specifiers: string[],
130
- callback: (newModules: (any | undefined)[]) => void,
131
- ): void;
118
+ /**
119
+ * Indicate that a dependency's module can be accepted. This variant
120
+ * accepts an array of dependencies, where the callback will receive
121
+ * the one updated module, and `undefined` for the rest.
122
+ *
123
+ * When `import.meta.hot.accept` is not used, the page will reload when
124
+ * the file updates, and a console message shows which files were checked.
125
+ */
126
+ accept(specifiers: string[], callback: (newModules: (any | undefined)[]) => void): void;
132
127
 
133
- /**
134
- * Attach an on-dispose callback. This is called:
135
- * - Just before the module is replaced with another copy (before the next is loaded)
136
- * - After the module is detached (removing all imports to this module)
137
- *
138
- * This callback is not called on route navigation or when the browser tab closes.
139
- *
140
- * Returning a promise will delay module replacement until the module is
141
- * disposed. All dispose callbacks are called in parallel.
142
- */
143
- dispose(cb: (data: any) => void | Promise<void>): void;
128
+ /**
129
+ * Attach an on-dispose callback. This is called:
130
+ * - Just before the module is replaced with another copy (before the next is loaded)
131
+ * - After the module is detached (removing all imports to this module)
132
+ *
133
+ * This callback is not called on route navigation or when the browser tab closes.
134
+ *
135
+ * Returning a promise will delay module replacement until the module is
136
+ * disposed. All dispose callbacks are called in parallel.
137
+ */
138
+ dispose(cb: (data: any) => void | Promise<void>): void;
144
139
 
145
- /**
146
- * No-op
147
- * @deprecated
148
- */
149
- decline(): void;
140
+ /**
141
+ * No-op
142
+ * @deprecated
143
+ */
144
+ decline(): void;
150
145
 
151
- // NOTE TO CONTRIBUTORS ////////////////////////////////////////
152
- // Callback is currently never called for `.prune()` //
153
- // so the types are commented out until we support it. //
154
- ////////////////////////////////////////////////////////////////
155
- // /**
156
- // * Attach a callback that is called when the module is removed from the module graph.
157
- // *
158
- // * This can be used to clean up resources that were created when the module was loaded.
159
- // * Unlike `import.meta.hot.dispose()`, this pairs much better with `accept` and `data` to manage stateful resources.
160
- // *
161
- // * @example
162
- // * ```ts
163
- // * export const ws = (import.meta.hot.data.ws ??= new WebSocket(location.origin));
164
- // *
165
- // * import.meta.hot.prune(() => {
166
- // * ws.close();
167
- // * });
168
- // * ```
169
- // */
170
- // prune(callback: () => void): void;
146
+ // NOTE TO CONTRIBUTORS ////////////////////////////////////////
147
+ // Callback is currently never called for `.prune()` //
148
+ // so the types are commented out until we support it. //
149
+ ////////////////////////////////////////////////////////////////
150
+ // /**
151
+ // * Attach a callback that is called when the module is removed from the module graph.
152
+ // *
153
+ // * This can be used to clean up resources that were created when the module was loaded.
154
+ // * Unlike `import.meta.hot.dispose()`, this pairs much better with `accept` and `data` to manage stateful resources.
155
+ // *
156
+ // * @example
157
+ // * ```ts
158
+ // * export const ws = (import.meta.hot.data.ws ??= new WebSocket(location.origin));
159
+ // *
160
+ // * import.meta.hot.prune(() => {
161
+ // * ws.close();
162
+ // * });
163
+ // * ```
164
+ // */
165
+ // prune(callback: () => void): void;
171
166
 
172
- /**
173
- * Listen for an event from the dev server
174
- *
175
- * For compatibility with Vite, event names are also available via vite:* prefix instead of bun:*.
176
- *
177
- * https://bun.sh/docs/bundler/hmr#import-meta-hot-on-and-off
178
- * @param event The event to listen to
179
- * @param callback The callback to call when the event is emitted
180
- */
181
- on(event: Bun.HMREvent, callback: () => void): void;
167
+ /**
168
+ * Listen for an event from the dev server
169
+ *
170
+ * For compatibility with Vite, event names are also available via vite:* prefix instead of bun:*.
171
+ *
172
+ * https://bun.sh/docs/bundler/hmr#import-meta-hot-on-and-off
173
+ * @param event The event to listen to
174
+ * @param callback The callback to call when the event is emitted
175
+ */
176
+ on(event: Bun.HMREvent, callback: () => void): void;
182
177
 
183
- /**
184
- * Stop listening for an event from the dev server
185
- *
186
- * For compatibility with Vite, event names are also available via vite:* prefix instead of bun:*.
187
- *
188
- * https://bun.sh/docs/bundler/hmr#import-meta-hot-on-and-off
189
- * @param event The event to stop listening to
190
- * @param callback The callback to stop listening to
191
- */
192
- off(event: Bun.HMREvent, callback: () => void): void;
193
- };
194
- }
178
+ /**
179
+ * Stop listening for an event from the dev server
180
+ *
181
+ * For compatibility with Vite, event names are also available via vite:* prefix instead of bun:*.
182
+ *
183
+ * https://bun.sh/docs/bundler/hmr#import-meta-hot-on-and-off
184
+ * @param event The event to stop listening to
185
+ * @param callback The callback to stop listening to
186
+ */
187
+ off(event: Bun.HMREvent, callback: () => void): void;
188
+ };
195
189
  }