Skip to content

Commit

Permalink
fix: types2
Browse files Browse the repository at this point in the history
  • Loading branch information
poyoho committed Aug 29, 2022
1 parent 9d7b5be commit 840978d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Expand Up @@ -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",
Expand Down
15 changes: 9 additions & 6 deletions 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
Expand All @@ -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;
Expand Down Expand Up @@ -108,15 +111,15 @@ export default class Bench extends EventTarget {
}

addEventListener(
type: IBenchEvents,
type: BenchEvents,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
) {
super.addEventListener(type, listener, options);
}

removeEventListener(
type: IBenchEvents,
type: BenchEvents,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
) {
Expand All @@ -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);
}

Expand Down
5 changes: 4 additions & 1 deletion 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);
Expand Down
9 changes: 5 additions & 4 deletions 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;
13 changes: 8 additions & 5 deletions src/task.ts
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -163,15 +166,15 @@ export default class Task extends EventTarget {
}

addEventListener(
type: ITaskEvents,
type: TaskEvents,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
) {
super.addEventListener(type, listener, options);
}

removeEventListener(
type: ITaskEvents,
type: TaskEvents,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
) {
Expand All @@ -181,8 +184,8 @@ export default class Task extends EventTarget {
/**
* change the result object values
*/
setResult(result: Partial<ITaskResult>) {
this.result = { ...this.result, ...result } as ITaskResult;
setResult(result: Partial<TaskResult>) {
this.result = { ...this.result, ...result } as TaskResult;
Object.freeze(this.reset);
}

Expand Down

0 comments on commit 840978d

Please sign in to comment.