在我的express + typescript 项目中创建 TypeORM 实体时,我遇到了以下错误:
Unable to resolve signature of class decorator when called as an expression.
The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.
Run Code Online (Sandbox Code Playgroud)
这是代码(从 TypeORM 文档复制粘贴)
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number
@Column()
firstName: string
@Column()
lastName: string
@Column()
age: number
}
Run Code Online (Sandbox Code Playgroud)
所有属性也会出现此错误:Property 'age' has no initializer and is not definitely assigned in the constructor
我不知道发生了什么,因为它是透明的粘贴,而且我之前已经将 typeorm 与 Nestjs 一起使用过,没有任何问题
Tre*_*phy 13
问题出在 tsconfig 内部,因为我忘记在配置中启用装饰器以及禁用 strictPropertyInitialization
这是代码中的解决方案:
tsconfig.json:
...
"experimentalDecorators": true,
"strictPropertyInitialization": false,
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2158 次 |
| 最近记录: |