Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import nameof function from the ts-nameof package that is not exported in d.ts

I found an interesting package and want to use it in my typescript application: https://github.com/dsherret/ts-nameof

But I cannot import nameof function. It is not exported in d.ts file:

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;
}

How should I import nameof function into my typescript module?

for import 'ts-nameof'; I have Uncaught ReferenceError: nameof is not defined error.

like image 986
Ievgen Martynov Avatar asked Jun 21 '17 09:06

Ievgen Martynov


1 Answers

Add this into tsd.d.ts:

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

Make sure to put correct path to node_modules

like image 112
MistyK Avatar answered Sep 23 '22 16:09

MistyK