我正在使用 Angular 8.2 并安装了 ts-nameof
4.2.2 用于我的项目和 ts-patch
1.0.5 全局。
我跑了ts-patch install
和 ts-patch check
显示:
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
examples 添加了以下内容部分到我的 tsconfig.json
:{
"compilerOptions": {
"plugins": [
{ "transform": "ts-nameof", "type": "raw" }
]
}
}
然后跑
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"
}
]
}
}
用 Angular 10.1.6 测试
关于angular - 尝试通过 ts-patch 在 Angular 项目中使用 ts-nameof,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59937480/