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