Skip to content

feat: ship TypeScript declarations - #33

Merged
killerwolf merged 4 commits into
mainfrom
feat/typescript-declarations
Sep 6, 2026
Merged

feat: ship TypeScript declarations#33
killerwolf merged 4 commits into
mainfrom
feat/typescript-declarations

Conversation

@killerwolf

Copy link
Copy Markdown
Owner

P1, item 1 of the discoverability plan.

Why

No types meant every TypeScript consumer got an implicit any and had to write their own declarations or pick a different library. It is the first thing an evaluator checks, and npm surfaces it on the package listing.

What changed

  • src/index.d.ts — hand-written, ~140 lines. Generating from the JSDoc produced a weaker surface than writing it directly, since the source is plain JS.
  • package.jsontypes entry point plus a types condition first in the exports map, so both bundler and node16/nodenext resolution find it.
  • npm run types:checktsc --noEmit over types-test.ts, a compile-time exercise of the whole public surface including @ts-expect-error negative cases. Wired into the Code Quality workflow. Declarations that silently drift from the implementation are worse than no declarations.
  • README — a short TypeScript section.

Two things the types make explicit

The docs previously only implied both:

  1. Coordinates are always in the image's original pixels, not displayed pixels.
  2. The style / handleStyle objects replace the defaults rather than merging into them — a partial override silently unsets every property it omits. Documented in the declarations; worth fixing in the implementation separately.

Verification

Beyond CI, I packed the tarball and installed it into a scratch project under moduleResolution: NodeNext. Types resolve, and getFocusPoint().x correctly types as number.

npm test (13 passing), lint:check, format:check and types:check all green. The declarations ship (3.8 kB); types-test.ts and tsconfig.json do not.

🤖 Generated with Claude Code

killerwolf and others added 2 commits September 6, 2026 09:42
No types meant every TypeScript consumer got an implicit `any` and had to
either write their own declarations or reach for a different library. That
is the first thing an evaluator checks, and npm shows it on the listing.

The declarations are hand-written rather than generated: the source is
plain JS with JSDoc, and generating from it produced a weaker surface than
writing the ~140 lines directly.

Two things the types encode that the docs previously only implied:
coordinates are always in the image's original pixels, and the style
objects replace the defaults wholesale instead of merging into them, so a
partial override silently unsets everything it omits.

Added `npm run types:check` (tsc --noEmit) over a compile-time test that
exercises the full surface, including negative cases, and wired it into
CI — declarations that drift from the implementation are worse than none.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
killerwolf and others added 2 commits September 6, 2026 09:52
The declarations documented the shallow-merge behaviour these comments
were written against. #36 fixes that merge, so the note that a partial
override unsets everything it omits no longer holds.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@killerwolf
killerwolf merged commit 5177fa7 into main Sep 6, 2026
2 checks passed
@killerwolf
killerwolf deleted the feat/typescript-declarations branch September 6, 2026 08:00
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