Skip to content

Commit

Permalink
fix: bundle event listener typings
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Jan 27, 2025
1 parent 340ec41 commit 2c51349
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 198 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ setTimeout(() => {
}, 10_000)
```

### TypeScript

Make sure you have configured your TSConfig so it matches the environment you are targetting. If you are targetting browsers, this would be `dom`:

```jsonc
{
"compilerOptions": {
"lib": ["dom"],
},
}
```

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.

## Migrating from v1 / v2

See [MIGRATION.md](MIGRATION.md#v2-to-v3) for a detailed migration guide.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"./package.json": "./package.json"
},
"scripts": {
"build": "pkg-utils build && pkg-utils --strict && tsx scripts/referenceEventTypings.ts",
"build": "pkg-utils build && pkg-utils --strict",
"build:watch": "pkg-utils watch",
"clean": "rimraf dist coverage",
"lint": "eslint . && tsc --noEmit",
Expand Down
45 changes: 0 additions & 45 deletions scripts/referenceEventTypings.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/EventSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import {createParser, type EventSourceMessage, type EventSourceParser} from 'eve

import {ErrorEvent, syntaxError} from './errors.js'
import type {
AddEventListenerOptions,
EventListenerOptions,
EventListenerOrEventListenerObject,
EventSourceEventMap,
EventSourceInit,
FetchLike,
Expand Down
152 changes: 0 additions & 152 deletions src/events.d.ts

This file was deleted.

49 changes: 49 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,52 @@ export interface EventSourceInit {
*/
fetch?: FetchLike
}

/**
* Mirrors the official DOM typings (sorta).
*
* @public
*/
export interface EventListenerOptions {
/** Not directly used by Node.js. Added for API completeness. Default: `false`. */
capture?: boolean
}

/**
* Mirrors the official DOM typings (sorta).
*
* @public
*/
export interface AddEventListenerOptions extends EventListenerOptions {
/** When `true`, the listener is automatically removed when it is first invoked. Default: `false`. */
once?: boolean
/** When `true`, serves as a hint that the listener will not call the `Event` object's `preventDefault()` method. Default: false. */
passive?: boolean
/** The listener will be removed when the given AbortSignal object's `abort()` method is called. */
signal?: AbortSignal
}

/**
* Mirrors the official DOM typings.
*
* @public
*/
export type EventListenerOrEventListenerObject = EventListener | EventListenerObject

/**
* Mirrors the official DOM typings.
*
* @public
*/
export interface EventListener {
(evt: Event | MessageEvent): void
}

/**
* Mirrors the official DOM typings.
*
* @public
*/
export interface EventListenerObject {
handleEvent(object: Event): void
}

0 comments on commit 2c51349

Please sign in to comment.