首页 > 解决方案 > 如何在 TypeScript 中使用 Cytoscape.Js 扩展?

问题描述

我尝试在 Typescript 项目中使用带有扩展名的 CytoscapeJS - Cytoscape-Node-Editing 。参考this Q&A后,我更改了一行@types/cytoscapeindex.d.ts但是,由于我不熟悉它,我在黑暗中迷失了设置,所以想得到任何建议,如何实施?还是其他地方有问题?真挚地。

@types/cytoscape/index.d.ts

function use(module: Ext, module2?: Ext, module3?: Ext): void;

画布.ts

import cytoscape from "cytoscape";
import $ from 'jquery';
import Konva from 'konva';
import nodeEditing from "cytoscape-node-editing";

cytoscape.use(nodeEditing, Konva, $);

var cy = (window.cy = cytoscape({ 

... 

}) 

cy.nodeEditing();

然后收到错误消息

Argument of type 'typeof Konva' is not assignable to parameter of type 'Ext'.
  Type 'typeof Konva' provides no match for the signature '(cytoscape: (options?: CytoscapeOptions | undefined) => Core): void'.

标签: typescript

解决方案


根据使用说明:https ://github.com/iVis-at-Bilkent/cytoscape.js-node-editing您的代码应该更像这样:

import cytoscape from 'cytoscape';
import $ from 'jQuery';
import nodeEditing from 'cytoscape-node-editing';
import konva from 'konva';

nodeEditing( cytoscape, $, konva ); // register extension

我对 cytoscape 不熟悉,但很少需要弄乱.d.ts@types/packages 包含的文件。有什么我想念的吗?


推荐阅读