admin管理员组文章数量:1323542
I can't get my head around the following TypeScript error message in the Webstorm IDE (pretty new to TypeScript so sorry ...)
I am using d3.d.ts from the DefinitelyTyped repository to implement graphics with d3js in which the interface for d3.svg.arc() method is defined like:
export interface Arc {
...
outerRadius: {
(): (data: any, index?: number) => number;
(radius: number): Arc;
(radius: () => number): Arc;
(radius: (data: any) => number): Arc;
(radius: (data: any, index: number) => number): Arc;
};
...
}
when implementing the arc in the following manner ...
svg.selectAll(".arc")
.attr("d", function (d) {
return d3.svg.arc().outerRadius(
function (d) {
return d - 9;
})
...
I get the error: "Argument Type Function is not assignable to parameter type function"
So
function (d) {return d - 9;})
doesn't seem to be valid for that interface even so it seems of the type
(): (data: any, index?: number) => number;
I guess I oversee something obvious yet ... I stuck right now
Thanks
I can't get my head around the following TypeScript error message in the Webstorm IDE (pretty new to TypeScript so sorry ...)
I am using d3.d.ts from the DefinitelyTyped repository to implement graphics with d3js in which the interface for d3.svg.arc() method is defined like:
export interface Arc {
...
outerRadius: {
(): (data: any, index?: number) => number;
(radius: number): Arc;
(radius: () => number): Arc;
(radius: (data: any) => number): Arc;
(radius: (data: any, index: number) => number): Arc;
};
...
}
when implementing the arc in the following manner ...
svg.selectAll(".arc")
.attr("d", function (d) {
return d3.svg.arc().outerRadius(
function (d) {
return d - 9;
})
...
I get the error: "Argument Type Function is not assignable to parameter type function"
So
function (d) {return d - 9;})
doesn't seem to be valid for that interface even so it seems of the type
(): (data: any, index?: number) => number;
I guess I oversee something obvious yet ... I stuck right now
Thanks
Share Improve this question asked Oct 24, 2013 at 14:21 dorjeduckdorjeduck 7,80411 gold badges53 silver badges68 bronze badges 2- That example (stripped down) works for me on typescriptlang/Playground – SLaks Commented Oct 24, 2013 at 14:27
-
The Playground and WebStorm aren't necessarily (probably aren't) using the same releases of TypeScript. Try explicitly typing the function passed into outerRadius and see what happens.
outerRadius(function (d: any): number { return d - 9; });
– Jeffery Grajkowski Commented Oct 24, 2013 at 15:12
1 Answer
Reset to default 4I had a similar issue with a string to number conversion and fixed it by adding an explicit typecasting like:
$.replace(/text/g, <string>$.now());
.
Just note the <string>
before the parameter.
Just try to typecast to and tell how it goes.
In your case it will be something like:
svg.selectAll(".arc")
.attr("d", function (d) {
return d3.svg.arc().outerRadius(
<Function>function (d) {
return d - 9;
})
...
or maybe:
svg.selectAll(".arc")
.attr("d", function (d) {
return d3.svg.arc().outerRadius(
<function>function (d) {
return d - 9;
})
...
since the error lies in the difference between Function and function.
版权声明:本文标题:javascript - TypeScript : Argument Type Function is not assignable to parameter type function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742124480a2421874.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论