Skip to content

Add TypeScript type definitions for saxonjs-he #14

@ThePlenkov

Description

@ThePlenkov

Feature Request: TypeScript Type Definitions

Summary

The saxonjs-he package currently lacks TypeScript type definitions, which causes type errors when using the library in TypeScript projects.

Current Error

Could not find a declaration file for module 'saxonjs-he'. 
'/node_modules/.bun/saxonjs-he@3.0.0-beta2/node_modules/saxonjs-he/SaxonJS3N.js' 
implicitly has an 'any' type.

Try `npm i --save-dev @types/saxonjs-he` if it exists or add a new declaration 
(.d.ts) file containing `declare module 'saxonjs-he';` [ts(7016)]

Use Case

We're building a universal XML ↔ JSON transformer package (xmlt) that relies on Saxon-JS for XSLT transformations. TypeScript type definitions would:

  1. Improve developer experience - Enable IDE autocompletion and inline documentation
  2. Catch errors at compile time - Detect incorrect API usage before runtime
  3. Better integration - Seamless integration with TypeScript projects without type workarounds
  4. Self-documenting API - Types serve as living documentation

Example Usage

import SaxonJS from 'saxonjs-he';

// Would love to have proper types here!
const result = await SaxonJS.transform({
  stylesheetInternal: compiledStylesheet,
  sourceText: xmlString,
  destination: 'serialized'
}, 'async');

Proposed Solution

Options for adding TypeScript support:

  1. Include .d.ts files in the package - Ship type definitions alongside the JavaScript code
  2. Publish @types/saxonjs-he - Create a DefinitelyTyped package
  3. Rewrite in TypeScript - Full TypeScript rewrite (most comprehensive but requires more effort)

Workaround

Currently using:

// Temporary workaround - loses all type safety
declare module 'saxonjs-he';

Additional Context

  • Package: saxonjs-he@3.0.0-beta2
  • Node.js: v24.10.0
  • TypeScript: Latest
  • Project: Open-source universal XSLT transformer

Saxon-JS is an excellent XSLT processor, and TypeScript definitions would make it even better for modern JavaScript/TypeScript development! 🚀

Would the team be open to adding TypeScript support? Happy to contribute if guidance is provided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions