Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6212

Type of image require in React-Native MobX-state-tree: "Possible Unhandled Promise Rejection"

$
0
0

Probably I'm doing it wrong, but what is the type of an "image" in a mobx-state-tree model?
How can I add a property to a MST model in react-native to hold a static 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  }}))

Error:

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)

Viewing all articles
Browse latest Browse all 6212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>