该表达式不可构造。输入“typeof import(”jspdf”)”没有构造签名

发布于 2025-01-14 02:57:13 字数 557 浏览 4 评论 0原文

我正在使用 jsPDF v1.5.3

我已经导入它像这样

import * as jsPDF from 'jspdf'

,在方法我有这个

 var doc = new jsPDF('l', 'pt', [175, 91])

但是我有此处类型错误

输入图像这里的描述

而且我也声明了这样的@types/jspdf模块,

    declare module 'jspdf'{
 
}

我该如何修复这个?

I am using jsPDF v1.5.3

I have imported it like this

import * as jsPDF from 'jspdf'

and in method I have this

 var doc = new jsPDF('l', 'pt', [175, 91])

But I have type error here

enter image description here

and also I have declared @types/jspdf module like this

    declare module 'jspdf'{
 
}

how can I fix this ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

帅气尐潴 2025-01-21 02:57:13

不需要这个通配符导入:

import * as jsPDF from 'jspdf'

你可以只使用命名导入:

import { jsPDF } from 'jspdf'

如果你想要通配符导入,你必须使用:

new jsPDF.jsPDF(...)

这是多余的

This wildcard import is not needed:

import * as jsPDF from 'jspdf'

You can just use a named import:

import { jsPDF } from 'jspdf'

If you want the wildcard import anyways, you have to use:

new jsPDF.jsPDF(...)

which is redundant ????

李白 2025-01-21 02:57:13

对于发现这个问题的其他人(或未来的我),另一个解决方案可能是在您的 tsconf.json 中设置此属性:"module": "commonjs"

For anybody else (or future me) who finds this question, another solution could be in your tsconf.json setting this property: "module": "commonjs".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文