2017-08-17 160 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(...)