小编Tre*_*phy的帖子

TypeORM 不接受实体

在我的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 一起使用过,没有任何问题

typeorm

4
推荐指数
1
解决办法
2158
查看次数

标签 统计

typeorm ×1