2017-08-17 156 views
0

我已經包括了類型並引用它們。 我不確定這些打字是否正確,因爲我不知道如何寫。但是,這是我做過什麼:Typescript找不到名稱'functionName'

// This is where I'm getting Cannot find name 'Polylabel' 
geometry: polylabel(feat.geometry.coordinates) 

我已經包含了這些分型:

declare module "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[]; 
namespace polylabel {} 
export = polylabel;} 

和參考它如下:

/// <reference path="globals/@types/polylabel/index.d.ts" /> 

回答

0

而不是使用/// <reference....d.ts文件添加到您的tsconfig.json,在"Files"部分。

要使用這個模塊做到這一點:

import * as polylabel from 'polylabel'; 
polylabel.polylabel(...) 

或者(如果您使用的命名空間,而不是進口)

polylabel.polylabel(...)