mapbox / polylabel

A fast algorithm for finding the pole of inaccessibility of a polygon (in JavaScript and C++)
Other
1.44k stars 151 forks source link

Typings not working. #31

Closed Zahma closed 7 years ago

Zahma commented 7 years ago

I have tried to work with the typings you provided but its not working.

So I tried to put some modificationsand I ended up with the following code:

declare namespace polylabel {
/**
 * Polylabel returns the pole of inaccessibility coordinate in [x, y] format.
 * 
 * @name polylabel
 * @function
 * @param {Array<number>} polygon - Given polygon coordinates in GeoJSON-like format
 * @param {number} precision - Precision (1.0 by default)
 * @param {boolean} debug - Debugging for Console 
 * @return {Array<number>}
 * @example
 * var p = polylabel(polygon, 1.0);
 */
function polylabel(polygon: number[][][], precision?: number, debug?: boolean): number[];
}

declare module "polylabel" {
    export = polylabel.polylabel;
}

Still I'm getting the following error:

cannot get a expression whose type lacks a call signature

mourner commented 7 years ago

This repo does not provide TypeScript definitions. You should report this to the author on a corresponding repo, not here. @DenisCarriere perhaps?

DenisCarriere commented 7 years ago

@Zahma I've pushed an update to the Typescript definition file (https://github.com/DefinitelyTyped/DefinitelyTyped/pull/19869), if there are any updates on the TypeScript definitions, post them on DefinitelyTyped or submit a PR with a fix.

If you define your own typings, you can use the following:

declare function polylabel(polygon: number[][][], precision?: number, debug?: boolean): number[];
declare namespace polylabel {}
export default polylabel;
DenisCarriere commented 7 years ago

@Zahma Another thing to note, how are you importing the polylabel module, the current Type Definition does work using the following:

import * as polylabel from 'polylabel';
console.log(polylabel);
//={ [Function: polylabel] default: [Circular] }