我有一个使用 Typescript 构建的基本 Stencil 应用程序。我没有使用 Angular。我无法使用 svg.js。
这是我的完整组件:
import { Component, State } from '@stencil/core';
import * as moment from 'moment';
import * as SVG from 'svg.js';
@Component({
tag: 'astro-sandbox',
styleUrl: 'sandbox.css'
})
export class AstroSandbox {
componentDidLoad() {
// console.info(SVG)
let drawing = SVG('drawing');
}
render() {
return (
<div>
<div id="drawing">
</div>
</div>
);
}
}
这失败了{ Error: Cannot call a namespace ('SVG')...
我尝试查看 SVGconsole.info('SVG')
并编译,但浏览器给了我错误
TypeError: Cannot set property 'SVG' of undefined
。
我知道我的应用程序可以正常工作,并且 moment.js 可以正常工作,因此不存在 TS 配置问题。VS Code 中用于 svg.js 的 Intellisense 也可以正常工作。