簡體   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