actions / actions/toolkit

Property body of WebhookPayload should be string | null not optional

Open
#1,785 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
5.9k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug
The body property of the WebhookPayload interface should be string | null, not an optional string.
https://github.com/actions/toolkit/blob/bb6c50093929116e7050c394da9b9a1eb720d746/packages/github/src/interfaces.ts#L22

To Reproduce

import { PullRequestOpenedEvent } from '@octokit/webhooks-types';
import * as github from '@actions/github';

github.context.payload =  {} as PullRequestOpenedEvent;
/*  TS2322: Type 'PullRequestOpenedEvent' is not assignable to type 'WebhookPayload'.
      Types of property 'pull_request' are incompatible.
        Type 'PullRequest & { state: "open"; closed_at: null; merged_at: null; active_lock_reason: null; merged_by: null; }' is not assignable to type '{ [key: string]: any; number: number; html_url?: string | undefined; body?: string | undefined; } | undefined'.
          Type 'PullRequest & { state: "open"; closed_at: null; merged_at: null; active_lock_reason: null; merged_by: null; }' is not assignable to type '{ [key: string]: any; number: number; html_url?: string | undefined; body?: string | undefined; }'.
            Types of property 'body' are incompatible.
              Type 'string | null' is not assignable to type 'string | undefined'.
                Type 'null' is not assignable to type 'string | undefined'.*/

Expected behavior
Typing should be compatible with @octokit/webhooks-definitions

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/github/src/interfaces.ts at the WebhookPayload definition referenced by the issue, then reproduce the TypeScript assignment with @octokit/webhooks-types. Done means the body property accepts string | null and the shown PullRequestOpenedEvent assignment is type-compatible.

Written by the indexing model from the issue text.

Assessment

Tech stack
github, typescript
Domain
api
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.