尝试通过 ts-patch 在 Angular 项目中使用 ts-nameof

2024-04-26

我正在使用 Angular 8.2 并安装ts-nameof https://github.com/dsherret/ts-nameof#ts-nameof4.2.2 对于我的项目和ts-patch https://github.com/nonara/ts-patch#ts-patch全球1.0.5。

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.

所以我添加了以下内容ts-patch例子 https://github.com/nonara/ts-patch#example-transformers部分到我的tsconfig.json:

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

and ran ng serve -o.

它仍然在抱怨Cannot find name 'nameof'..

我没有看到列出任何其他步骤,那么我做错了什么?


修复编译时错误Cannot find name 'nameof'

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

修复运行时错误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"
      }
    ]
  }
}

使用角度 10.1.6 进行测试

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

尝试通过 ts-patch 在 Angular 项目中使用 ts-nameof 的相关文章

随机推荐