You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As you can see from example above original `ps` list was of `Point` records while mapped `xs` list is of numbers and that is refleced in the type of the list. Although given that JS is untyped language theer is no guarantee that mapping function will return values of the same type which makes things little more complex, result of such mapping will be list of union type of all types that mapping funciton produced (see types section for union types).
227
227
228
+
### Map
229
+
230
+
You can define a typed map by providing `Map` the type for the key and the type for the value:
Typed maps may contain only entries with key and value that match the specified type:
245
+
246
+
```js
247
+
248
+
Products([[1, "Mapper 1000"]])
249
+
// => TypeError: Invalid value: Invalid data structure "Mapper 1000" was passed to Product
250
+
251
+
Products().set("P1", {name:"Mapper 1000"})
252
+
// TypeError: Invalid key: "P1" is not a number
253
+
254
+
// All keys in an object are strings, so this fails too:
255
+
Products({1: {name:"Mapper 1000"}}) // TypeError: Invalid key: "1" is not a number
256
+
```
257
+
258
+
Note the last example - all keys in an object are strings so if you instantiate a map from an object the type of your key must be a string (or something that handles strings).
259
+
260
+
As with other types Typed maps can also be named for convenience:
0 commit comments