README
This is a transformer for the TypeScript compiler that adds a whole new nameof keyword.
Example usage with WebPack and ts-loader:
In webpack.config.js:
- Import the nameof transformer
const nameOfTransformer = require("./node_modules/@abstraqt-dev/nameof/lib/transformer").default;
- In the rules sction
rules: [
{
test: /\.(ts|tsx)$/,
loader: 'ts-loader',
options: {
getCustomTransformers: (program) => ({
before: [nameOfTransformer(program)],
after: []
})
},
exclude: /node_modules/,
},
- In tsconfig.json add the library to the included declarations files
{
...,
"types": [
"@abstraqt-dev/nameof"
],
...
}
In your code now you can just use the nameof keyword:
interface IFoo {
}
class Bar {
}
let foo = nameof<IFoo>();
let bar = nameof<Bar>();
console.log(foo); // "IFoo"
console.log(bar); // "Bar"