Giter Club home page Giter Club logo

Comments (7)

wolfy1339 avatar wolfy1339 commented on June 2, 2024 1

Sorry, I didn't realize you were using @octokit/app.

The solution you posted is almost entirely correct.

You don't have to pass the event to HandlerFunction<E, TTransformed>
The first parameter is the event name, the second is the value that is added onto the event object in the internals of the type.
The T & { octokit: Octokit } is extraneous

You can simply do it this way:

type _HandlerFunction<T extends EmitterWebhookEventName> = HandlerFunction<
  T,
  { octokit: Octokit }
>

from webhooks.js.

wolfy1339 avatar wolfy1339 commented on June 2, 2024

Your example has a syntax error.

I'm not sure why you would want to do that.

All the types for HandlerFunction are exported

You can simply do:

const onDeploymentStatus: HandlerFunction<"deployment_status"> = (event) => {
  // ...
}
app.on('deployment_status', onDeploymentStatus)

from webhooks.js.

mpint avatar mpint commented on June 2, 2024

HandlerFunction doesn't appear to be exported in "@octokit/webhooks": "^12.0.3". Am I missing something?

Screen Shot 2023-07-31 at 9 37 28 PM

from webhooks.js.

wolfy1339 avatar wolfy1339 commented on June 2, 2024

It isn't directly exported.

You have to import it from a specific file,

import type { HandlerFunction } from "@octokit/webhooks/dist-types/types.d";

from webhooks.js.

mpint avatar mpint commented on June 2, 2024

That works but octokit isn't provided by HandlerFunction

import type { HandlerFunction } from "@octokit/webhooks/dist-types/types.d"

const onPullRequestClosed: HandlerFunction<
  "pull_request.opened",
  unknown
> = async ({ octokit, payload }) => { ... }
Screen Shot 2023-07-31 at 10 48 10 PM

from webhooks.js.

wolfy1339 avatar wolfy1339 commented on June 2, 2024

Can you share what versions of Probot/Octokit packages you are using

from webhooks.js.

mpint avatar mpint commented on June 2, 2024

I'm using @octokit/[email protected], but HandlerFunction is coming from @octokit/[email protected]. Maybe I need the version from the @octokit/app package.

import type { HandlerFunction } from "@octokit/webhooks/dist-types/types.d"

const onPullRequestOpened: HandlerFunction<
  "pull_request.opened",
  unknown
> = async ({ octokit, payload }) => {}

Update:

Here's what I did to get it working with Octokit

import { Octokit } from "@octokit/rest"
import type { EmitterWebhookEventName } from "@octokit/webhooks"
import type { HandlerFunction } from "@octokit/webhooks/dist-types/types.d"

type _HandlerFunction<T extends EmitterWebhookEventName> = HandlerFunction<
  T,
  T & { octokit: Octokit }
>
const onPullRequestOpened: _HandlerFunction<"pull_request.opened"> = async ({
  octokit,
  payload,
}) => { ... }

from webhooks.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.