import { select } from "d3-selection";
import React, { useEffect } from "react";
import { feature, topology } from "topojson";
import us from "./us.json";
const Map: React.FunctionComponent = () => {
const mapRef = React.createRef<SVGSVGElement>();
useEffect(() => {
createMap();
});
const createMap = () => {
const map = select(mapRef.current);
map.selectAll("path").data(feature(us, us.objects.states));
};
return <svg ref={mapRef} />;
};
export default Map;
我在feature(us, us.objects.states)
行遇到打字错误,在这里我们给我提供类型错误字符串,该字符串不能分配给拓扑类型。在查看json文件后,类型实际上是"type":"Topology"
,但是我可以看到typescript如何将其视为字符串。我该如何解决这个问题?