What happened?
I tried to call verifyAndReceive with name=request.headers["x-github-event"], and got a type error because the header's type is string, but verifyAndReceive expects WebhookEventName, which isn't even exported from the library. It turns out that
|
const eventName = request.headers["x-github-event"] as WebhookEventName; |
is casting without checking (and then
unnecessarily casts to
any on top of that), which indicates that
verifyAndReceive should probably just take a
string.
Alternatively, the library could expose a function to validate the event name and maybe payload structure, but that seems like more work than just loosening up the types.
A secondary question is whether receive should also take looser types for name and payload.
|
return state.eventHandler.receive({ |
|
id: event.id, |
|
name: event.name, |
|
payload, |
|
} as EmitterWebhookEvent); |
casts without checking, which seems to indicate that it should, but doing that takes more surgery on
BaseWebhookEvent to make it correctly infer the payload type when the event name does happen to be constrained.
Versions
Typescript 5.6
Relevant log output
No response
Code of Conduct
What happened?
I tried to call
verifyAndReceivewithname=request.headers["x-github-event"], and got a type error because the header's type isstring, butverifyAndReceiveexpectsWebhookEventName, which isn't even exported from the library. It turns out thatwebhooks.js/src/middleware/node/middleware.ts
Line 78 in 6531c97
webhooks.js/src/middleware/node/middleware.ts
Line 98 in 6531c97
anyon top of that), which indicates thatverifyAndReceiveshould probably just take astring.Alternatively, the library could expose a function to validate the event name and maybe payload structure, but that seems like more work than just loosening up the types.
A secondary question is whether
receiveshould also take looser types fornameandpayload.webhooks.js/src/verify-and-receive.ts
Lines 41 to 45 in 6531c97
BaseWebhookEventto make it correctly infer the payload type when the event name does happen to be constrained.Versions
Typescript 5.6
Relevant log output
No response
Code of Conduct