You need to ensure that you've correctly setup the prerequisites for using TypeScript transform plugins.
TypeScript transform plugins like ts-nameof require some setup because they rely on the transform compiler,ttypescript.
What you need to do:
1. Install ttypescript and ts-nameof:
npm i ttypescript ts-nameof @types/ts-nameof -D
2. Add ts-nameof to your plugins array in tsconfig.json:
{
"compilerOptions": {
"noEmitOnError": true,
"target": "ES2020",
"plugins": [{ "transform": "ts-nameof", "type": "raw" }],
}
}
3. Change the path to your tsdk to the location ofttypescript in your vscode users settings:
"typescript.tsdk": "node_modules/ttypescript/lib" // this is for intellisense
4. Run with npx
npx ttsc
Then:
const name = nameof<MyClass>();
will generate:
const name = "MyClass";
Example:
ts-nameof-example
Original documentation: