javascript - Typescript 类型转换 D3.js DefaultArcObject
问题描述
我目前正在使用从此包加载的类型定义。我的代码正在尝试使用D3.js 生成的元素设置d
svg 属性。path
arc
我的代码如下所示:
const pie = d3.pie<SomeDataInterface>()
.value((d) => d.dataVal);
const arc = g.selectAll(".arc")
.data(pie(mockData));
const path = d3.arc();
arc.append("path")
.attr("d", path); // >> Where compilation fails
但是,我收到此编译错误:
TypeScript error: Argument of type 'Arc<any, DefaultArcObject>' is not assignable to parameter of type 'ValueFn<SVGPathElement, PieArcDatum<ID3Data>, string | number | boolean | null>'.
Types of parameters 'd' and 'datum' are incompatible.
看这里的例子,似乎我可以在声明中声明一个<any>
类型path
。同样,我也尝试导入包含实际类型定义的Arc
using的类型定义并像这样分配它:import { Arc } from "d3-shape";
.attr("d", <Arc>path)
其中还收到编译警告。知道我可能缺少什么类型转换,具体在哪里?
更新
这段代码正在处理此处显示的示例。
解决方案
推荐阅读
- actions-on-google - 一项行动必须有多广泛才能被允许发布?
- python - 如何让 celery 优先处理任务?
- python - 熊猫数据框日期无法转换为日期时间格式
- amazon-s3 - 访问 aws s3 存储桶以暂存文件以用于 mapbox tileset
- flutter - 每当在 Flutter 中重建 App 时,身份验证数据都会重置
- javascript - 复选框中的 JQuery/JavaScript 更改
- dataset - 在 AWS Quick Sight 中更改视觉对象的数据集
- python - 由于矩阵形状/大小不兼容,无法做出预测
- python - 如何将数据帧分成 2 个相等的部分(前半行和后半行) - 在 Python 中
- multithreading - ReactiveX 与多线程编程有何不同