Socket
Socket
Sign inDemoInstall

@octokit/types

Package Overview
Dependencies
1
Maintainers
4
Versions
201
Alerts
File Explorer

Advanced tools

Install Socket

Protect your apps from supply chain attacks

Install

@octokit/types

Shared TypeScript definitions for Octokit projects

    12.6.0latest
    GitHub
    npm

Version published
Maintainers
4
Weekly downloads
13,117,457
increased by3.82%

Weekly downloads

Package description

What is @octokit/types?

The @octokit/types npm package provides TypeScript definitions for GitHub's REST API, GraphQL API, and Webhooks. It is designed to be used with other Octokit libraries to offer type safety and auto-completion in code editors, making it easier to work with GitHub's APIs in a TypeScript project.

What are @octokit/types's main functionalities?

GitHub REST API Types

Provides types for responses from GitHub's REST API endpoints. This example shows how to type an object representing a GitHub issue as it would be returned from the REST API.

import { RestEndpointMethodTypes } from '@octokit/types';

const issue: RestEndpointMethodTypes['issues']['get']['response']['data'] = {
  id: 1,
  number: 1347,
  title: 'Just a test issue'
};

GitHub GraphQL API Types

Provides types for constructing and receiving responses from GitHub's GraphQL API. This example demonstrates fetching a repository's details using GraphQL and typing the response.

import { graphql } from '@octokit/graphql';
import { Repository } from '@octokit/types';

async function getRepository(owner: string, name: string): Promise<Repository> {
  const { repository } = await graphql<{ repository: Repository }>(
    `{
      repository(owner: "${owner}", name: "${name}") {
        id
        name
        owner {
          login
        }
      }
    }`
  );
  return repository;
}

GitHub Webhooks Types

Includes types for GitHub Webhook events. This example shows how to handle an incoming webhook event with type safety, specifically for an issue event.

import { WebhookEvent } from '@octokit/types';

function handleWebhook(event: WebhookEvent) {
  if (event.name === 'issues') {
    const action = event.payload.action;
    console.log(`Issue action: ${action}`);
  }
}

Other packages similar to @octokit/types

Readme

Source

types.ts

Shared TypeScript definitions for Octokit projects

@latest Build Status

Usage

See all exported types at https://octokit.github.io/types.ts

Examples

Get parameter and response data types for a REST API endpoint

import { Endpoints } from "@octokit/types";

type listUserReposParameters =
  Endpoints["GET /repos/{owner}/{repo}"]["parameters"];
type listUserReposResponse = Endpoints["GET /repos/{owner}/{repo}"]["response"];

async function listRepos(
  options: listUserReposParameters,
): listUserReposResponse["data"] {
  // ...
}

Get response types from endpoint methods

import {
  GetResponseTypeFromEndpointMethod,
  GetResponseDataTypeFromEndpointMethod,
} from "@octokit/types";
import { Octokit } from "@octokit/rest";

const octokit = new Octokit();
type CreateLabelResponseType = GetResponseTypeFromEndpointMethod<
  typeof octokit.issues.createLabel
>;
type CreateLabelResponseDataType = GetResponseDataTypeFromEndpointMethod<
  typeof octokit.issues.createLabel
>;

Contributing

See CONTRIBUTING.md

License

MIT

Keywords

FAQs

Last updated on 22 Feb 2024

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc