simonbengtsson / jsPDF-AutoTable

jsPDF plugin for generating PDF tables with javascript
https://simonbengtsson.github.io/jsPDF-AutoTable/
MIT License
2.33k stars 624 forks source link

TypeScript declaration file mismatch #964

Open scottpageindysoft opened 1 year ago

scottpageindysoft commented 1 year ago

I'm not sure how to describe this better than TypeScript 5.0.4 can.

Here's the warning I get when I import 'jspdf-autotable' in a React tsx component.

Could not find a declaration file for module 'jspdf-autotable'. 'C:/Users/scott/Documents/projects/indysoftweb/IndySoftWebAPI/ClientApp/node_modules/.pnpm/registry.npmjs.org+jspdf-autotable@3.5.28_jspdf@2.5.1/node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js' implicitly has an 'any' type. There are types at 'c:/Users/scott/Documents/projects/indysoftweb/IndySoftWebAPI/ClientApp/packages/indysoft-react-main-app/node_modules/jspdf-autotable/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'jspdf-autotable' library may need to update its package.json or typings.ts(7016)

This is definitely a typing issue from this package, since we don't have any local declarations for it.

simonbengtsson commented 1 year ago

Could it be fixed in the latest version?

thierschi commented 1 year ago

I also experienced this issue using NodeJS with TypeScript. Somehow the types are inaccessible to TS and VS Code.

The error I'm getting here is autotable [...] is not callable or doc.autoTable is not a function.

The current workaround is this:

import {jsPDF} from 'jspdf';
import 'jspdf-autotable';
import {UserOptions} from 'jspdf-autotable';

interface jsPDFCustom extends jsPDF {
    autoTable: (options: UserOptions) => void;
}