-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(types): accept string event.name for receive() #434
Conversation
I disagree with you, I think you should use this code webhooks.receive({
id: request.headers["x-github-delivery"],
name: request.headers["x-github-event"] as EmitterWebhookEventName,
payload: request.body,
}); |
That's a runtime check targeted as JS users - allowing |
@G-Rath Okay, I've removed the @wolfy1339 |
Pretty much the same thing as with the Again as with (Also note that we're warning not erroring for this check) |
The examples in the docs had me thinking that e.g. |
Neither side is - that responsibility lies with the caller of the function (aka whoevers consuming the dependency). The example in the documentation is using the We do some basic runtime checking for our JS users for the things that are cheap and easy to check, but we only warn on the actual event names because we don't want to be too restrictive - otherwise the library would be unusable if we were ever missing an event (i.e a bug/typo in our schemas, using a fancy new event that we'd not implemented schemas for, or even maybe custom endpoints or prototyping because you're working at Github on implementing that fancy new event). |
Isn't |
That would require us to error instead of warn on event names, which we don't want to do because we don't want to be too restrictive. There are pros and cons to both approaches, but this library has gone the route of warning meaning at the very least changing it to error would be a breaking change. |
This comment has been minimized.
This comment has been minimized.
🤦 I used the wrong issue number, sorry - I meant to close #431 with that PR. |
I see my mistake: if |
Since #428 I get the following type error:
Instead of changing
webhooks.receive()
to matcheventHandler.receive()
(as in #428), can we do the reverse and changeeventHandler.receive()
to matchwebhooks.receive()
(as in this PR)?I additionally added
| undefined
because:.receive()
webhooks.js/src/event-handler/receive.ts
Lines 46 to 48 in b799113
request.headers["x-github-event"]!
or test it before calling.receive()
(redundant since it's checked again by.receive()
) when running with--noUncheckedIndexedAccess