![](/img/trans.png)
[英]d3 Selection merge error in TypeScript: Types of property 'merge' are incompatible
[英]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.