1
0
Fork 0

Update location of typescript definitions (#743)

https://github.com/octokit/webhooks.js#typescript
pull/817/head
Chris Mc 2021-05-20 16:49:57 -04:00 committed by GitHub
parent 3bd746139f
commit 8dc2d6eb6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 5 deletions

View File

@ -59,18 +59,19 @@ const newIssue = await octokit.rest.issues.create({
## Webhook payload typescript definitions ## Webhook payload typescript definitions
The npm module `@octokit/webhooks` provides type definitions for the response payloads. You can cast the payload to these types for better type information. The npm module `@octokit/webhooks-definitions` provides type definitions for the response payloads. You can cast the payload to these types for better type information.
First, install the npm module `npm install @octokit/webhooks` First, install the npm module `npm install @octokit/webhooks-definitions`
Then, assert the type based on the eventName Then, assert the type based on the eventName
```ts ```ts
import * as core from '@actions/core' import * as core from '@actions/core'
import * as github from '@actions/github' import * as github from '@actions/github'
import * as Webhooks from '@octokit/webhooks' import {PushEvent} from '@octokit/webhooks-definitions/schema'
if (github.context.eventName === 'push') { if (github.context.eventName === 'push') {
const pushPayload = github.context.payload as Webhooks.WebhookPayloadPush const pushPayload = github.context.payload as PushEvent
core.info(`The head commit is: ${pushPayload.head}`) core.info(`The head commit is: ${pushPayload.head_commit}`)
} }
``` ```