【问题标题】:Conflicting signatures with TypeScript and d3.merge与 TypeScript 和 d3.merge 冲突的签名
【发布时间】:2020-08-25 08:53:17
【问题描述】:

我有这段 d3.js JavaScript 代码:

  const paths = svg.selectAll("path").data([1,2,3]);
  paths
    .enter()
    .append("path")
    .merge(paths)
    .attr(...) // more commands that refer to merged selection

但是,merge 函数会因以下错误而中断编译:

Argument of type 'Selection<BaseType, number, BaseType,
unknown>' is not assignable to parameter of type
'Selection<SVGPathElement, number, BaseType, unknown>'.

我可以通过将merge(paths) 替换为merge(svg.selectAll("path")) 来解决此问题,但这只是一种解决方法。我错过了什么?

【问题讨论】:

    标签: javascript typescript d3.js


    【解决方案1】:

    这对我有用。当我们追加 svg-path 时,变量 path 改变了类型,并且该类型是 merge 方法所需的类型。

    const paths = svg.selectAll("path").data([1,2,3]);
    const p = paths
        .enter()
        .append("path")
    p.merge(p)
        .attr(...)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-28
      • 2016-01-30
      • 1970-01-01
      • 2018-07-26
      • 2020-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多