Struggling with creating a typescript definition file for a seemingly 'simple' npm module.
Here are the key points:
Problem: encounter an error when compiling TypeScript:
play.ts(1,9): error TS2305: Module '"/to/the/dir/node_modules/geojson/geojson"' has no exported member 'GeoJSON'.
Module: geojson (https://www.npmjs.com/package/geojson). The package consists of only one public function located in geojson.js:
(function(GeoJSON) {
GeoJSON.version = '0.3.0';
GeoJSON.defaults = {};
// The sole public function.
// Converts an array of objects into a GeoJSON feature collection
GeoJSON.parse = function(objects, params, callback) {
...
...
...
(typeof module == 'object' ? module.exports : window.GeoJSON = {}));
The package.json contains
"main": "./geojson",
"name": "geojson",
//// I ADDED THIS TYPE DEF FILE
"typings": "./geojson.d.ts",
Based on this information
- module name: geojson
- parse: signature is parse(objects: any, params: any, callback?: any): any;
- Is GeoJSON an interface?
The definition file named geojson.d.ts looks like this:
export declare module geojson {
interface GeoJSON {
parse(objects: any, params: any, callback?: any): any;
}
}
The tsconfig file appears as follows:
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
}
}
Attempting to import (tried numerous methods..) including:
import GeoJSON from 'geojson';
import geojson from 'geojson';
import {geojson} from geojson;
import geojson = require('geojson');
import GeoJSON = require('geojson');
Where am I going wrong?