Не могу импортировать GeoJSON из @ types / ol - PullRequest
0 голосов
/ 23 октября 2019

У меня есть следующие файлы:

tsconfig.json

{
    "compilerOptions": {
        "lib": [
            "es2019",
            "dom"
        ],
        "target": "es5",
        "module": "system",
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
        "outFile": "bundle.js"
    },
    "files": ["index.ts"]
}

Package.json

{
  "name": "testol",
  "version": "1.0.0",
  "description": "",
  "main": "bundle.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ol": "^5.3.3",
    "@types/ol": "^5.3.6"
  },
  "devDependencies": {
    "typescript": "^3.6.4"
  }
}

index.ts

import GeoJSON from 'ol/format/GeoJSON';
const geoJSON = new GeoJSON();

Когда я запускаю tsc --build tsconfig.json, я получаю много ошибок, таких как

node_modules/@types/ol/format/GeoJSON.d.ts:1:10 - error TS2305: Module '"node_modules/@types/ol/format/GeoJSON"' has no exported member 'Feature'.
1 import { Feature, FeatureCollection, GeoJSON as GeoJSON_1, Geometry, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon } from 'geojson';
           ~~~~~~~

node_modules/@types/ol/format/GeoJSON.d.ts:1:19 - error TS2305: Module '"node_modules/@types/ol/format/GeoJSON"' has no exported member 'FeatureCollection'.
1 import { Feature, FeatureCollection, GeoJSON as GeoJSON_1, Geometry, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon } from 'geojson';
                    ~~~~~~~~~~~~~~~~~

Что здесь не так? Я попытался установить более старую версию @ types / geojson, как предложено здесь

1 Ответ

0 голосов
/ 23 октября 2019

Мне удалось заставить его работать с помощью

{
    "compilerOptions": {
        "target": "es5",
        "module": "amd",
        "importHelpers": true,
        "declaration": false,
        "moduleResolution": "node",
        "outFile": "bundle.js"
    },
    "files": ["index.ts"]
}
...