当尝试在openlayers中导入GeoTiff源时,得到错误TS2304 AbstractDecoder



当我尝试使用Angular 12和Open图层编译我的web应用程序时,如果我尝试用

行编译代码
import GeoTIFF from 'ol/source/GeoTIFF';

我得到2个错误。

Error: node_modules/geotiff/dist-node/geotiffimage.d.ts:67:118 - error TS2304: Cannot find name 'Source'.

我通过添加一个导入到ol/source/source来解决这个错误。

我得到的最后一个错误,我找不到任何其他地方当我搜索它是

Error: node_modules/geotiff/dist-node/geotiffimage.d.ts:136:100 - error TS2304: Cannot find name 'AbstractDecoder'.

,我找不到任何方法导入或任何文档。

我用npm install OL和npm install @types/OL安装了OL,这是一个新的项目,所以我不知道为什么我得到这个错误或如何解决它。

任何解决这个问题的建议或资源链接将非常感谢

从OpenLayers的v6.6.0开始,TS声明包含在ol包中,所以你不再需要安装@types/ol了(参见这里的发行说明)。删除包应该可以解决您的问题。

我也建议你在tsconfig.json"compilerOptions"中设置"skipLibCheck": true,正如这个Git问题所建议的那样,以避免类型定义的进一步问题。下面是一个例子:

{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
},
}

最新更新