fix: improve types (#423) · tinylibs/tinybench@8fbd137
11import type { BenchEvent } from '../src/event'
22import type { Task } from '../src/task'
3-import type { JSRuntime } from './utils'
43export type { BenchEvent } from '../src/event'
5465export type AddEventListenerOptionsArgument = Parameters<
@@ -22,9 +21,9 @@ export type BenchEvents =
2221| 'warmup' // when the benchmarks start getting warmed up
23222423export type BenchEventsOptionalTask = Omit<BenchEvents, 'add' | 'cycle' | 'error' | 'remove'>
24+2525export type BenchEventsWithError = Extract<BenchEvents, 'error'>
2626export type BenchEventsWithTask = Extract<BenchEvents, 'add' | 'cycle' | 'error' | 'remove'>
27-2827export interface BenchLike extends EventTarget {
2928addEventListener: <K extends BenchEvents>(
3029type: K,
@@ -144,16 +143,16 @@ export type ConsoleTableConverter = (
144143 */
145144export type EventListener<E extends BenchEvents, M extends 'bench' | 'task' = 'bench'> = (evt: BenchEvent<E, M>) => void
146145146+export interface EventListenerObject<E extends BenchEvents, M extends 'bench' | 'task' = 'bench'> {
147+handleEvent(evt: BenchEvent<E, M>): void
148+}
149+147150/**
148151 * Both the `Task` and `Bench` objects extend the `EventTarget` object.
149152 * So you can attach a listeners to different types of events to each class instance
150153 * using the universal `addEventListener` and `removeEventListener` methods.
151154 */
152155153-export interface EventListenerObject<E extends BenchEvents, M extends 'bench' | 'task' = 'bench'> {
154-handleEvent(evt: BenchEvent<E, M>): void
155-}
156-157156/**
158157 * The task function.
159158 *
@@ -243,6 +242,28 @@ export type Hook = (
243242mode?: 'run' | 'warmup'
244243) => Promise<void> | void
245244245+/**
246+ * The JavaScript runtime environment.
247+ * @see https://runtime-keys.proposal.wintercg.org/
248+ */
249+export type JSRuntime =
250+| 'browser'
251+| 'bun'
252+| 'deno'
253+| 'edge-light'
254+| 'fastly'
255+| 'hermes'
256+| 'jsc'
257+| 'lagon'
258+| 'moddable'
259+| 'netlify'
260+| 'node'
261+| 'quickjs-ng'
262+| 'spidermonkey'
263+| 'unknown'
264+| 'v8'
265+| 'workerd'
266+246267// @types/node doesn't have these types globally, and we don't want to bring "dom" lib for everyone
247268export type RemoveEventListenerOptionsArgument = Parameters<
248269typeof EventTarget.prototype.removeEventListener