Mobx: Question: TypeScript & observable & key/value object

Created on 13 Jul 2017  路  1Comment  路  Source: mobxjs/mobx

interface MyType {
    id: string;
    name: string;
}

class Store {
    @observable byId: { [id: string]: MyType } = {};

    @computed get list(): MyType[] {
        return this.byId.values();
    }
}

I'm getting this error on the .values():

Cannot invoke an expression whose type lacks a call signature.
Type 'MyType' has no compatible call signatures.

What would be a proper way to define byId so that .values is available and returns MyType[]? Is there a generic type for this?

Most helpful comment

Found it!

@observable byId = new ObservableMap<MyType>();

>All comments

Found it!

@observable byId = new ObservableMap<MyType>();

Was this page helpful?
0 / 5 - 0 ratings

Related issues

weitalu picture weitalu  路  3Comments

cafreeman picture cafreeman  路  4Comments

mehdi-cit picture mehdi-cit  路  3Comments

josvos picture josvos  路  3Comments

kirhim picture kirhim  路  3Comments