我无法创建BehaviourSubject
我期望有一个json
可以映射到以下Typescript
类
export class GetDataAPI {
'some-data':string;
constructor (public title:string,
public description:string,
public tags:Array<string>,
public someData:string
){
this['some-data'] = someData;
}
}
在我的代码中,我创建了一个BehaviourSubject
,如下所示:
private dataSubject: BehaviorSubject<GetDataAPI>;
当我尝试初始化BehaviourSubject
时,出现编译错误this.dataSubject = new BehaviorSubject<GetDataAPI>({});
错误为error TS2345: Argument of type '{}' is not assignable to parameter of type 'GetDataAPI'.
Property ''some-data'' is missing in type '{}'.
答案 0 :(得分:0)
我必须创建一个指定所有参数的对象,即
new BehaviorSubject<GetDataAPI>({'some-data':'',
'title':'',
'description':'',
'tags':[],
'someData':''});