ChilliSniff
ChilliSniff9mo ago

cannot set property on fetch response

in the browser this works
let o = await fetch('https://deno.com');
o.asdf = 2
console.log(o.asdf)//2
let o = await fetch('https://deno.com');
o.asdf = 2
console.log(o.asdf)//2
but not in deno js
2 Replies
ChilliSniff
ChilliSniff9mo ago
ok i just tested it, it works also in deno js but it gets not logged when i log the object
Deno AI Helper
Deno AI Helper9mo ago
In Deno, the fetch() function returns a Response object that is based on the web standard Fetch API. According to the documentation, the Response object is read-only and its properties cannot be modified. This is why you cannot set a new property on a Response object in Deno. In your example, you're trying to set a new property asdf on the Response object o. This is not allowed in Deno, hence it doesn't work. If you need to store additional information related to a response, consider using a separate variable or data structure.