gpt4 book ai didi

typescript - 无法在 Typescript 中导入 svg.js

转载 作者:搜寻专家 更新时间:2023-10-30 21:57:32 25 4
gpt4 key购买 nike

我安装了 svg.js 作为开发依赖。它在我的 package.json 中显示为 svg.js": "^2.6.6"

我可以在 javascript 文件中导入库:

import SVG from 'svg.js';

但是,如果我在 Typescript 文件中做同样的事情,我会得到错误:“找不到模块 svg.js”。

我还有一个名为“typings”的文件夹,其中包含 svg.js 网站上提供的类型定义文件。

为什么我不能使用这个库?

最佳答案

在 ES6 中,您可以使用以下代码导入它:

import * as SVG from "svg.js";
let draw = SVG('drawing');
let rect = draw.rect(100, 100);

关于typescript - 无法在 Typescript 中导入 svg.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52188175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com