Skip to content

feat: destroy(), cancellable fades, honest types and tsrs type checking - #81

Merged
jonataswalker merged 8 commits into
masterfrom
feat/destroy-types-tsrs
Nov 17, 2026
Merged

jonataswalker merged 8 commits into
masterfrom
feat/destroy-types-tsrs

Conversation

@jonataswalker

Copy link
Copy Markdown
Owner

Implements spec #757 (T778): destroy(), cancellable fades, honest types, and tsrs type checking. Next release expected: 5.1.0. version is untouched.

Commits

# Commit Item
1 5f89d71 test: destroy() tears a picker down (failing) 1
2 5738994 feat: add destroy() 1
3 8534afa test: fades stop on destroy() and on a later show()/hide() (failing) 2
4 9114b28 fix: let destroy(), show() and hide() stop a fade at any frame 2
5 7e898aa refactor(types): build the picker complete and declare null selections 3
6 6d5fc4d build(types): type check with pinned tsrs, TypeScript 7 as second pass 4

The two test commits were made with HUSKY=0, because the pre-commit hook runs npm test. Lint, typecheck and format were run by hand for both.

1. destroy()

Test first (tests/destroy.spec.ts, 6 tests × 3 projects).

  • How it checks listeners: it wraps EventTarget.prototype.add/removeEventListener before creating pickers. That counts the listeners actually attached, not just whether the DOM is gone.
  • What it requires:
    • after destroy(), every listener the picker added is gone, as is the container
    • focusing or clicking the target, a document mousedown, clicks on the detached hour/minute anchors, show(), hide() and a late on() all do nothing, with no page errors
    • a second destroy() is a no-op
    • another picker keeps working
    • destroying mid-drag removes the document mousemove/mouseup, and a later move doesn't move the container
    • destroy() called from inside open, change and close handlers leaves 0 listeners and no errors
  • Before the fix: at 5f89d71, all 18 runs fail with destroy is not a function.

What destroy() does:

  • removes the document mousedown, the target focus/click and every anchor click
  • runs the drag teardown that handleDrag now returns, which also removes an in-progress drag's document listeners
  • clears all mitt handlers, cancels the fade and removes the container
  • makes show(), hide() and on() no-ops afterwards

The README documents destroy(), and its #52 paragraph now says to call it on the old picker before creating a new one.

2. Fade cancellation

The bug: fade() returned only its first requestAnimationFrame id, so cancelling did nothing after the first frame. show() never cancelled a running fade, so a show() during a fade-out ended hidden.

Test first (tests/fade.spec.ts, 4 tests × 3).

  • What it requires:
    • opacity stays put for 10 frames after destroy(), both mid fade-in and mid fade-out
    • show() during a fade-out ends shown
    • hide() during a fade-in ends hidden
  • Before the fix: at 8534afa, 8 of 12 runs fail: both destroy cases in all 3 projects, and show-during-fade-out in both Chromium projects. hide-during-fade-in passes even before the fix, because the fade-in finishes first and the fade-out then completes. It stays as a check on the fixed behavior.

Fix: fade() reports every frame it schedules through onFrame, which keeps picker.requestAnimationId current. show() and hide() go through startFade(), which cancels the running fade first, and destroy() cancels it outright. The exported Picker type is unchanged.

3. Honest types

  • Suppressions: all 13 @ts-expect-error are gone (12 in main.ts, 1 in drag.ts). No as, non-null assertion or suppression is left in src/.

  • How:

    • createStructure() takes the options, so the DOM is built first and picker is created complete. The drag header is checked with instanceof.
    • handleDrag() takes its handlers as an argument.
    • The two as keyof EmitterEvents casts in fade() were unnecessary and are gone.
  • Contract: Picker['hour'], Picker['minute'], and so the change payload, are declared string | null. At runtime both are null until picked, as before. The README now says so. The test harness type follows, with no runtime change.

  • Public API vs 5.0.1: comparing the built dist/timepicker.d.ts with the published 5.0.1:

    -    hour: string;          +    hour: string | null;
    -    minute: string;        +    minute: string | null;
                                +    destroy(): void;
    

    The only other lines are five new private declarations (destroyed, releaseDrag, targetEvent, removeDomListeners, startFade), which TypeScript emits for private members. They aren't callable from outside.

  • Runtime unchanged: the existing 45 tests and the packed Chromium/Firefox consumer checks pass.

4. tsrs

Same shape as ol-contextmenu PR #316:

  • Pin: tsrs is exactly 7.1.0-beta.tsrs2, still the newest build. Upstream dropped its next dist-tag on 2026-11-17, so latest now points to the older 0.25.0-ts7.1.0-beta. The version is not deprecated.

  • Scripts: typecheck = check:typecheckers → typecheck:tsrs → typecheck:ts7. TypeScript 7 runs by path, because .bin/tsc is @typescript/typescript6's, whose declaration tooling is unchanged.

  • Guard: exits 1 on a range pin (^7.1.0-beta.tsrs2) and on a mismatched pin (0.25.0-ts7.1.0-beta); both tried by hand.

  • Consumers: check-consumers.mjs compiles the packed consumer with tsrs and TypeScript 7, under both bundler and nodenext.

  • Parity: npm run check:typecheck-parity runs outside verify and needs a build.

    Case tsrs TypeScript 7
    Real project / real consumer 0 errors 0 errors
    src/main.ts + theme: 'neon' TS2322 at (303,57) same
    consumer + lang: 'xx', evt.hour.padStart(…) TS2322 at (22,54), TS18047 'evt.hour' is possibly 'null' at (24,19) same

    Message text is identical too. Exit codes on errors differ (tsrs 2, TS7 1), and both fail.

  • Lint backend: oxlint 1.93 picks tsrs-lint once tsrs is installed.

    • Proof: replacing .bin/tsrs-lint with a stub that exits 3 makes lint fail with the stub's message. Replacing .bin/tsgolint leaves lint passing.
    • Repo lint: findings are the same before and after (0).
    • Bad file: a probe with 6 type-aware violations (no-floating-promises, await-thenable, no-unnecessary-type-assertion, no-redundant-type-constituents, require-await, require-array-sort-compare) gives identical findings under tsrs-lint and under tsgolint forced with OXLINT_TSGOLINT_PATH.
    • Dependency: oxlint-tsgolint is no longer used, so it is removed.

Gate

After rm -rf node_modules dist && npm ci (Node 26.13.1, npm 12.2.2), npm run verify exits 0:

  • guard, tsrs and TS7 typecheck, lint, format
  • 75 Playwright tests (45 existing + 18 destroy + 12 fade)
  • build, attw, publint, the 6-file tarball
  • packed consumers: tsrs and TS7 types, Chromium and Firefox

npm audit reports 0 vulnerabilities.

🤖 Generated with Claude Code

jonataswalker and others added 6 commits November 17, 2026 11:41
Records every addEventListener/removeEventListener on the page, then
checks that destroy() removes the container and each listener the
picker added (target, document, anchors, drag, in-flight drag), that a
destroyed picker ignores focus, document clicks, anchor clicks, show(),
hide() and on(), that a second destroy() is a no-op, that other pickers
keep working, and that destroy() from inside open, change and close
handlers completes cleanly. Fails on 5.0.1: there is no destroy().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
destroy() removes the document mousedown listener, the target's focus
or click listener, the click listeners on every hour and minute anchor,
and the drag listeners, including the document mousemove/mouseup of a
drag in progress (handleDrag now returns a teardown). It clears every
mitt handler, cancels the pending fade frame and removes the container.
After destroy(), show(), hide() and on() are no-ops, and a second
destroy() does nothing.

The README documents destroy() and tells #52 readers to call it on the
old picker before creating one for a replaced input.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fade() returns only its first requestAnimationFrame id, so neither
destroy() nor a later show()/hide() can stop a fade after its first
frame. The tests destroy a picker mid fade-in and mid fade-out and
require the opacity to stay put for 10 more frames, and call show()
during a fade-out and hide() during a fade-in, requiring the state of
the last call. On 5.0.1 opacity keeps changing after destroy(), and a
show() during a fade-out ends hidden in Chromium.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fade() returned only its first requestAnimationFrame id, and each later
frame replaced a local id, so cancelAnimationFrame(requestAnimationId)
stopped nothing after the first frame. fade() now reports every frame
it schedules through onFrame, which keeps picker.requestAnimationId
current. show() and hide() cancel the running fade before starting
their own, and destroy() cancels it outright. triggerShow no longer
cancels separately, since show() does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The constructor built the picker object with null placeholders and 12
@ts-expect-error comments, and drag.ts started from an empty handler
object under a 13th. Now:

- createStructure() takes the options, so the DOM is built first and
  the picker object is created complete. The drag header is checked
  with instanceof instead of a non-null assertion, and the drag
  coordinates start at 0 (only read after a mousedown sets them).
- handleDrag() takes its start/move/end handlers as an argument and
  returns the teardown.
- fade() emits its internal events without `as keyof EmitterEvents`.
- Picker['hour'] and Picker['minute'], and so the change payload, are
  declared string | null. Runtime is unchanged: both stay null until
  picked, which the declarations used to hide. The test harness and
  the README say so.

No suppressions, assertions or non-null assertions remain in src.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ond pass

As in ol-contextmenu (#290, PR #316):

- tsrs 7.1.0-beta.tsrs2, pinned exactly, is the primary checker
  through its own tsrs bin. TypeScript 7 runs as a labelled second
  pass by path. The TypeScript 6 declaration tooling is unchanged.
- check:typecheckers fails the gate unless tsrs matches the exact pin
  and the second pass is TypeScript 7.
- check-consumers.mjs compiles the packed consumer under bundler and
  nodenext resolution with both checkers.
- check:typecheck-parity (outside verify, needs a build) shows both
  pass the real project and consumer, and reject planted errors in
  src/main.ts (TS2322) and in the consumer (TS2322, and TS18047 from the
  new nullable hour) with the same file, line, column and code.
- With tsrs installed, oxlint 1.93 runs tsrs-lint instead of tsgolint,
  so oxlint-tsgolint is removed. Lint findings are unchanged (0), and a
  bad file gives identical findings under both backends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@socket-security

socket-security Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedtsrs@​7.1.0-beta.tsrs21001001009590

View full report

jonataswalker and others added 2 commits November 17, 2026 11:56
mitt's emit() iterates a copy of the handler list, so clearing it in
destroy() does not stop later handlers of the same emission. The test
registers a destroying handler first and a recording handler second for
open, change and close, and requires the second never to run. Fails at
6d5fc4d: all three recorders run (review round 1, #802).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
on() now registers a wrapper that checks the destroyed flag when it is
called, so a handler later in the same emission does not run after an
earlier one called destroy(). mitt's emit() iterates a copy of the
handler list, which emitter.all.clear() alone cannot stop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonataswalker
jonataswalker merged commit a774659 into master Nov 17, 2026
5 checks passed
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.

1 participant