Skip to content

Commit d78e6a5

Browse files
authored
fix: remove DOM-related types to make tinybench environment agnostic (#58)
1 parent dfb6ef5 commit d78e6a5

File tree

6 files changed

+56
-37
lines changed

6 files changed

+56
-37
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"build": "tsup",
99
"prepare": "git config core.hooksPath .hooks",
1010
"publish": "npm run build && clean-publish",
11+
"typecheck": "tsc --noEmit",
1112
"release": "bumpp package.json --commit --push --tag && npm run publish",
1213
"test": "vitest --no-threads"
1314
},
@@ -40,7 +41,7 @@
4041
"nano-staged": "^0.5.0",
4142
"size-limit": "^7.0.8",
4243
"tsup": "^5.11.7",
43-
"typescript": "^4.5.4",
44+
"typescript": "^5.2.2",
4445
"vite": "^2.9.12",
4546
"vitest": "^0.14.2"
4647
},

pnpm-lock.yaml

Lines changed: 40 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bench.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
} from '../types/index';
1010
import { createBenchEvent } from './event';
1111
import Task from './task';
12+
import { AddEventListenerOptionsArgument, RemoveEventListenerOptionsArgument } from './types';
1213
import { now } from './utils';
1314

1415
/**
@@ -134,15 +135,15 @@ export default class Bench extends EventTarget {
134135
addEventListener<K extends BenchEvents, T = BenchEventsMap[K]>(
135136
type: K,
136137
listener: T,
137-
options?: boolean | AddEventListenerOptions,
138+
options?: AddEventListenerOptionsArgument,
138139
): void {
139140
super.addEventListener(type as string, listener as any, options);
140141
}
141142

142143
removeEventListener<K extends BenchEvents, T = BenchEventsMap[K]>(
143144
type: K,
144145
listener: T,
145-
options?: boolean | EventListenerOptions,
146+
options?: RemoveEventListenerOptionsArgument,
146147
) {
147148
super.removeEventListener(type as string, listener as any, options);
148149
}

src/task.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
import Bench from './bench';
99
import tTable from './constants';
1010
import { createBenchEvent } from './event';
11+
import { AddEventListenerOptionsArgument, RemoveEventListenerOptionsArgument } from './types';
1112
import { getMean, getVariance, isAsyncTask } from './utils';
1213

1314
/**
@@ -247,15 +248,15 @@ export default class Task extends EventTarget {
247248
addEventListener<K extends TaskEvents, T = TaskEventsMap[K]>(
248249
type: K,
249250
listener: T,
250-
options?: boolean | AddEventListenerOptions,
251+
options?: AddEventListenerOptionsArgument,
251252
) {
252253
super.addEventListener(type, listener as any, options);
253254
}
254255

255256
removeEventListener<K extends TaskEvents, T = TaskEventsMap[K]>(
256257
type: K,
257258
listener: T,
258-
options?: boolean | EventListenerOptions,
259+
options?: RemoveEventListenerOptionsArgument,
259260
) {
260261
super.removeEventListener(type, listener as any, options);
261262
}

src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @types/node doesn't have these types globally, and we don't want to bring "dom" lib for everyone
2+
3+
export type RemoveEventListenerOptionsArgument = Parameters<typeof EventTarget.prototype.removeEventListener>[2];
4+
export type AddEventListenerOptionsArgument = Parameters<typeof EventTarget.prototype.addEventListener>[2];

tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
"esModuleInterop": true,
77
"moduleResolution": "node",
88
"noUncheckedIndexedAccess": true,
9-
"baseUrl": "."
9+
"baseUrl": ".",
10+
"skipLibCheck": true,
11+
"lib": []
1012
},
1113
"include": ["src", "test", "@types"],
1214
"exclude": ["node_modules", "dist"],
1315
"removeComments": true,
14-
"newLine": "lf",
16+
"newLine": "lf"
1517
}

0 commit comments

Comments
 (0)