html2pdf.js
html2pdf.js copied to clipboard
Add support of typescript
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, andHtml2PdfStatic. - Ensured all documented methods and parameters are typed correctly.
- Included JSDoc comments for better documentation.
Motivation & Benefits:
- Enables TypeScript developers to use
html2pdf.jswith type checking. - Enhances code editor autocompletion and documentation.
- Reduces potential runtime errors by enforcing correct API usage.
How to Test:
- Import the library in a TypeScript project:
import html2pdf from "html2pdf.js"; - Use the library with the new type definitions:
const element = document.getElementById("element-to-print"); html2pdf().from(element).set({ filename: "test.pdf" }).save(); - Verify that TypeScript recognizes the method signatures and shows relevant hints in an IDE.
Looking forward to feedback and suggestions!