Issue
My TypeScript application is reporting that property parse
does not exist on ./path/to/node_modules/@types/geojson/index
. Which is true when inspecting the interfaces for the geojson type definition.
The geojson
module does however offer a parse method.
How can I access the parse
method?
I tried removing the @types/geojson
module which seems to make the method accessible. However, despite having removed the type definition the same exception is thrown or, in another scenario I've not been able to replicate, VS Code throws an error that a type definition is recommended and won't compile without it.
I added the // @ts-ignore
decorator to disable the error but I'd prefer a cleaner fix.
Solution
Unfortunately you bumped on a rare case where a DefinitelyTyped @types/xxx
package does NOT describe the same named xxx
package on npm...
@types/geojson
definition describes the GeoJSON standard
This package contains type definitions for geojson (https://geojson.org/).
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/geojson/package.json#L5
{
"name": "@types/geojson",
"nonNpm": true,
"nonNpmDescription": "geojson"
}
geojson
on npm is actually a library to parse such GeoJSON objects...
As mentioned in the README of that library:
For Typescript environments, you can use GeoJSON.ts, a Typescript-native library. @EugeneYWang/GeoJSON.ts
...and the full explanation on the latter:
The reason to create this repo
Usually, an existed NPM package can just be used in TypeScript if a type definition file with the same name of that package is also installed. So why should I refactor that library into this typescript one? The reason is that the type definition named as GeoJSON has been occupied as the type definition of GeoJSON standard specification. Therefore, no one could contribute a type definition in TypeDefinition for @caseycesari/GeoJSON.js.
Answered By - ghybs
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.