我有一些使用OpenLayers的简单TypeScript代码,我可以编译成JavaScript,加载到浏览器中,一切正常:
var map = new ol.Map({
target: 'map',
layers: [new ol.layer.Tile({source: new ol.source.OSM()})],
view: new ol.View({
center: [0, 0],
zoom: 4
})
});
但是,一旦我尝试将第二个代码文件导入主文件,我就会收到一个无法解决的错误:
import {SomeClass} from "./SomeClass";
var map = new ol.Map({
// ... save as above
index.ts(3,15): error TS2686: 'ol' refers to a UMD global, but the current file is a module. Consider adding an import instead.
针对安装的OpenLayers类型进行编译,如下所示:
npm install --save-dev openlayers
npm install --save-dev @types/openlayers
如何使用多个使用OpenLayers的代码文件编译TypeScript代码库?
答案 0 :(得分:1)
尝试使用
import * as ol from 'openlayers';