GeezerVison is showing github.com — fix: enforce optional signature (#633) · tinylibs/tinybench@b54b73b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/bench.ts +8-3Lines changed: 8 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -146,7 +146,7 @@ export class Bench extends EventTarget implements BenchLike { | 146 | 146 | * Otherwise calibrated once at construction time via | 147 | 147 | * {@link calibrateTimerOverhead}. | 148 | 148 | */ | 149 | | - readonly timerOverhead: number | undefined | | 149 | + readonly timerOverhead?: number | 150 | 150 |
| 151 | 151 | /** | 152 | 152 | * A timestamp provider and its related functions. | @@ -221,16 +221,21 @@ export class Bench extends EventTarget implements BenchLike { | 221 | 221 | this.setup = restOptions.setup ?? emptyFunction | 222 | 222 | this.teardown = restOptions.teardown ?? emptyFunction | 223 | 223 | this.throws = restOptions.throws ?? false | 224 | | - this.signal = restOptions.signal | | 224 | + if (restOptions.signal != null) { | | 225 | + this.signal = restOptions.signal | | 226 | + } | 225 | 227 | this.retainSamples = restOptions.retainSamples === true | 226 | 228 | this.subtractTimerOverhead = restOptions.subtractTimerOverhead === true | 227 | 229 | assert( | 228 | 230 | !(this.subtractTimerOverhead && this.concurrency === 'task'), | 229 | 231 | subtractTimerOverheadConcurrencyError | 230 | 232 | ) | 231 | | - this.timerOverhead = this.subtractTimerOverhead | | 233 | + const timerOverhead = this.subtractTimerOverhead | 232 | 234 | ? calibrateTimerOverhead(this.timestampProvider) | 233 | 235 | : undefined | | 236 | + if (timerOverhead != null) { | | 237 | + this.timerOverhead = timerOverhead | | 238 | + } | 234 | 239 |
| 235 | 240 | if (this.signal) { | 236 | 241 | this.signal.addEventListener( | |
Collapse file Copy file name to clipboardExpand all lines: src/event.ts +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -69,10 +69,12 @@ class BenchEvent< | 69 | 69 | errorOrReason?: Error | TimerSaturationReason | 70 | 70 | ) { | 71 | 71 | super(type) | 72 | | - this.#task = task | | 72 | + if (task != null) { | | 73 | + this.#task = task | | 74 | + } | 73 | 75 | if (typeof errorOrReason === 'string') { | 74 | 76 | this.#reason = errorOrReason | 75 | | - } else { | | 77 | + } else if (errorOrReason != null) { | 76 | 78 | this.#error = errorOrReason | 77 | 79 | } | 78 | 80 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/task.ts +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -622,9 +622,9 @@ export class Task extends EventTarget { | 622 | 622 | latencySamples, | 623 | 623 | overriddenIndices, | 624 | 624 | }: { | 625 | | - error?: Error | 626 | | - latencySamples?: number[] | 627 | | - overriddenIndices?: Set<number> | | 625 | + error: Error | undefined | | 626 | + latencySamples: number[] | undefined | | 627 | + overriddenIndices: Set<number> | undefined | 628 | 628 | }): void { | 629 | 629 | if (isValidSamples(latencySamples)) { | 630 | 630 | this.#runs = latencySamples.length | |
Collapse file Copy file name to clipboardExpand all lines: src/utils.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -774,7 +774,7 @@ interface WithConcurrencyOptions<R> { | 774 | 774 | /** | 775 | 775 | * An optional AbortSignal to cancel the execution. | 776 | 776 | */ | 777 | | - signal?: AbortSignal | | 777 | + signal?: AbortSignal | undefined | 778 | 778 | /** | 779 | 779 | * The maximum amount of time to run the executions in milliseconds. If 0, | 780 | 780 | * runs until iterations are completed. | |
Collapse file Copy file name to clipboardExpand all lines: test/utils-default-convert-task-result-for-console-table.test.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -170,7 +170,7 @@ test('defaultConvertTaskResultForConsoleTable - errored - with stack', () => { | 170 | 170 |
| 171 | 171 | test('defaultConvertTaskResultForConsoleTable - errored - without stack', () => { | 172 | 172 | const error = new Error('Sample error') | 173 | | - error.stack = undefined | | 173 | + delete error.stack | 174 | 174 | expect( | 175 | 175 | defaultConvertTaskResultForConsoleTable({ | 176 | 176 | name: 'Sample Task', | |
Collapse file Copy file name to clipboardExpand all lines: tsconfig.json +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 11 | 11 | "erasableSyntaxOnly": true, | 12 | 12 | "noImplicitOverride": true, | 13 | 13 | "noImplicitReturns": true, | | 14 | + "exactOptionalPropertyTypes": true, | 14 | 15 | "noImplicitThis": true, | 15 | 16 | "noUncheckedIndexedAccess": true, | 16 | 17 | "noUnusedLocals": true, | |
|