Skip to content

Commit 2c51349

Browse files
committed
fix: bundle event listener typings
1 parent 340ec41 commit 2c51349

File tree

6 files changed

+67
-198
lines changed

6 files changed

+67
-198
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ setTimeout(() => {
7171
}, 10_000)
7272
```
7373

74+
### TypeScript
75+
76+
Make sure you have configured your TSConfig so it matches the environment you are targetting. If you are targetting browsers, this would be `dom`:
77+
78+
```jsonc
79+
{
80+
"compilerOptions": {
81+
"lib": ["dom"],
82+
},
83+
}
84+
```
85+
86+
If you're using Node.js, ensure you have `@types/node` installed (and it is version 18 or higher). Cloudflare workers have `@cloudflare/workers-types` etc.
87+
7488
## Migrating from v1 / v2
7589

7690
See [MIGRATION.md](MIGRATION.md#v2-to-v3) for a detailed migration guide.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"./package.json": "./package.json"
2020
},
2121
"scripts": {
22-
"build": "pkg-utils build && pkg-utils --strict && tsx scripts/referenceEventTypings.ts",
22+
"build": "pkg-utils build && pkg-utils --strict",
2323
"build:watch": "pkg-utils watch",
2424
"clean": "rimraf dist coverage",
2525
"lint": "eslint . && tsc --noEmit",

scripts/referenceEventTypings.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/EventSource.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import {createParser, type EventSourceMessage, type EventSourceParser} from 'eve
22

33
import {ErrorEvent, syntaxError} from './errors.js'
44
import type {
5+
AddEventListenerOptions,
6+
EventListenerOptions,
7+
EventListenerOrEventListenerObject,
58
EventSourceEventMap,
69
EventSourceInit,
710
FetchLike,

src/events.d.ts

Lines changed: 0 additions & 152 deletions
This file was deleted.

src/types.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,52 @@ export interface EventSourceInit {
8686
*/
8787
fetch?: FetchLike
8888
}
89+
90+
/**
91+
* Mirrors the official DOM typings (sorta).
92+
*
93+
* @public
94+
*/
95+
export interface EventListenerOptions {
96+
/** Not directly used by Node.js. Added for API completeness. Default: `false`. */
97+
capture?: boolean
98+
}
99+
100+
/**
101+
* Mirrors the official DOM typings (sorta).
102+
*
103+
* @public
104+
*/
105+
export interface AddEventListenerOptions extends EventListenerOptions {
106+
/** When `true`, the listener is automatically removed when it is first invoked. Default: `false`. */
107+
once?: boolean
108+
/** When `true`, serves as a hint that the listener will not call the `Event` object's `preventDefault()` method. Default: false. */
109+
passive?: boolean
110+
/** The listener will be removed when the given AbortSignal object's `abort()` method is called. */
111+
signal?: AbortSignal
112+
}
113+
114+
/**
115+
* Mirrors the official DOM typings.
116+
*
117+
* @public
118+
*/
119+
export type EventListenerOrEventListenerObject = EventListener | EventListenerObject
120+
121+
/**
122+
* Mirrors the official DOM typings.
123+
*
124+
* @public
125+
*/
126+
export interface EventListener {
127+
(evt: Event | MessageEvent): void
128+
}
129+
130+
/**
131+
* Mirrors the official DOM typings.
132+
*
133+
* @public
134+
*/
135+
export interface EventListenerObject {
136+
handleEvent(object: Event): void
137+
}

0 commit comments

Comments
 (0)