我有一個包含rect元素和文本元素的SVG。d3Service/d3-ng2-service TypeScript TS2346提供的參數不匹配簽名
的index.html
<svg id="timeline" width="300" height="100">
<g transform="translate(10,10)" class="container" width="280" height="96">
<rect x="10" y="30" width="48" cy="10" r="30" height="60" class="timelineSeries_0" id="day1"></rect>
<rect x="58" y="30" width="48" cy="10" r="30" height="60" class="timelineSeries_0" id="day2"></rect>
<rect x="106" y="30" width="48" cy="10" r="30" height="60" class="timelineSeries_0" id="day3"></rect>
<rect x="154" y="30" width="48" cy="10" r="30" height="60" class="timelineSeries_0" id="day4"></rect>
<text class="textnumbers" id="day1" x="22.8" y="50">1</text>
<text class="textnumbers" id="day2" x="70.8" y="50">1</text>
<text class="textnumbers" id="day3" x="118.8" y="50">1</text>
<text class="textnumbers" id="day4" x="116.8" y="50">1</text>
</g>
</svg>
從d3-ng2-service
使用D3Service,我做了以下內容:
let day = 1;
let rect_id = "rect#day" + day;
let ele = D3.select<SVGRectElement>(rect_id).node();
let label_id = rect_id.replace("rect", ".textnumbers");
let numberEle = D3.select<TextElement>(label_id);
我得到一個錯誤TS2346與選擇: error TS2346: Supplied parameters do not match any signature of call target.
的D3服務的index.d.ts
是:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/d3-selection/index.d.ts#L155
線162,它說:
select<DescElement extends BaseType>(selector: string): Selection<DescElement, Datum, PElement, PDatum>;
我假設我是從index.d.ts
得到錯誤的元素類型那裏,我應該使用其他別的東西比SVGRectElement
和TextElement
,但我無法弄清楚什麼。 Angular2組件在實踐中運行良好。如何閱讀index.d.ts
文件以查找正確的元素類型?謝謝!