Angular 2 typescript d3 type issue: Property 'x' does not exist on type '[number, number]'

前端 未结 6 1197
小鲜肉
小鲜肉 2021-01-11 15:15

I am generating a line chart with d3. It works, but typescript code complain about a property not exists in vs.

Property \'x\' does not exist on type

6条回答
  •  一整个雨季
    2021-01-11 16:03

    When data is passed as a variable, defining that data as type any should appease TypeScript, e.g.:

    // Append a 'text' SVGElement with data-driven text() to each 'g' SVGElement 
    d3.selectAll('g')
      .each(function(d: any) {
        d3.select(this)
          .append('text')
          .text(d.mytext);
      });
    
    

提交回复
热议问题