Having issues with model with Dynamic Keys #1686
-
Hey all, I am getting a typescript error 'Type is not assignable error' for the following. I am not sure what I am doing wrong. Thanks in advance.
This is ok!
This is not!
It gives error
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @alex-hladun! TypeScript cannot infer all the needed information automatically in this case, so you can use self.storeArray.replace([
cast({
name: "McDonalds (Sarcee Beecon Hill)",
address: "1994 Maynard Rd. Calgary, AB, T2E6J8",
city: "Calgary",
iconUrl: "https://i.imgur.com/bwtfoyu.png",
coverUrl: "https://i.imgur.com/xPUF6zr.png",
storeNumber: 1001,
storeHours: {
Monday: {
open: true,
times: [{ openTime: 900, closeTime: 1700 }]
}
}
})
]); There is also a tiny error in the first snippet, but I'm not sure why TypeScript can't pick that up in the map self.stores.clear();
self.stores.set("1001", {
name: "McDonalds (Sarcee Beecon Hill)",
address: "1994 Maynard Rd. Calgary, AB, T2E6J8",
city: "Calgary",
iconUrl: "https://i.imgur.com/bwtfoyu.png",
coverUrl: "https://i.imgur.com/xPUF6zr.png",
storeNumber: 1001,
storeHours: {
Monday: {
open: true,
times: [{ openTime: 900, closeTime: 1700 }]
}
}
}); |
Beta Was this translation helpful? Give feedback.
Hi @alex-hladun!
TypeScript cannot infer all the needed information automatically in this case, so you can use
cast
to cast the node snapshot to an instance type. You will then see that there is a slight error in the code; it's supposed to beopenTime
andcloseTime
:There is also a tiny error i…