Тип изображения, требуемый в дереве состояний React-Native MobX: «Возможный необработанный отказ от обещания» - PullRequest
0 голосов
/ 03 мая 2020

Возможно, я делаю это неправильно, но каков тип "изображения" в модели дерева состояний mobx?
Как добавить свойство в модель MST в реакции-нативе для хранения свойства stati c image?

const default_img = {
  img1: require("./images/01.png"),
  img2: require("./images/02.png")
}

const userData = [{
  id: 1,
  name: "name1",
  avatar: default_img.img1
},{
  id: 2,
  name: "name2",
  avatar: default_img.img2
},
}]


export const UserModel = types.model({
  id: types.identifierNumber,
  name: types.string,
  avatar: types.maybe(types.string) // <-- this the error below
})

export const RootStoreModel = types.model("RootStore").props({
  users: types.array(UserModel)
}).actions(self => ({
  afterCreate() {
    self.users = userData
  }
}))

Ошибка:

Possible Unhandled Promise Rejection (id:0):
Error: [mobx-state-tree] Error while converting `...` to `AnonymousModel[]``
at path `...` value is not assignable to type `(string | undefined)` (No type is applicable for the union)
...