【问题标题】:Typescript Cannot find name 'functionName'打字稿找不到名称'functionName'
【发布时间】:2018-01-25 15:37:45
【问题描述】:

我已经包含了类型并引用了它们。 我不确定打字是否正确,因为我不知道如何写。但这就是我所做的:

// 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" />

【问题讨论】:

  • 您声明的内容应该像 polylabel.polylabel(...) 一样使用。

标签: node.js typescript typescript-typings


【解决方案1】:

不要使用/// &lt;reference...,而是将.d.ts 文件添加到tsconfig.json"Files" 部分。

要使用此模块,请执行以下操作:

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

或(如果您使用的是命名空间而不是导入)

polylabel.polylabel(...)

【讨论】:

    猜你喜欢
    • 2018-01-18
    • 2016-09-15
    • 2019-02-25
    • 1970-01-01
    • 1970-01-01
    • 2016-01-28
    • 2017-06-18
    • 2018-11-28
    • 1970-01-01
    相关资源
    最近更新 更多