打字稿中类的新实例

时间:2018-08-10 17:14:24

标签: typescript class angular6

我正在使用angular6。我想创建一个类的新实例,但是在下面的“警告”文本之间收到警告。

错误文本:“未定义EntityLocationGetDto”

此外,我创建了一个构造函数,但无法再次使用。

那是我的密码;

customer.ts:

abstract class EntityGetDto<PK> {
    public Id: PK;
    public CreatedDate: Date;
    public UpdateDate: Date;
    public CreatedBy: string;
    public UpdatedBy: string;
}
abstract class EntityLocationGetDto<PK> extends EntityGetDto<PK> {
    public StateId?: string;
    public CityId?: string;
    public CountyId?: string;
}
export class CustomerCartDto extends EntityLocationGetDto<string> {
    FullName: string;
    Adress?: string;
    PostCode?: string;
    Email?: string;
    Web?: string;
    TaxOffice?: string;
    TaxIdNumber?: string;
    PhoneNumber?: string;
    MobileNumber?: string;
    FaxNumber?: string;
    BirthDay?: Date;
}

customer.service.ts:

import { CustomerCartDto } from './customer';
@Injectable()
export class CustomerService {
constructor() { }
getById(customerId: string): CustomerCartDto {
    const custId: string = customerId.replace('xx', '');
   WARNING =>  const res: CustomerCartDto = new CustomerCartDto(); <= WARNING 
    res.FullName = 'xx' + custId;
    res.Email = 'xx_' + custId + '@hotmail.com';
    res.Web = 'xx.com';
    res.PhoneNumber = null;
    res.MobileNumber = '0123456789';
    res.FaxNumber = null;
    res.BirthDay = null;
    res.Id = 'xx' + custId;
    res.CreatedDate = new Date();
    res.UpdateDate = new Date();
    res.CreatedBy = null;
    res.UpdatedBy = null;
    return res;
  }
}

而且,它的工作原理是这样的

const res: CustomerCartDto = {
      FullName: 'xx' + custId,
      Email: 'xx_' + custId + '@hotmail.com',
      Web: 'xx.com',
      PhoneNumber: null,
      MobileNumber: '0123456789',
      FaxNumber: null,
      BirthDay: null,
      Id: 'xx' + custId,
      CreatedDate: new Date(),
      UpdateDate: new Date(),
      CreatedBy: null,
      UpdatedBy: null
    };

谢谢。

0 个答案:

没有答案