Skip to content

Commit

Permalink
Merge pull request #1281 from iiroj/fix-earlyresponse-type
Browse files Browse the repository at this point in the history
fix: make request.earlyResponse an optional field in TypeScript type definitions
  • Loading branch information
willfarrell authored Feb 27, 2025
2 parents 7641859 + 2bcdfd1 commit 82ba616
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface Request<
event: TEvent
context: TContext
response: TResult | null
earlyResponse: TResult | null
earlyResponse?: TResult | null | undefined
error: TErr | null
internal: TInternal
}
Expand Down
7 changes: 5 additions & 2 deletions packages/core/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,15 @@ expectType<middy.MiddyfiedHandler<APIGatewayProxyEvent, number>>(
)

// Issue #1275 Early Response type
middy()
middy<unknown, string>()
.before(async (request) => {
request.earlyResponse = 'Hello, world!'
})
.use({
after: (request) => {
request.earlyResponse = 'Hello, world!'
request.earlyResponse = null
}
})
.onError(async (request) => {
request.earlyResponse = undefined
})
1 change: 0 additions & 1 deletion packages/util/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ TInternal
succeed: () => {}
},
response: null,
earlyResponse: null,
error: null,
internal: {
boolean: true,
Expand Down

0 comments on commit 82ba616

Please sign in to comment.