d3 / d3-zoom

Pan and zoom SVG, HTML or Canvas using mouse or touch input.
https://d3js.org/d3-zoom
ISC License
507 stars 143 forks source link

svg.call(d3.zoom().on('zoom',function(){})) warning : Argument of type 'ZoomBehavior<Element, unknown>' is not assignable to parameter of type '(selection: Selection<BaseType, unknown, HTMLElement, any>, ...args: any[]) => void'. #246

Closed uniquker closed 2 years ago

uniquker commented 2 years ago

typescript verison 4.3.5 d3 version 7.1.0 code: svg.call(d3.zoom().on('zoom',function(){})) typescript warning: 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 '{ (selector: string): Selection<DescElement, unknown, HTMLElement, any>; (selector: null): Selection<null, undefined, HTMLElement, any>; (selector: ValueFn<...>): Selection<...>; }' is not assignable to type '{ (selector: string): Selection<DescElement, unknown, any, any>; (selector: null): Selection<null, undefined, any, any>; (selector: ValueFn<...>): Selection<...>; }'. Types of parameters 'selector' and 'selector' are incompatible. Types of parameters 'groups' and 'groups' are incompatible. Type 'BaseType[] | ArrayLike' is not assignable to type 'Element[] | ArrayLike'. Type 'BaseType[]' is not assignable to type 'Element[] | ArrayLike'. Type 'BaseType[]' is not assignable to type 'Element[]'. Type 'BaseType' is not assignable to type 'Element'.ts(2345)

Fil commented 2 years ago

What is svg? It should be a d3 selection.

uniquker commented 2 years ago

What is svg? It should be a d3 selection. const svg = d3.select('svg')

use this code resolve it. const svg = d3.select('svg') function zoomed (event: any) { console.log(event) } const zoom = zoom().on('zoom', zoomed) as any svg.call(zoom)