widget: ship generated type declarations + typed element/events

Integrators had to read the demo to learn the API: the package built via
vite with no .d.ts and no types field, so @bitlogin/widget and
@bitlogin/widget/session resolved to `any`.

Emit declarations from source (tsconfig.types.json -> dist-types,
build:types wired into build) and point the package types/exports
conditions at them, for both the root and the /session entry. Generated,
so they can't drift from the implementation.

Add the type surface integrators actually want:
- HTMLElementTagNameMap["bitlogin-auth"], so querySelector/createElement
  return the typed element.
- Typed addEventListener/removeEventListener overloads (declaration-merged
  interface) for the bitlogin-* events.
- Exported event-detail types and BitLoginEventMap (src/events.ts), matching
  element.ts's dispatchEvent shapes.

Verified with a consumer conformance typecheck (typed detail with no cast,
typed element methods, readCachedSession return type). README gains a
"TypeScript" section.

Addresses the ".d.ts / documented API surface" item of the Tessera
integration feedback (docs/TODO.md).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BXQCvJPA6sVSQ5j8uBd9bB
This commit is contained in:
thePR0M3TH3ANandClaude Opus 4.8 committed 2026-08-11 19:37:32 -04:00
1 parent 1b39e0f60c
commit 5ae41ed9db
7 files changed
+154 -6

No files matched your search

+12 -3
View File
@@ -416,6 +416,15 @@ how much they cost.
### Small
- Ship a `.d.ts` (or documented event/method surface) for the element:
`getPublicKey`, `signEvent`, `nip44Encrypt/Decrypt`, and the event
`detail` shapes. Integrators currently read the demo to learn the API.
- **[DONE 2026-08-11]** Ship a `.d.ts` (or documented event/method surface) for
the element. **Shipped:** the widget now emits type declarations from source
(`tsconfig.types.json` → `dist-types/`, wired via `build:types` and the
package `types`/`exports` conditions for both `@bitlogin/widget` and
`@bitlogin/widget/session`) — zero-drift because they're generated, not
hand-written. Added the type surface integrators actually want: a
`HTMLElementTagNameMap["bitlogin-auth"]` augmentation (typed
`querySelector`/`createElement`), typed `addEventListener` overloads via a
declaration-merged interface, and exported event-detail types
(`BitLoginLoginEventDetail` etc. + `BitLoginEventMap`) in `src/events.ts`.
Verified with a consumer conformance typecheck; README "TypeScript" section
added.