从 d.ts 中没有导出的 ts-nameof 包中导入 nameof 函数

Iev*_*nov 6 javascript typescript

我发现了一个有趣的包,并想在我的打字稿应用程序中使用它:https : //github.com/dsherret/ts-nameof

但我无法导入nameof功能。它不会在 d.ts 文件中导出:

declare module "ts-nameof" {
    interface Api {
        ...
    }
    var func: Api;
    export = func;
}

declare function nameof<T>(func?: (obj: T) => void): string;
declare function nameof(obj: Object | null | undefined): string;
declare namespace nameof {
    function full<T>(periodIndex?: number): string;
    function full(obj: Object | null | undefined, periodIndex?: number): string;
}
Run Code Online (Sandbox Code Playgroud)

我应该如何将nameof函数导入我的打字稿模块?

因为import 'ts-nameof';我有Uncaught ReferenceError: nameof is not defined错误。

Mis*_*tyK 3

将其添加到tsd.d.ts

/// <reference path="../node_modules/ts-nameof/ts-nameof.d.ts" />
Run Code Online (Sandbox Code Playgroud)

确保输入正确的路径node_modules