为什么这样做:
let provider = new Provider();
var keys = Object.keys(provider);
console.log(keys);
在以下情况下返回空数组
:let provider = { Name: '', Surname: '' };
var keys = Object.keys(provider);
console.log(keys);
是否返回其中具有2个属性的数组?
这是我的Provider.ts
:
export class Provider {
public Id: string;
public Name: string;
public FriendlyName: string;
public CompanyRegistrationNumber: string;
public VatRegistrationNumber: string;
public TfgUniqueReferenceNumber: string;
public Since: Date;
public Until: Date;
public DefaultBillingDay: number;
public DefaultProvisioningDay: number;
public AllowsToProvisionProRata: boolean;
public AllowsToBillProRata: boolean;
public EmailAddress: string;
public DateCreated: Date;
public DateModified: Date;
public UserCreated: string;
public UserModified: string;
public IsRetired: boolean;
public ImageUrl: string;
public ContactNumber1: ContactNumber;
public ContactNumber2: ContactNumber;
public PhysicalAddress: Address;
public PostalAddress: Address;
public FinancialSystemAccount: FinancialSystemAccount;
public WholesaleProducts: Array<WholesaleProduct>;
public ContactPeople: Array<ContactPerson>;
public Batches: Array<Batch>;
public BatchCandidates: Array<BatchCandidate>;
public AllowableBatchTypes: Array<BatchType>;
}
答案 0 :(得分:3)
除非初始化属性,否则实际上不会创建它们。您可以检查已交易的Provider.js
文件并进行验证。这只是一种告诉编译器的方法,每当我们在Provider
实例中使用时,都将强制使用那些预定义的类型。
这堂课
class Provider {
public Id: string;
public Name: string;
public FriendlyName: string;
public CompanyRegistrationNumber: string;
public VatRegistrationNumber: string;
public TfgUniqueReferenceNumber: string;
public InitializedProp: string = '';
}
被交易到:
var Provider = (function () {
function Provider() {
this.InitializedProp = '';
}
return Provider;
}());
您可以看到,仅InitializedProp
被创建为经过转换的构造函数中的属性。