html2pdf.js icon indicating copy to clipboard operation
html2pdf.js copied to clipboard

Add support of typescript

Open umidjon-2231 opened this issue 10 months ago • 2 comments

This pull request introduces TypeScript definitions (type.d.ts) for html2pdf.js, allowing developers to use the library with improved type safety and better IDE support.

Changes Included:

  • Created a TypeScript declaration file (type.d.ts) with comprehensive type definitions for the library.
  • Added typings for Html2PdfOptions, Html2PdfWorker, and Html2PdfStatic.
  • Ensured all documented methods and parameters are typed correctly.
  • Included JSDoc comments for better documentation.

Motivation & Benefits:

  • Enables TypeScript developers to use html2pdf.js with type checking.
  • Enhances code editor autocompletion and documentation.
  • Reduces potential runtime errors by enforcing correct API usage.

How to Test:

  1. Import the library in a TypeScript project:
    import html2pdf from "html2pdf.js";
    
  2. Use the library with the new type definitions:
    const element = document.getElementById("element-to-print");
    html2pdf().from(element).set({ filename: "test.pdf" }).save();
    
  3. Verify that TypeScript recognizes the method signatures and shows relevant hints in an IDE.

Looking forward to feedback and suggestions!

umidjon-2231 avatar Mar 05 '25 16:03 umidjon-2231