我使用 Turf.js 的 bbox 功能。无论我如何尝试,似乎都找不到 TS 类型定义。
我尝试了以下方法:
package.json:
"dependencies": {
...
"@turf/turf": "6.5.0",
"vue": "^3.3.11",
...
},
导入Vue文件(使用Composition API和TS):
<script setup lang="ts">
import * as turf from "@turf/turf";
...
</script>
打字稿错误:
Could not find a declaration file for module '@turf/turf'. '/Users/.../node_modules/@turf/turf/dist/es/index.js' implicitly has an 'any' type.
There are types at '/Users/.../node_modules/@turf/turf/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@turf/turf' library may need to update its package.json or typings.ts(7016)
Turf v6.5.0 中的 Typescript 支持有些破损(请参阅 https://github.com/Turfjs/turf/issues/2553)。如果您准备升级,请尝试 v7 alpha 之一。
撰写本文时的最新版本是 https://www.npmjs.com/package/@turf/turf/v/7.0.0-alpha.115