尝试通过 ts-patch 在 Angular 项目中使用 ts-nameof [英] Trying to use ts-nameof in Angular project via ts-patch

查看:29
本文介绍了尝试通过 ts-patch 在 Angular 项目中使用 ts-nameof的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Angular 8.2 并安装了 ts-nameof 4.2.2 用于我的项目和 ts-patch 1.0.5 全局.

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

我运行了 ts-patch installts-patch check 显示:

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 示例中添加了以下内容 部分到我的 tsconfig.json :

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

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

并运行ng serve -o.

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

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

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

推荐答案

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

使用 angular 10.1.6 测试

Tested with angular 10.1.6

这篇关于尝试通过 ts-patch 在 Angular 项目中使用 ts-nameof的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆