【问题标题】:Import nameof function from the ts-nameof package that is not exported in d.ts从 d.ts 中没有导出的 ts-nameof 包中导入 nameof 函数
【发布时间】:2017-11-24 03:12:59
【问题描述】:

我发现了一个有趣的包并想在我的打字稿应用程序中使用它: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;
}

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

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

【问题讨论】:

    标签: javascript typescript


    【解决方案1】:

    将此添加到tsd.d.ts

    /// <reference path="../node_modules/ts-nameof/ts-nameof.d.ts" />
    

    确保将正确的路径放入node_modules

    【讨论】:

    • 您将tsd.d.ts 文件放在哪里?我是否需要从每个 ts 文件中引用它,或者我可以以某种方式在整个项目中引用它一次?
    猜你喜欢
    • 2022-07-08
    • 1970-01-01
    • 2017-10-06
    • 2018-11-01
    • 2018-02-03
    • 2020-02-14
    • 2020-11-10
    • 2016-02-12
    • 1970-01-01
    相关资源
    最近更新 更多