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

ES6 Map autoconverted to {}? [duplicate]

$
0
0

In my React Native + TypeScript app, I've defined a bunch of types as follows:

export type Streak = {    ...    marked: Map<number, string>};export type Habit = {  ...   ...  streak: Streak,  ...}

When I save Habit to AsyncStorage and read it back, I seem to be losing the Map type of the marked field, since I get marked back as an object {} type, and I cannot invoke functions like keys() or has() etc on marked.

await AsyncStorage.setItem(habit.key, JSON.stringify(habit));........let res = await AsyncStorage.getItem(habit.key);let habit: Habit = JSON.parse(res); // I thought specifying the type Habit here would have given me `marked` back as a Mapif (habit.streak.marked.has(<someKey>)) { ... }

TypeError: ... marked.has is not a function ...

What should I be doing to preserve the Map type?


Viewing all articles
Browse latest Browse all 6290

Trending Articles



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