繁体   English   中英

d3 和 Typescript。 selection.merge 类型问题

[英]d3 and Typescript. selection.merge types problem

我正在尝试使用 typescript 实现 d3 输入、更新、删除模式

资料来源: https://codesandbox.io/s/brave-banach-g1h51?file=/src/index.ts

import { select } from "d3-selection";

const chart = select("#chart");

const values = [1, 2, 3, 4, 5];

const node = chart.selectAll("g.node").data(values);
const nodeEnter = node
  .enter()
  .append("g")
  .attr("class", "node");

// Type Error here
const nodeUpdate = nodeEnter.merge(node);

node.exit().remove();

但是我在这个刺痛上遇到了错误:

在此处输入图像描述

Argument of type 
'Selection<BaseType, number, BaseType, unknown>' is not assignable to parameter of type 
'Selection<SVGGElement, number, BaseType, unknown>'.
Types of property 'select' are incompatible.

我该如何解决?

我找到了解决方案。

长银

const node = chart.selectAll("g.node").data(values);

const node = chart.selectAll<SVGGElement, number[]>("g.node").data(values);

正在解决类型不匹配。

暂无
暂无

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

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