Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to use ts-nameof in Angular project via ts-patch

I'm using Angular 8.2 and installed ts-nameof 4.2.2 for my project and ts-patch 1.0.5 globally.

I ran ts-patch install and ts-patch check shows:

Checking TypeScript v3.5.3 installation in [...]
[+] tsc.js is patched with ts-patch version 1.0.5.
[+] tsserverlibrary.js is patched with ts-patch version 1.0.5.
[+] typescript.js is patched with ts-patch version 1.0.5.
[+] typescriptServices.js is patched with ts-patch version 1.0.5.

So I added the following from the ts-patch examples section to my tsconfig.json:

{
  "compilerOptions": {
    "plugins": [
      { "transform": "ts-nameof", "type": "raw" }
    ]
  }
}

and ran ng serve -o.

It's still complaining about Cannot find name 'nameof'..

I don't see any additonal steps listed, so what am I doing wrong?

like image 496
Steffen Avatar asked Oct 28 '22 02:10

Steffen


1 Answers

To fix compile time error Cannot find name 'nameof'

// tsconfig.json
{
  "compilerOptions": {
    ...
    "types": [..., "ts-nameof"]
  }
}

To fix runtime error Uncaught ReferenceError: nameof is not defined

# install ts-patch
yarn add -D ts-patch
ts-patch install
// tsconfig.json
{
  "compilerOptions": {
    ...
    "plugins": [
      {
        "transform": "ts-nameof",
        "type": "raw"
      }
    ]
  }
}

Tested with angular 10.1.6

like image 163
Edison Avatar answered Dec 21 '22 14:12

Edison