Skip to content

Commit 03842c4

Browse files
committed
fix: FexiosFinalContext.data should be readonly
1 parent 90a8c7c commit 03842c4

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/types.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,30 @@ export type FexiosFinalContext<T = any> = Omit<
128128
| 'responseType'
129129
| 'url'
130130
| 'query'
131+
| 'data'
131132
> & {
132133
/** Response Headers */
133134
readonly headers: Headers
135+
/**
136+
* Resolved response body
137+
* @note
138+
* This is a read-only property,
139+
* if you want to completely replace the ctx.data,
140+
* you should return Response in `afterResponse` hook.
141+
* @example
142+
* ```
143+
* // DO THIS √
144+
* fx.on('afterResponse', (ctx) => {
145+
* return Response.json({ newData: 'new data' }, { status: 200 })
146+
* })
147+
* // DON'T DO THIS ×
148+
* fx.on('afterResponse', (ctx) => {
149+
* ctx.data = { newData: 'new data' } // error!
150+
* return ctx
151+
* })
152+
* ```
153+
*/
154+
readonly data: T
134155
/**
135156
* Response type of data
136157
* If not set in request options, it will be guessed based on content-type header.

0 commit comments

Comments
 (0)