Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript d3Service/d3-ng2-service TypeScript TS2346提供的参数与签名不匹配_Javascript_Typescript_D3.js_Svg - Fatal编程技术网

Javascript d3Service/d3-ng2-service TypeScript TS2346提供的参数与签名不匹配

Javascript d3Service/d3-ng2-service TypeScript TS2346提供的参数与签名不匹配,javascript,typescript,d3.js,svg,Javascript,Typescript,D3.js,Svg,我有一个包含rect元素和text元素的SVG 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="tim

我有一个包含rect元素和text元素的SVG

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>
我在选择时遇到TS2346错误:
错误TS2346:提供的参数与呼叫目标的任何签名都不匹配。

D3服务的
索引d.ts
为:

第162行写道:

select(选择器:字符串):选择


我假设我从
index.d.ts
中得到了错误的元素类型,我应该使用除
SVGRectElement
TextElement
之外的其他元素,但我不知道是什么。Angular2组件在实践中运行良好。如何读取
index.d.ts
文件以找到正确的元素类型?谢谢

正如您在
select()
方法签名中所看到的:

select(选择器:字符串):选择

select方法返回一个
Selection
元素,因此无法转换为
SVRectElement
。此外,强制转换(如果需要)应该位于调用的方法前面,如下所示:
let ele=D3.select(rect_id).node()

但在这种情况下,不需要强制转换,因此代码应为:

让rectEle=self.d3.select(rectId);

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);