I'm having issues creating a typescript definition file a 'simple' npm module.
Here are the details:
Issue: when I compile the typescript it get the following error:
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 only has one public function. it is in a file geojson.js:
(function(GeoJSON) {
GeoJSON.version = '0.3.0';
GeoJSON.defaults = {};
// The one and only 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 includes
"main": "./geojson",
"name": "geojson",
//// I ADDED THIS TYPE DEF FILE
"typings": "./geojson.d.ts",
From this i gather
- module name: geojson
- parse: signature is parse(objects: any, params: any, callback?: any): any;
- GeoJSON is an interface ?
My definition file is: geojson.d.ts
export declare module geojson {
interface GeoJSON {
parse(objects: any, params: any, callback?: any): any;
}
}
My tsconfig file is:
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
}
}
I'm trying to import (I've tried 1000 ways..) here are some:
import GeoJSON from 'geojson';
import geojson from 'geojson';
import {geojson} from geojson;
import geojson = require('geojson');
import GeoJSON = require('geojson');
What am I doing wrong?