1
0
Fork 0

Update readme with type assertion information (#310)

* Update readme with type assertion information

* PR updates
pull/320/head
Thomas Boop 2020-01-22 11:53:39 -05:00 committed by GitHub
parent 6072c249ee
commit 80e6ba7033
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 0 deletions

View File

@ -55,3 +55,20 @@ const newIssue = await octokit.issues.create({
body: 'Hello Universe!'
});
```
## 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.
First, install the npm module `npm install @octokit/webhooks`
Then, assert the type based on the eventName
```ts
import * as core from '@actions/core'
import * as github from '@actions/github'
import * as Webhooks from '@octokit/webhooks'
if (github.context.eventName === 'push') {
const pushPayload = github.context.payload as Webhooks.WebhookPayloadPush
core.info(`The head commit is: ${pushPayload.head}`)
}
```