Skip to content

Commit d35969e

Browse files
committed
Wrap types in global
1 parent 448aacd commit d35969e

16 files changed

Lines changed: 1347 additions & 1259 deletions

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ bun add -d @openworkers/workers-types
1010

1111
## Usage
1212

13+
### Exclusive mode (recommended)
14+
1315
Add to your `tsconfig.json`:
1416

1517
```json
@@ -20,7 +22,23 @@ Add to your `tsconfig.json`:
2022
}
2123
```
2224

23-
Or use a triple-slash directive:
25+
This includes only OpenWorkers types and excludes conflicting types (like `@types/node` or `@types/bun`). Best for pure worker projects.
26+
27+
### Compatible mode
28+
29+
If you need to mix with Node.js or Bun types, just install the package without configuring `types`. The types will merge with existing globals:
30+
31+
```json
32+
{
33+
"compilerOptions": {
34+
// no "types" array - all @types/* are included
35+
}
36+
}
37+
```
38+
39+
### Triple-slash directive
40+
41+
For per-file control:
2442

2543
```typescript
2644
/// <reference no-default-lib="true" />
@@ -30,6 +48,7 @@ Or use a triple-slash directive:
3048

3149
## Structure
3250

51+
- `types/globals.d.ts` - globalThis, self
3352
- `types/fetch.d.ts` - Request, Response, Headers, fetch
3453
- `types/url.d.ts` - URL, URLSearchParams
3554
- `types/streams.d.ts` - ReadableStream, WritableStream

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// OpenWorkers Runtime Types
22

3+
/// <reference path="./types/globals.d.ts" />
34
/// <reference path="./types/events.d.ts" />
45
/// <reference path="./types/abort.d.ts" />
56
/// <reference path="./types/streams.d.ts" />

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openworkers/workers-types",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "TypeScript types for the OpenWorkers runtime",
55
"license": "MIT",
66
"repository": {

types/abort.d.ts

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
// AbortController API types
22

3-
/**
4-
* A signal object that allows you to communicate with an async operation
5-
* and abort it if required via an AbortController.
6-
*/
7-
interface AbortSignal extends EventTarget {
8-
/** Returns true if the signal has been aborted. */
9-
readonly aborted: boolean;
10-
/** The reason for aborting, if any. */
11-
readonly reason: unknown;
12-
/** Throws the abort reason if the signal has been aborted. */
13-
throwIfAborted(): void;
14-
}
3+
export {};
4+
5+
declare global {
6+
/**
7+
* A signal object that allows you to communicate with an async operation
8+
* and abort it if required via an AbortController.
9+
*/
10+
interface AbortSignal extends EventTarget {
11+
/** Returns true if the signal has been aborted. */
12+
readonly aborted: boolean;
13+
14+
/** The reason for aborting, if any. */
15+
readonly reason: unknown;
16+
17+
/** Throws the abort reason if the signal has been aborted. */
18+
throwIfAborted(): void;
19+
}
20+
21+
/**
22+
* A controller object that allows you to abort one or more async operations.
23+
*
24+
* @example
25+
* ```ts
26+
* const controller = new AbortController();
27+
* fetch(url, { signal: controller.signal });
28+
* controller.abort(); // Cancels the fetch
29+
* ```
30+
*/
31+
class AbortController {
32+
/** The AbortSignal associated with this controller. */
33+
readonly signal: AbortSignal;
1534

16-
/**
17-
* A controller object that allows you to abort one or more async operations.
18-
*
19-
* @example
20-
* ```ts
21-
* const controller = new AbortController();
22-
* fetch(url, { signal: controller.signal });
23-
* controller.abort(); // Cancels the fetch
24-
* ```
25-
*/
26-
declare class AbortController {
27-
/** The AbortSignal associated with this controller. */
28-
readonly signal: AbortSignal;
29-
/** Aborts the associated signal with an optional reason. */
30-
abort(reason?: unknown): void;
35+
/** Aborts the associated signal with an optional reason. */
36+
abort(reason?: unknown): void;
37+
}
3138
}

0 commit comments

Comments
 (0)