Giter VIP home page Giter VIP logo

Comments (8)

DarkFIxED avatar DarkFIxED commented on June 19, 2024 1

Thank you very much!

from terraformer-wkt-parser.

jgravois avatar jgravois commented on June 19, 2024

I had to add import GeoJson from 'geojson';

Another option would be to declare the external dependency the way we do here. Either way, a PR with an improvement would be welcome.

/// <reference types="geojson" />

also had to do npm i @types/geojson

Not sure what else we can do to help with that. @types/geojson is already listed as a dependency of this lib.

"@types/geojson": "^1.0.0",

from terraformer-wkt-parser.

WORMSS avatar WORMSS commented on June 19, 2024

Yeah, I actually went a little farther with changing some other files to get exactly what I needed. I am not 100% with everything I did to get things to work. I need to undo things but the app is currently running for the next few hours. I will make a proper report in the morning (BST) with everything I did.

from terraformer-wkt-parser.

DarkFIxED avatar DarkFIxED commented on June 19, 2024

So, is there some progress? I really need this fix.

from terraformer-wkt-parser.

joseph-galindo avatar joseph-galindo commented on June 19, 2024

#40 seems to have broken use cases where an external dependency exists for @types/geojson on a version other than 1.x. For example, cases like:

sample package.json

"dependencies": {
   ...,
   "terraformer-wkt-parser": "1.2.1",
   ...
},
"devDependencies": {
   ...,
   "@types/geojson": "7946.0.7",
   ...
}

sample TypeScript source code

import terraWkt from 'terraformer-wkt-parser';
import * as GeoJSON from 'geojson';

const sampleWkt = '...';
const parsedWkt: GeoJSON.GeometryObject = terraWkt.parse(sampleWkt);
      ^^^^^^^^^
Type 'GeometryObject' is not assignable to type 'Geometry'.
  Type 'DirectGeometryObject' is not assignable to type 'Geometry'.
    Type 'DirectGeometryObject' is not assignable to type 'MultiPolygon'.
      Types of property 'type' are incompatible.
        Type 'string' is not assignable to type '"MultiPolygon"'.ts(2322)

The same sample block above works with [email protected].

from terraformer-wkt-parser.

jgravois avatar jgravois commented on June 19, 2024

Thanks for the report. I'm no typescript expert, but it looks like you can fix the problem and regain control over the version of the typings you're importing in your own application by making sure to import them before you import the terraformer parser.

import * as GeoJSON from 'geojson'
import terraWkt from 'terraformer-wkt-parser';

const parsedWkt: GeoJSON.GeometryObject = terraWkt.parse(sampleWkt);

from terraformer-wkt-parser.

joseph-galindo avatar joseph-galindo commented on June 19, 2024

@jgravois I wasn't expecting this to work at first, but it strangely does seem to work, thanks.

I'm guessing moving the import up somehow "shadows" over the GeoJSON that the types for terraformer-wkt-parser try to reference, since GeoJSON itself is exported as a global namespace?

In other words, the import order is actually influencing the type definitions that terraformer-wkt-parser is trying to use internally?

Specifically this part: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/geojson/index.d.ts#L14

from terraformer-wkt-parser.

jgravois avatar jgravois commented on June 19, 2024

the import order is actually influencing the type definitions that terraformer-wkt-parser is trying to use internally?

tbh, I'm not sure.

your import might be overriding the definitions our parser declares as a dependency internally or maybe it's just a lucky coincidence that they are compatible.

from terraformer-wkt-parser.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.