I've noticed there are many type errors for d3js when using it with Angular(typescript).
For example I can't get the following snippet to work
svg.call(d3.zoom().on('zoom', () => {
g.attr('transform', d3.events.transform);
}));
Throws
S2345: Argument of type 'ZoomBehavior<Element, unknown>' is not assignable to parameter of type '(selection: Selection<BaseType, unknown, HTMLElement, any>, ...args: any[]) => void'. ??Types of parameters 'selection' and 'selection' are incompatible. ????Type 'Selection<BaseType, unknown, HTMLElement, any>' is not assignable to type 'Selection<Element, unknown, any, any>'. ??????Types of property 'select' are incompatible. ????????Type '{ <DescElement extends BaseType>(selector: string): Selection<DescElement, unknown, HTMLElement, any>; <DescElement extends BaseType>(selector: null): Selection<null, undefined, HTMLElement, any>; <DescElement extends BaseType>(selector: ValueFn<...>): Selection<...>; }' is not assignable to type '{ <DescElement extends BaseType>(selector: string): Selection<DescElement, unknown, any, any>; <DescElement extends BaseType>(selector: null): Selection<null, undefined, any, any>; <DescElement extends BaseType>(selector: ValueFn<...>): Selection<...>; }'. ??????????Types of parameters 'selector' and 'selector' are incompatible. ????????????Types of parameters 'groups' and 'groups' are incompatible. ??????????????Type 'BaseType[] | ArrayLike<BaseType>' is not assignable to type 'Element[] | ArrayLike<Element>'. ????????????????Type 'BaseType[]' is not assignable to type 'Element[] | ArrayLike<Element>'. ??????????????????Type 'BaseType[]' is not assignable to type 'Element[]'. ????????????????????Type 'BaseType' is not assignable to type 'Element'. ??????????????????????Type 'null' is not assignable to type 'Element'.
Also, another error is that d3.events is undefined.
Any tips on how to get this working? There are multiple code samples that just don't work due to type errors. Even suppressing with @ts-ignore doesn't solve them.
UPDATE: After using the migrations guide from v5 to v6, the zoom handler doesn't throw any more errors
const zoom = d3.zoom().on('zoom', ({transform}, d) => {
g.attr('transform', transform);
});
But there still is the type error when trying to call it like this
svg.call(zoom)
question from:
https://stackoverflow.com/questions/66059904/type-errors-for-d3js-in-angular-latest 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…