我在该接口中有一个接口,其中有一个名为data
的属性,它是一个array.
所以看起来是这样的:
type Data = { prop1: string; prop2: string }[];
interface MyInterface {
prop1: string;
data: Data;
}
现在我有了RxJS流,
在该流中,接口为MyInterface
.
所以现在我想在data属性中显示一些稍微不同的东西. 所以我所做的就是扩展添加新的价值
type DataExtended = Data & {
newValue: string
}
将该新类型添加到扩展接口
interface MyInterfaceExtended extends MyInterface {
data: DataExtended
}
现在在控制器中,我调用了一个服务,该服务具有一个预期结果为MyInterface
的HTTP服务.但我需要更改该数据 struct ,因此我有以下内容:
var myData$ = Observable<MyInterfaceExtended>;
constructor(private myService:myservice){
this.myData$ = this.myService.get().pipe((map(value)) => {
foreach(value.data, (data) =>{
data.newValue = 'new';
})
return value
})
}
但我一直收到这样的错误:
类型{ETC}上不存在‘newValue’
为什么会这样呢?