Javascript 使用observable.map()而不是asMap()时出现Typescript错误
在带有Javascript 使用observable.map()而不是asMap()时出现Typescript错误,javascript,typescript,mobx,Javascript,Typescript,Mobx,在带有asMap的第2版中,我曾经初始化一个空的可观察贴图,如下所示: class Store{ @observable private collection: ObservableMap<SomeType> = asMap() } @observable private collection: ObservableMap<SomeType> = observable.map({}) 我能想到的避免此错误的唯一方法是: class Store{ @ob
asMap
的第2版中,我曾经初始化一个空的可观察贴图,如下所示:
class Store{
@observable private collection: ObservableMap<SomeType> = asMap()
}
@observable private collection: ObservableMap<SomeType> = observable.map({})
我能想到的避免此错误的唯一方法是:
class Store{
@observable private collection: ObservableMap<SomeType>;
constructor(props: Props) {
super(props);
let fakeObj = {} as SomeType
this.collection = observable.map({fake:fakeObj})
}
}
类存储{
@可观测私人收藏:可观测地图;
建造师(道具:道具){
超级(道具);
设fakeObj={}为SomeType
this.collection=observable.map({false:fakeObj})
}
}
这是在不使用任何
的情况下避免类型错误的唯一方法吗?可以@observable private collection:ObservableMap=observable.map()
为您工作吗?可以@observable private collection:ObservableMap=observable.map()
为您工作吗?