diff --git a/.eslintrc.json b/.eslintrc.json index d2c4143..aadacd6 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -17,6 +17,9 @@ "commonjs": true }, "rules": { + "no-restricted-syntax": "off", + "no-await-in-loop": "off", + "@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/interface-name-prefix": "off", "@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/no-explicit-any": "off", diff --git a/src/bench.ts b/src/bench.ts index 0f322d7..03758a7 100644 --- a/src/bench.ts +++ b/src/bench.ts @@ -1,6 +1,9 @@ import { createBenchEvent } from './event'; import Task from './task'; import { now } from './utils'; +import type { + Hook, Options, Fn, BenchEvents, TaskResult, +} from '../@types'; /** * The Benchmark instance for keeping track of the benchmark tasks and controlling @@ -21,11 +24,11 @@ export default class Bench extends EventTarget { now = now; - setup: IHook; + setup: Hook; - teardown: IHook; + teardown: Hook; - constructor(options: IOptions = {}) { + constructor(options: Options = {}) { super(); this.now = options.now ?? this.now; this.warmupTime = options.warmupTime ?? this.warmupTime; @@ -108,7 +111,7 @@ export default class Bench extends EventTarget { } addEventListener( - type: IBenchEvents, + type: BenchEvents, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions, ) { @@ -116,7 +119,7 @@ export default class Bench extends EventTarget { } removeEventListener( - type: IBenchEvents, + type: BenchEvents, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions, ) { @@ -126,7 +129,7 @@ export default class Bench extends EventTarget { /** * (getter) tasks results as an array */ - get results(): (ITaskResult | undefined)[] { + get results(): (TaskResult | undefined)[] { return [...this.#tasks.values()].map((task) => task.result); } diff --git a/src/event.ts b/src/event.ts index 6f9c8d8..84de256 100644 --- a/src/event.ts +++ b/src/event.ts @@ -1,7 +1,10 @@ import Task from './task'; +import type { + BenchEvents, +} from '../@types'; function createBenchEvent( - eventType: IBenchEvents, + eventType: BenchEvents, target: Task | null = null, ) { const event = new Event(eventType); diff --git a/src/index.ts b/src/index.ts index 8e5dbbd..22767de 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,9 @@ -export type {} from "../@types/index"; -import Bench from "./bench"; -import Task from "./task"; +import Bench from './bench'; +import Task from './task'; -export { now } from "./utils"; +export type {} from '../@types/index'; + +export { now } from './utils'; export { Bench, Task }; export default Bench; diff --git a/src/task.ts b/src/task.ts index 2e4b2ea..29cefdf 100644 --- a/src/task.ts +++ b/src/task.ts @@ -2,6 +2,9 @@ import Bench from './bench'; import tTable from './constants'; import { createBenchEvent } from './event'; import { getMean, getVariance } from './utils'; +import type { + Fn, TaskResult, TaskEvents, +} from '../@types'; /** * A class that represents each benchmark task in Tinybench. It keeps track of the @@ -27,7 +30,7 @@ export default class Task extends EventTarget { /** * the result object */ - result?: ITaskResult; + result?: TaskResult; constructor(bench: Bench, name: string, fn: Fn) { super(); @@ -163,7 +166,7 @@ export default class Task extends EventTarget { } addEventListener( - type: ITaskEvents, + type: TaskEvents, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions, ) { @@ -171,7 +174,7 @@ export default class Task extends EventTarget { } removeEventListener( - type: ITaskEvents, + type: TaskEvents, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions, ) { @@ -181,8 +184,8 @@ export default class Task extends EventTarget { /** * change the result object values */ - setResult(result: Partial) { - this.result = { ...this.result, ...result } as ITaskResult; + setResult(result: Partial) { + this.result = { ...this.result, ...result } as TaskResult; Object.freeze(this.reset); }