🌐 Frontend & Web

Promise Decoration: Fetch Ergonomics That Won't Break Your Response

You've typed await response.json() a hundred times too many. One dev's Promise decoration trick delivers client.get('/api/todos').json() without sacrificing native fetch semantics.

Code snippet decorating a fetch Promise with .json() and .text() methods

⚡ Key Takeaways

  • Attach Response methods directly to fetch Promises via descriptors for chainable .json() without wrappers. 𝕏
  • Non-enumerable, locked props preserve native interop while hiding extras from iteration/JSON. 𝕏
  • Guards against re-decoration; ideal for plugin systems but watch test mocking. 𝕏
Published by

theAIcatchup

Ship faster. Build smarter.

Worth sharing?

Get the best Developer Tools stories of the week in your inbox — no noise, no spam.

Originally reported by dev.to

Stay in the loop

The week's most important stories from theAIcatchup, delivered once a week.