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

Set default value of boolean to false instead of undefined

$
0
0

I have a type

export type ItemResponse = {....addedManually: boolean;....}

At some point I parse a JSON response into this type like this:

  const response = await fetch(      `https://api.com`    );    const json: ItemResponse = await response.json();    console.log(json?.manuallyAdded)    return json;

The console log gives me undefined, because my API does not return any value for manuallyAdded. This field is only needed for usage inside the client-Application. I expected manuallyAdded to be false by default, but it is undefined. How can I get around this. I would like to avoid manually setting this filed to false for each response. Would there be any easy JS/TS way to change the default value without adding another wrapper-type?

Thanks in advance


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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