繁体   English   中英

如何在 TypeScript 中使用 Cytoscape.Js 扩展?

[英]How to Use Cytoscape.Js Extension in TypeScript?

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

@types/cytoscape/index.d.ts

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

canvas.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'.

根据使用说明: 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 不熟悉,但很少需要弄乱@types/packages 包含的.d.ts文件。 有什么我想念的吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM