【发布时间】:2020-11-27 04:59:39
【问题描述】:
我正在使用 graphQL Apollo、Postgres、Express.js 来构建一个小型网站。
我正在选择一个现有的profile,我想更新它的firstName 和lastName
我的代码
const profile = await Profile.findOne({where: { user: payload!.userId}})
if (profile) {
console.log(profile) <-- It returns correctly the profile I am looking for
await profile.save({
firstName, <-- Error here
lastName
})
但是,我收到以下错误:
'{ firstName: string; 类型的参数姓氏:字符串; }' 不可分配给“SaveOptions”类型的参数。 对象字面量只能指定已知属性,而“SaveOptions”类型中不存在“firstName”。ts(2345)
错误:https://imgur.com/a/Khdn6LH
我认为问题在于配置文件的 type,即 Profile |未定义。 其中 Profile 是从 typeORM 实体推断出来的:
@ObjectType()
@Entity("profile")
export class Profile extends BaseEntity{
@Field(()=>String)
@Column({ nullable: true })
firstName: string;
@Field(()=>String)
@Column({ nullable: true })
lastName: string;
}
【问题讨论】:
标签: typescript typeorm