question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript types for the format GeoJSON cause compilation errors

See original GitHub issue

Describe the bug I am using OpenLayers 6.15.1 in an Angular 14 application and when I make use of the GeoJSON format I get the following compilation errors:

ERROR: node_modules/ol/format/GeoJSON.d.ts:2:36 - error TS2307: Cannot find module 'geojson' or its corresponding type declarations.

2 export type GeoJSONObject = import("geojson").GeoJSON;
node_modules/ol/format/GeoJSON.d.ts:3:37 - error TS2307: Cannot find module 'geojson' or its corresponding type declarations.

3 export type GeoJSONFeature = import("geojson").Feature;
node_modules/ol/format/GeoJSON.d.ts:4:47 - error TS2307: Cannot find module 'geojson' or its corresponding type declarations.

4 export type GeoJSONFeatureCollection = import("geojson").FeatureCollection;
node_modules/ol/format/GeoJSON.d.ts:5:38 - error TS2307: Cannot find module 'geojson' or its corresponding type declarations.

5 export type GeoJSONGeometry = import("geojson").Geometry;
node_modules/ol/format/GeoJSON.d.ts:6:35 - error TS2307: Cannot find module 'geojson' or its corresponding type declarations.

6 export type GeoJSONPoint = import("geojson").Point;
node_modules/ol/format/GeoJSON.d.ts:7:40 - error TS2307: Cannot find module 'geojson' or its corresponding type declarations.

7 export type GeoJSONLineString = import("geojson").LineString;
node_modules/ol/format/GeoJSON.d.ts:8:37 - error TS2307: Cannot find module 'geojson' or its corresponding type declarations.

8 export type GeoJSONPolygon = import("geojson").Polygon;
node_modules/ol/format/GeoJSON.d.ts:9:40 - error TS2307: Cannot find module 'geojson' or its corresponding type declarations.

9 export type GeoJSONMultiPoint = import("geojson").MultiPoint;
node_modules/ol/format/GeoJSON.d.ts:10:45 - error TS2307: Cannot find module 'geojson' or its corresponding type declarations.

10 export type GeoJSONMultiLineString = import("geojson").MultiLineString;
node_modules/ol/format/GeoJSON.d.ts:11:42 - error TS2307: Cannot find module 'geojson' or its corresponding type declarations.

11 export type GeoJSONMultiPolygon = import("geojson").MultiPolygon;
node_modules/ol/format/GeoJSON.d.ts:12:48 - error TS2307: Cannot find module 'geojson' or its corresponding type declarations.

12 export type GeoJSONGeometryCollection = import("geojson").GeometryCollection;

The error disappears if I add the following dependency: npm install @types/geojson --save-dev

To Reproduce Steps to reproduce the behavior:

  1. ng new test-app
  2. cd test-app
  3. npm install ol
  4. Add lines 2 and 10 to app.component.ts
import { Component } from '@angular/core';
import GeoJSON from 'ol/format/GeoJSON';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  myType = GeoJSON;
  title = 'test-app';
}
  1. ng build

Expected behavior Not to have to add the dependency @types/geojson in order to get rid of the compilation errors. The same issue happens with the format EsriJSON, so I am guessing that the installation of multiple dependencies may potentially be required.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ahocevarcommented, Aug 4, 2022

@mediafreakch That’s a different issue, which was reported recently in #13924.

1reaction
javier-lopez-1scommented, Aug 2, 2022

You get the same error if you import the format TopoJSON, as this is in turn importing types from topojson-specification. In a few days I will create a PR in which I will be moving the 3 items below:

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript assignment causes compilation error - Stack Overflow
1 Answer 1 ... The error is not about assignment, it's about calling JSON.parse() function. Error looks like your data variable is already...
Read more >
TSConfig Reference - Docs on every TSConfig option
An error occurs if any of the files can't be found. This is useful when you only have a small number of files...
Read more >
TypeScript errors and how to fix them
This error occurs when you import the same file in two different files using two different casing styles (ex. camelCase and UpperCamelCase):.
Read more >
Take control of unexpected data at runtime with TypeScript
In this article, we'll explore how to use TypeScript type ... returning HTML-formatted error responses with OK (200) status from JSON APIs, ...
Read more >
Troubleshooting | ts-node - TypeStrong · GitHub
... errors from ts-node, errors from the TypeScript compiler, and errors from node . It is also important to understand when errors are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found