Skip to content

fix(types): support non-DOM runtime declarations - #659

Merged
jerome-benoit merged 1 commit into
tinylibs:mainfrom
jerome-benoit:fix/non-dom-declaration-compatibility
Sep 5, 2026
Merged

fix(types): support non-DOM runtime declarations#659
jerome-benoit merged 1 commit into
tinylibs:mainfrom
jerome-benoit:fix/non-dom-declaration-compatibility

Conversation

@jerome-benoit

Copy link
Copy Markdown
Collaborator

Summary

  • make the emitted BenchEvent declaration compatible with runtimes whose Event constructor is not exposed through typeof globalThis
  • type performanceNow as the existing NowFn contract so the declaration returns number instead of leaking DOMHighResTimeStamp
  • compile the emitted bundle against Workerd types with skipLibCheck: false, while preserving the literal BenchEvent.type contract

Root cause

Two source-level DOM details leaked into the public declaration bundle:

  1. BenchEvent extends globalThis.Event was emitted verbatim. Wrangler-generated Workerd declarations provide the global Event type, but do not expose Event as a property of typeof globalThis.
  2. performance.now.bind(...) had no explicit annotation, so TypeScript inferred the DOM alias DOMHighResTimeStamp instead of Tinybench's runtime-neutral NowFn return type.

The existing Workerd consumer inherited skipLibCheck: true from the root configuration. It validated listener call sites but did not validate dist/index.d.ts, allowing both ambient-type leaks through. These two diagnostics predated and were explicitly out of scope for #646.

Design

  • expose an EventBase construct signature that omits only the base type member, then retain BenchEvent<K>["type"] as K
  • annotate performanceNow with NowFn; runtime behavior stays unchanged
  • override skipLibCheck in the permanent Workerd declaration consumer

Verification

  • exact issue fixture, Wrangler 4.129.0 / TypeScript 6.0.3: two diagnostics before, zero after
  • pnpm typecheck:workerd
  • pnpm test — 64 files, 243 tests passed
  • pnpm typecheck
  • pnpm lint
  • pnpm lint:typedoc
  • pnpm build

Closes #658.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-05T12:01:07.795708Z 393ab16 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Sep 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/tinybench@659

commit: 393ab16

Co-authored-by: michalius <48828911+michalius@users.noreply.github.com>
@jerome-benoit
jerome-benoit force-pushed the fix/non-dom-declaration-compatibility branch from ba030b6 to 393ab16 Compare September 5, 2026 11:58
@jerome-benoit
jerome-benoit merged commit 7c278a6 into tinylibs:main Sep 5, 2026
30 checks passed
@jerome-benoit
jerome-benoit deleted the fix/non-dom-declaration-compatibility branch September 5, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tinybench@6.1.5 declarations require globalThis.Event and DOMHighResTimeStamp with Wrangler-generated Workerd types

1 participant