小编S T*_*X K的帖子

类型缺少以下属性

我需要一些帮助。我使用 typeorm 创建 User 实体,并且想在 Customer 类中覆盖 toResponseObject 以更改返回属性,但是当我写入完成时,错误发生为“Type '{ userName: string; firstName: string; lastName: string; email: string; address : Address; token: string; }' 缺少类型“User”中的以下属性:password、hasPassword、toResponObject、comparePassword” 我想这意味着我应该返回所有用户属性,但我不想返回所有属性。我应该怎么办?

用户实体.ts

import {PrimaryColumn, Column, BeforeInsert} from "typeorm";
import * as bcrypt from 'bcryptjs'
import * as jwt from 'jsonwebtoken'

export abstract class User {

    @PrimaryColumn()
    userName: string;

    @Column()
    password: string;

    @Column()
    firstName: string;

    @Column()
    lastName: string;

    @Column()
    email: string;

    @BeforeInsert()
    async hasPassword(){
        this.password = await bcrypt.hash(this.password,10)
    }

    async toResponObject(showToken:boolean = true){
        const {userName,firstName,lastName,email,token} = …
Run Code Online (Sandbox Code Playgroud)

typescript typeorm

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

typeorm ×1

typescript ×1