首页 > 解决方案 > 如何在joint.d.ts、jointjs中扩展命名空间

问题描述

我正在尝试在jointjs中创建自定义元素,但我有点陷入打字稿类型的问题。我不知道如何扩展我的命名空间/接口,所以我可以轻松地创建新的jointjs 元素。

我正在使用 React,但我认为它不会有帮助。

我得到的错误是

元素隐式具有“任何”类型,因为“html”类型的表达式不能用于索引类型“typeof 形状”。类型“typeof 形状”上不存在属性“html”

错误 > 关节形状 ['html'] = {};

import * as joint from 'jointjs';

const BeerObject = (graph: joint.dia.Graph) => {

    joint.shapes['html'] = {};
    joint.shapes['html'].Element = joint.shapes.basic.Rect.extend({
        defaults: joint.util.deepSupplement({
            type: 'html.Element',
            attrs: {
                rect: { stroke: 'none', 'fill-opacity': 0 }
            }
        }, joint.shapes.basic.Rect.prototype.defaults)
    });

};

export default BeerObject;

标签: typescripttypesnamespacesjointjs

解决方案


推荐阅读