@hipreme_entertainment/decltype-loader

1.0.1 • Public • Published

decltype-loader

WARN: Typescript Only

This is a webpack loader, which uses Regexes for finding the type declared for a variable. That means it can't find any decltype that wasn't defined in the same file. I did like that because for my purposes, it is good enough.

For using it, it requires a typescript loader or a babel plugin inside your webpack config. After that, you can add to your loader config

{ test: /\.tsx?$/, use: [{ loader: path.resolve('../decltype-loader.js'), options: {keyword:"decltype"}}]}

For applying it in your code, just call the following:

decltype(variable)

By doing that, you will be able to retrieve what type is defined. It will take a variable that was defined like

const variable : string = "";

By doing that, it will replace any decltype(variable) with string; If you need it stringified, you can do the following:

console.log(decltype("variable"))

With that, decltype will expand to "string".

If you need to take a class decltype, you use the "this"

class Test
{
    public _type : string;
    constructor()
    {
        this._type = decltype("this");
        console.log(decltype("this._type"))
    }
}

With that, the property _type will get the value "test". and will print "string"

REMINDER

  • It does not work inter-modules
  • It may conflict when variables have the same name
  • Open for pull requests

/@hipreme_entertainment/decltype-loader/

    Package Sidebar

    Install

    npm i @hipreme_entertainment/decltype-loader

    Weekly Downloads

    3

    Version

    1.0.1

    License

    ISC

    Unpacked Size

    8.69 kB

    Total Files

    9

    Last publish

    Collaborators

    • hipreme