gpt4 book ai didi

javascript - 类型 'transition' 上不存在属性 'Selection'

转载 作者:行者123 更新时间:2023-11-29 23:46:54 27 4
gpt4 key购买 nike

我想在 angular2 中使用 d3js,但是当我想在元素更改时添加过渡时出现错误: Property 'transition' does not exist on type 'Selection<BaseType, {}, null, undefined>'我使用angular-cli生成项目,angular的版本是4.0.0,d3js是4.8.0

这是我的 typings.d.ts :

declare module 'd3' {
export * from 'd3-array';
export * from 'd3-axis';
export * from 'd3-brush';
export * from 'd3-chord';
export * from 'd3-collection';
export * from 'd3-color';
export * from 'd3-dispatch';
export * from 'd3-drag';
export * from 'd3-dsv';
export * from 'd3-ease';
export * from 'd3-force';
export * from 'd3-format';
export * from 'd3-geo';
export * from 'd3-hierarchy';
export * from 'd3-interpolate';
export * from 'd3-path';
export * from 'd3-polygon';
export * from 'd3-quadtree';
export * from 'd3-queue';
export * from 'd3-random';
export * from 'd3-request';
export * from 'd3-scale';
export * from 'd3-selection';
export * from 'd3-shape';
export * from 'd3-time';
export * from 'd3-time-format';
export * from 'd3-timer';
export * from 'd3-transition';
export * from 'd3-voronoi';
export * from 'd3-zoom';

这是我的 app.component.ts

import * as d3 from 'd3';
......
d3.select(this).select("path").transition().attr("d", function(d) {
console.log(d);
return arc2(<any>d);
})

如果我删除 transition()它表现良好。

如何解决?谢谢

最佳答案

我已经通过以下方式修复了我的代码:

import { select as d3Select } from 'd3-selection';
import { transition as d3Transition } from 'd3-transition';
d3Select.prototype.transition = d3Transition;

然后在您的代码中使用 d3Select 代替 select

您可以关注: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/16176

关于javascript - 类型 'transition' 上不存在属性 'Selection<BaseType, {}, null, undefined>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43653228/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com