我有一个我试图扩展的打字稿界面,但在运行时我的属性和方法都缺失了。有人可以看一看,看看我做错了什么吗?
从TypeLite生成的继承接口
declare module ModelsShared {
interface AddressModel {
Country: ModelsSupportingData.SupportingDataModel;
County: string;
Line1: string;
Line2: string;
Line3: string;
Postcode: string;
Town: string;
}
}
由于我无法自动重新生成这些界面,因此我使用自己的界面对其进行了扩展:
interface IAddressModel extends ModelsShared.AddressModel {
FlatString: string;
asFlatString() : string;
}
然后使用导出的类实现该接口:
export class AddressModel implements IAddressModel {
public Country: ModelsSupportingData.SupportingDataModel;
public County: string;
public Line1: string;
public Line2: string;
public Line3: string;
public Postcode: string;
public Town: string;
public FlatString : string;
public asFlatString = (): string => {
return "A nice formatted address";
}
}
但是,即使将地址转换为我的界面,例如:
let address: IAddressModel = (user.Address as IAddressModel);
虽然VS很高兴,但我没有在运行时获得属性或方法,我只是未定义。