import { onMounted, onUnmounted, nextTick, ref } from "vue"; import * as turf from "@turf/turf"; import mymap from "./../../views/dmap/components/sgmap/index.vue"; // import mymap from "./components/mapbox/index.vue"; // import mapboxgl from "mapbox-gl"; // import * as THREE from "three"; // import { debounce } from "lodash"; // import _ from 'lodash';
import * as d3 from "d3"; import * as topojson from "topojson";
到底应该用 type 还是 interface ? Because an interface more closely maps how JavaScript objects work by being open to extension, we recommend using an interface over a type alias when possible. On the other hand, if you can’t express some shape with an interface and you need to use a union or tuple type, type aliases are usually the way to go.
意思是说能用 interface 的地方就用 interface,否则用 type,其实这个解释官方说的也比较明确,这样使用的原因是因为更贴合 JavaScript 对象的工作方式,再清晰一些,如果我们是定义一个 object,那么最好是使用 interface 去做类型声明,什么时候用 type 呢,当定义一个 function 的时候,用 type 会更好一些
1 2 3 4
// the `?` operator here marks parameter `c` as optional function add(a: number, b: number, c?: number) { return a + b + (c || 0); }