2

我使用 node.js 7.44。

在文件 user.models.ts 我有 multilplie 类,如:

import { Exclude, Expose } from "class-transformer";

export class User {
    @Expose() _id: string;
    @Expose() fname: string;
    @Expose() lname: string;
    @Expose() birthday: Date;   
    @Expose() address: Address;

    constructor(){...}
}

@Exclude()
export class Address {
    @Expose() street: string;
    @Expose() num: number;
    @Expose() city: string;
    @Expose() zipCode: number;
}

当我编译服务器时,我得到了错误ReferenceError: Adress is not defined

如何在同一个文件中使用 multilplie 类?

4

1 回答 1

1

由于您使用的是Addressin User,因此您必须先定义Address。考虑使用 eslint 规则no-use-before-define

import { Exclude, Expose } from "class-transformer";

@Exclude()
export class Address {
    @Expose() street: string;
    @Expose() num: number;
    @Expose() city: string;
    @Expose() zipCode: number;
}

export class User {
    @Expose() _id: string;
    @Expose() fname: string;
    @Expose() lname: string;
    @Expose() birthday: Date;   
    @Expose() address: Address;

    constructor(){...}
}
于 2019-01-19T13:56:29.070 回答