dsherret / ts-nameof

nameof in TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Request] - Mention a plugin interaction

MrcSnm opened this issue · comments

Hello!
I've made some plugin for webpack that generates a C-Like macro. So, I've been using this plugin with ts-nameof, and it has a great relationship with this plugin.

For instance, I could define a new macro called _LOG: which would log the variable name with its value

DEFINE(_LOG, (v) =>
{
console.log(nameof(v) + " = ", v);
});
When this function is called anywhere, the output code would be the filename where this function is called, every compile time feature has much to gain from that as it is a simple text replace tool.

//index.ts

let myName = "Test";

_LOG(myName); //myName = "Test"

By using macro functions, no variable name is lost at the function call, which makes a perfect candidate to use together with the nameof plugin
Hope you take a look and we could work in some more interactions for define_macro-loader