question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

not compatible with jsPDF 2.0.0 - Property 'autoTable' does not exist on type 'jsPDF'

See original GitHub issue

Hello,

I tried to use jsPDF-AutoTable with jsPDF 2.0.0 but I cant find the way to solve the following compile error: Property ‘autoTable’ does not exist on type ‘jsPDF’

` import jsPDF from ‘jspdf’;

import ‘jspdf-autotable’; … const doc = new jsPDF(‘landscape’, ‘mm’, ‘a4’);

doc.autoTable({ body: [x.content], `

It worked with jsPDF 1.5.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
victoriaDrewscommented, Aug 24, 2020

Hello I have an similar error, I import the scripts like this:

      <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.0.0/jspdf.umd.min.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.6/jspdf.plugin.autotable.min.js"></script>

And want to use it like this:

    window.jsPDF = window.jspdf.jsPDF;

    function createInvoice(final){
      const doc = new jsPDF();
      console.log(window.autotable);

      doc.text("Hello world!", 10, 10);
      doc.autoTable({
        head: [['Name', 'Email', 'Country']],
        body: [
          ['David', 'david@example.com', 'Sweden'],
          ['Castille', 'castille@example.com', 'Spain']
        ]
      });
      doc.save("a4.pdf");
    }

I have all times the doc.autoTable is not a function error.

1reaction
cloakedchcommented, Aug 21, 2020

I imported:

import { autoTable, RowInput } from 'jspdf-autotable';
import { jsPDF } from 'jspdf';

and used as:

(doc as jsPDF & { autoTable: autoTable }).autoTable({
      head: [columnsTitles],
      body: this.source as RowInput[],
(...)
});

and it worked.

As an alternative, you could create an interface wrapping the autoTable plugin. This effectively does the same, its just (imo) prettier:

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

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

Also, this lets you add any other plugins as new lines in the interface (ofc you could just AND it together like @digit81 proposed).

Then use it in your class:

export class PDFDocument {
  protected doc: jsPDFWithPlugin;

  constructor() {
    this.doc = new jsPDF({
      orientation: 'portrait',
      unit: 'mm',
      format: 'a4',
    }) as jsPDFWithPlugin;
  }

  generate() {
    this.doc.autoTable({
      ...
    });
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Property 'autoTable' does not exist on type jsPDF
The following worked for me in Angular 11, jsPDF 2.3.1, jspdf-autotable 3.5.14: import jsPDF from 'jspdf' import autoTable from ...
Read more >
Property 'autoTable' does not exist on type jsPDF #297 - GitHub
I am using angular2 and Node JS. I have installed jspdf and jspdf-autotable both modules using npm. and in .angular-cli.json file , I...
Read more >
jspdf-autotable - npm
Start using jspdf-autotable in your project by running `npm i jspdf-autotable`. There are 228 other projects in the npm registry using ...
Read more >
jspdf-autotable/README.md - UNPKG
The CDN for jspdf-autotable. ... The goal is to support all units supported by jspdf including mm and in but currently there is...
Read more >
Property 'autoTable' does not exist on type jsPDF - Bountysource
I am using angular2 and Node JS. I have installed jspdf and jspdf-autotable both modules using npm. and in .angular-cli.json file , I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found