我有這樣的代碼:
if(svg) {
// zoom
// svg type = d3.Selection<SVGSVGElement, unknown, null, undefined>
const zoomBehavior = d3
.zoom()
.scaleExtent([0.5, 5] )
.translateExtent([
[0, 0]。
[containerWidth, containerHeight],
])
.on("zoom", (event) => {
const zoomState = event.transform;
console.log("zoomState"/span>, zoomState)。
});
svg.call(zoomBehavior)。
我得到了這樣的錯誤型別:
Argument of type 'ZoomBehavior< Element, unknown>'不能分配給引數of型別'(selection: Selection<SVGSVGElement, unknown, null, undefined>, ...args: any[] ) => void'。
我不想使用ts-ignore
。uj5u.com熱心網友回復:
你可以在函式的泛型中定義縮放行為的型別,以匹配呼叫它的SVG選擇的型別。
既然你的SVG選擇型別是d3.Selection<SVGSVGElement, unknown, null, undefined>,那么:
const zoomBehavior = d3
.zoom<SVGSVGElement, unknown> ()
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/320671.html
標籤:
