Skip to content

Ship type declarations generated from existing JSDoc #64

Description

@shroy

Problem

The package ships no type declarations — no types field in package.json and no .d.ts files. Consumers running tsc with checkJs (or plain TypeScript) get TS7016: Could not find a declaration file for module 'hooktml', and every import is implicitly any. This silently defeats type-checking for exactly the API surface where it helps most: signal() value types, hook deps arrays, and component signatures.

Downstream apps currently have to hand-maintain a local declare module "hooktml" shadow of the public API and re-diff it against the README on every version bump.

Proposal

The source is already thoroughly JSDoc-annotated, so declarations can be generated rather than written:

  1. Emit declarations from the existing JSDoc:
    // tsconfig.build.json
    {
      "compilerOptions": {
        "allowJs": true,
        "declaration": true,
        "emitDeclarationOnly": true,
        "outDir": "dist/types"
      },
      "include": ["src/**/*.js"]
    }
  2. Point package.json at them:
    {
      "types": "./dist/types/index.d.ts",
      "exports": {
        ".": {
          "types": "./dist/types/index.d.ts",
          "browser": "./index.browser.js",
          "node": "./index.js",
          "default": "./index.js"
        }
      }
    }
  3. Add the emit step to the release/build script so the declarations can never drift from the source JSDoc.

Notes

  • A few internal spots may need JSDoc tightening before the emit is clean (e.g. index.js uses a bare @type {Object} where a @typedef with a current property is needed).
  • Generic-heavy signatures (signal, computed) are worth eyeballing in the emitted output — JSDoc @template usually emits fine, but these are the highest-value types in the API.
  • Zero runtime impact; browser/CDN consumers are unaffected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions